Skip to content

Commit 92f5cc8

Browse files
WIP
1 parent ff292fc commit 92f5cc8

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

linodecli/baked/request.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def __init__( # pylint: disable=too-many-arguments
2626
is_parent: bool = False,
2727
parent: Optional[str] = None,
2828
depth: int = 0,
29+
option_path: Optional[List[str]] = None,
2930
) -> None:
3031
"""
3132
Parses a single Schema node into a argument the CLI can use when making
@@ -123,12 +124,15 @@ def __init__( # pylint: disable=too-many-arguments
123124
"instead of object's properties! This is a programming error."
124125
)
125126

127+
self.option_path = option_path
128+
126129

127130
def _parse_request_model(
128131
schema: Schema,
129132
prefix: Optional[str] = None,
130133
parent: Optional[str] = None,
131134
depth: int = 0,
135+
option_path: Optional[List[str]] = None,
132136
) -> List[OpenAPIRequestArg]:
133137
"""
134138
Parses an OpenAPI schema into a list of OpenAPIRequest objects
@@ -147,6 +151,7 @@ def _parse_request_model(
147151
args = []
148152

149153
properties, required = _aggregate_schema_properties(schema)
154+
print(properties, required)
150155

151156
if properties is None:
152157
return args
@@ -191,6 +196,7 @@ def _parse_request_model(
191196
is_parent=True,
192197
parent=parent,
193198
depth=depth,
199+
option_path=option_path,
194200
)
195201
)
196202

@@ -209,6 +215,7 @@ def _parse_request_model(
209215
prefix=prefix,
210216
parent=parent,
211217
depth=depth,
218+
option_path=option_path,
212219
)
213220
)
214221

linodecli/baked/util.py

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

55
from collections import defaultdict
6-
from typing import Any, Dict, Set, Tuple
6+
from typing import Any, Dict, List, Set, Tuple
77

88
from openapi3.schemas import Schema
99

@@ -23,7 +23,16 @@ def _aggregate_schema_properties(
2323
properties = {}
2424
required = defaultdict(lambda: 0)
2525

26-
def _handle_schema(_schema: Schema):
26+
def _handle_schema(path: List[str], data: Dict[str, Any]):
27+
# We accept data as a dict here to prevent and parsing edge cases
28+
for i, entry in enumerate(data.get("oneOf", [])):
29+
_handle_schema(path + ["oneOf", i], entry)
30+
31+
for i, entry in enumerate(data.get("allOf", [])):
32+
_handle_schema(path + ["allOf", i], entry)
33+
34+
_schema = Schema(path, data, schema._root)
35+
2736
if _schema.properties is None:
2837
return
2938

@@ -37,14 +46,7 @@ def _handle_schema(_schema: Schema):
3746
for key in _schema.required:
3847
required[key] += 1
3948

40-
_handle_schema(schema)
41-
42-
one_of = schema.oneOf or []
43-
any_of = schema.anyOf or []
44-
45-
for entry in one_of + any_of:
46-
# pylint: disable=protected-access
47-
_handle_schema(Schema(schema.path, entry, schema._root))
49+
_handle_schema(schema.path, schema.raw_element)
4850

4951
return (
5052
properties,

0 commit comments

Comments
 (0)