Skip to content

Commit

Permalink
Support oneOfs in response model
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarber-akamai committed Dec 12, 2024
1 parent e663f45 commit 0a04571
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 8 additions & 1 deletion linodecli/baked/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Request details for a CLI Operation
"""

pass
import sys

from openapi3.schemas import Schema

Expand Down Expand Up @@ -138,6 +138,13 @@ def _parse_request_model(schema, prefix=None, parent=None, depth=0):
"""
args = []

if depth > 0 and schema.oneOf is not None:
print(
f"WARN: {'.'.join(schema.path)}: "
f"Ignoring oneOf because it is not defined at the request schema's root level.",
file=sys.stderr,
)

if schema.properties is None:
return args

Expand Down
21 changes: 19 additions & 2 deletions linodecli/baked/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from openapi3.paths import MediaType
from openapi3.schemas import Schema


def _is_paginated(response):
Expand Down Expand Up @@ -169,10 +170,26 @@ def _parse_response_model(schema, prefix=None, nested_list_depth=0):
)

attrs = []
if schema.properties is None:

properties = {}

if schema.properties is not None:
properties.update(dict(schema.properties))

# We dynamically merge oneOf values here to ensure they are all accounted for
# in the response model.
if schema.oneOf is not None:
for entry in schema.oneOf:
entry_schema = Schema(schema.path, entry, schema._root)
if entry_schema.properties is None:
continue

properties.update(dict(entry_schema.properties))

if properties is None:
return attrs

for k, v in schema.properties.items():
for k, v in properties.items():
pref = prefix + "." + k if prefix else k

if v.type == "object":
Expand Down

0 comments on commit 0a04571

Please sign in to comment.