Skip to content

Commit 0a04571

Browse files
Support oneOfs in response model
1 parent e663f45 commit 0a04571

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

linodecli/baked/request.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Request details for a CLI Operation
33
"""
44

5-
pass
5+
import sys
66

77
from openapi3.schemas import Schema
88

@@ -138,6 +138,13 @@ def _parse_request_model(schema, prefix=None, parent=None, depth=0):
138138
"""
139139
args = []
140140

141+
if depth > 0 and schema.oneOf is not None:
142+
print(
143+
f"WARN: {'.'.join(schema.path)}: "
144+
f"Ignoring oneOf because it is not defined at the request schema's root level.",
145+
file=sys.stderr,
146+
)
147+
141148
if schema.properties is None:
142149
return args
143150

linodecli/baked/response.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
from openapi3.paths import MediaType
6+
from openapi3.schemas import Schema
67

78

89
def _is_paginated(response):
@@ -169,10 +170,26 @@ def _parse_response_model(schema, prefix=None, nested_list_depth=0):
169170
)
170171

171172
attrs = []
172-
if schema.properties is None:
173+
174+
properties = {}
175+
176+
if schema.properties is not None:
177+
properties.update(dict(schema.properties))
178+
179+
# We dynamically merge oneOf values here to ensure they are all accounted for
180+
# in the response model.
181+
if schema.oneOf is not None:
182+
for entry in schema.oneOf:
183+
entry_schema = Schema(schema.path, entry, schema._root)
184+
if entry_schema.properties is None:
185+
continue
186+
187+
properties.update(dict(entry_schema.properties))
188+
189+
if properties is None:
173190
return attrs
174191

175-
for k, v in schema.properties.items():
192+
for k, v in properties.items():
176193
pref = prefix + "." + k if prefix else k
177194

178195
if v.type == "object":

0 commit comments

Comments
 (0)