Skip to content

TPT-4280: linode-cli: Adjust parser for the OpenAPI changes#888

Merged
mgwoj merged 2 commits into
linode:devfrom
mgwoj:feature/TPT-4280-linode-cli-add-integration-tests-for-reserved-ip-for-ipv4
May 12, 2026
Merged

TPT-4280: linode-cli: Adjust parser for the OpenAPI changes#888
mgwoj merged 2 commits into
linode:devfrom
mgwoj:feature/TPT-4280-linode-cli-add-integration-tests-for-reserved-ip-for-ipv4

Conversation

@mgwoj
Copy link
Copy Markdown
Contributor

@mgwoj mgwoj commented May 11, 2026

This PR contains fix which allow parsing latest version of the OpenAPI specification.

@mgwoj mgwoj requested review from a team as code owners May 11, 2026 20:32
@mgwoj mgwoj requested review from ckulinsk and jriddle-linode and removed request for a team May 11, 2026 20:32
@mawilk90 mawilk90 self-requested a review May 12, 2026 05:57
@mgwoj mgwoj added the hotfix for hotfixes that do not have a corresponding Jira ticket label May 12, 2026
@mgwoj mgwoj changed the title TPT-4175: cli: Update interactive config token access check TPT-4280: linode-cli: Add integration tests for Reserved IP for IPv4 May 12, 2026
@mawilk90 mawilk90 removed the request for review from ckulinsk May 12, 2026 07:06
@mgwoj mgwoj requested a review from Copilot May 12, 2026 07:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Parameter objects that use content by extracting the first media-type schema into a top-level schema field.
  • Apply this normalization to parameters defined in components.parameters and those defined inline on paths/operations.
  • Run normalization automatically during _load_openapi_spec prior to constructing the OpenAPI object.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread linodecli/cli.py
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 thread linodecli/cli.py
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.
@mawilk90
Copy link
Copy Markdown
Contributor

mawilk90 commented May 12, 2026

The changes do the job for me - I successfully generated linode-cli tool with make install no matter what version of openapi.json used.

Copy link
Copy Markdown
Contributor

@ezilber-akamai ezilber-akamai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this! Can you update the PR title to better reflect the changes in the PR?

@mgwoj mgwoj changed the title TPT-4280: linode-cli: Add integration tests for Reserved IP for IPv4 TPT-4280: linode-cli: Adjust parser for the OpenAPI changes May 12, 2026
@mgwoj mgwoj merged commit d695939 into linode:dev May 12, 2026
18 checks passed
@mgwoj mgwoj deleted the feature/TPT-4280-linode-cli-add-integration-tests-for-reserved-ip-for-ipv4 branch May 12, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotfix for hotfixes that do not have a corresponding Jira ticket

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants