TPT-4280: linode-cli: Adjust parser for the OpenAPI changes#888
Merged
mgwoj merged 2 commits intoMay 12, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the CLI’s OpenAPI spec loading path to handle newer OpenAPI specs that define Parameter objects using the OpenAPI 3.x content form, which the openapi3 Python library can’t parse directly.
Changes:
- Normalize
Parameterobjects that usecontentby extracting the first media-type schema into a top-levelschemafield. - Apply this normalization to parameters defined in
components.parametersand those defined inline on paths/operations. - Run normalization automatically during
_load_openapi_specprior to constructing theOpenAPIobject.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+308
to
+336
| CLI._normalize_content_parameters(parsed) | ||
|
|
||
| return OpenAPI(parsed) | ||
|
|
||
| @staticmethod | ||
| def _normalize_content_parameters(parsed: Dict[str, Any]): | ||
| """ | ||
| The openapi3 library does not support the OpenAPI 3.0 ``content`` | ||
| form for Parameter objects. This method converts any such | ||
| parameters (in components and inline on paths/operations) to use | ||
| a top-level ``schema`` field so they can be parsed normally. | ||
|
|
||
| :param parsed: The raw spec dict to mutate in-place. | ||
| """ | ||
|
|
||
| def _fix_param(param): | ||
| if not isinstance(param, dict): | ||
| return | ||
| if "content" in param and "schema" not in param: | ||
| content = param.pop("content") | ||
| for media_obj in content.values(): | ||
| if isinstance(media_obj, dict) and "schema" in media_obj: | ||
| param["schema"] = media_obj["schema"] | ||
| break | ||
|
|
||
| for param in ( | ||
| parsed.get("components", {}).get("parameters", {}).values() | ||
| ): | ||
| _fix_param(param) |
Comment on lines
+308
to
+318
| CLI._normalize_content_parameters(parsed) | ||
|
|
||
| return OpenAPI(parsed) | ||
|
|
||
| @staticmethod | ||
| def _normalize_content_parameters(parsed: Dict[str, Any]): | ||
| """ | ||
| The openapi3 library does not support the OpenAPI 3.0 ``content`` | ||
| form for Parameter objects. This method converts any such | ||
| parameters (in components and inline on paths/operations) to use | ||
| a top-level ``schema`` field so they can be parsed normally. |
Contributor
|
The changes do the job for me - I successfully generated linode-cli tool with |
mawilk90
approved these changes
May 12, 2026
ezilber-akamai
approved these changes
May 12, 2026
Contributor
ezilber-akamai
left a comment
There was a problem hiding this comment.
Thanks for fixing this! Can you update the PR title to better reflect the changes in the PR?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains fix which allow parsing latest version of the OpenAPI specification.