Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for edge case where apiVersion param has no default #678

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion linodecli/baked/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,13 @@ def _resolve_api_version(
None,
)
if version_param is not None:
return version_param.schema.default
schema = version_param.schema

if schema.default:
return schema.default

if schema.enum and len(schema.enum) > 0:
return schema.enum[0]

return None

Expand Down
18 changes: 18 additions & 0 deletions tests/fixtures/api_url_components_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,21 @@ paths:
description: foobar
content:
application/json: {}

/{apiVersion}/bar:
parameters:
- name: apiVersion
in: path
required: true
schema:
type: string
enum:
- v1000
- v1000beta
get:
operationId: barGet
responses:
'200':
description: foobar
content:
application/json: {}
19 changes: 19 additions & 0 deletions tests/unit/test_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,25 @@ def test_resolve_api_components(self, get_openapi_for_api_components_tests):
operation=root.paths["/{apiVersion}/bar/foo"].post, params=[]
) == ("http://localhost", "/{apiVersion}/bar/foo", "v100beta")

def test_resolve_api_version(self, get_openapi_for_api_components_tests):
root = get_openapi_for_api_components_tests

assert (
OpenAPIOperation._resolve_api_version(
params=root.paths["/{apiVersion}/bar/foo"].parameters,
server_url="http://localhost",
)
== "v9canary"
)

assert (
OpenAPIOperation._resolve_api_version(
params=root.paths["/{apiVersion}/bar"].parameters,
server_url="http://localhost",
)
== "v1000"
)

def test_resolve_docs_url_legacy(self, get_openapi_for_docs_url_tests):
root = get_openapi_for_docs_url_tests

Expand Down
Loading