Skip to content

Commit 14dfd2a

Browse files
Support VPC Interfaces Changes (#536)
1 parent fa2e11a commit 14dfd2a

File tree

3 files changed

+41
-23
lines changed

3 files changed

+41
-23
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ endif
1818
install: check-prerequisites requirements build
1919
pip3 install --force dist/*.whl
2020

21-
.PHONY: build
22-
build: clean
21+
.PHONY: bake
22+
bake: clean
2323
python3 -m linodecli bake ${SPEC} --skip-config
2424
cp data-3 linodecli/
25+
26+
.PHONY: build
27+
build: clean bake
2528
python3 -m build --wheel --sdist
2629

2730
.PHONY: requirements

linodecli/baked/operation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from os import environ, path
1212
from typing import List, Tuple
1313

14+
from openapi3.paths import Operation
15+
1416
from linodecli.baked.request import OpenAPIFilteringRequest, OpenAPIRequest
1517
from linodecli.baked.response import OpenAPIResponse
1618
from linodecli.overrides import OUTPUT_OVERRIDES
@@ -233,7 +235,7 @@ class OpenAPIOperation:
233235
This is the class that should be pickled when building the CLI.
234236
"""
235237

236-
def __init__(self, command, operation, method, params):
238+
def __init__(self, command, operation: Operation, method, params):
237239
"""
238240
Wraps an openapi3.Operation object and handles pulling out values relevant
239241
to the Linode CLI.

linodecli/baked/response.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
Converting the processed OpenAPI Responses into something the CLI can work with
33
"""
4+
from openapi3.paths import MediaType
5+
46
from .colors import colorize_string
57

68

@@ -159,26 +161,35 @@ def _parse_response_model(schema, prefix=None, nested_list_depth=0):
159161
:returns: The list of parsed OpenAPIResponseAttr objects representing this schema
160162
:rtype: List[OpenAPIResponseAttr]
161163
"""
162-
attrs = []
163164

164-
if schema.properties is not None:
165-
for k, v in schema.properties.items():
166-
pref = prefix + "." + k if prefix else k
167-
168-
if v.type == "object":
169-
attrs += _parse_response_model(v, prefix=pref)
170-
elif v.type == "array" and v.items.type == "object":
171-
attrs += _parse_response_model(
172-
v.items,
173-
prefix=pref,
174-
nested_list_depth=nested_list_depth + 1,
175-
)
176-
else:
177-
attrs.append(
178-
OpenAPIResponseAttr(
179-
k, v, prefix=prefix, nested_list_depth=nested_list_depth
180-
)
165+
if schema.type == "array":
166+
return _parse_response_model(
167+
schema.items,
168+
prefix=prefix,
169+
nested_list_depth=nested_list_depth,
170+
)
171+
172+
attrs = []
173+
if schema.properties is None:
174+
return attrs
175+
176+
for k, v in schema.properties.items():
177+
pref = prefix + "." + k if prefix else k
178+
179+
if v.type == "object":
180+
attrs += _parse_response_model(v, prefix=pref)
181+
elif v.type == "array" and v.items.type == "object":
182+
attrs += _parse_response_model(
183+
v.items,
184+
prefix=pref,
185+
nested_list_depth=nested_list_depth + 1,
186+
)
187+
else:
188+
attrs.append(
189+
OpenAPIResponseAttr(
190+
k, v, prefix=prefix, nested_list_depth=nested_list_depth
181191
)
192+
)
182193

183194
return attrs
184195

@@ -189,7 +200,7 @@ class OpenAPIResponse:
189200
responses section of an OpenAPI Operation
190201
"""
191202

192-
def __init__(self, response):
203+
def __init__(self, response: MediaType):
193204
"""
194205
:param response: The response's MediaType object in the OpenAPI spec,
195206
corresponding to the application/json response type
@@ -228,7 +239,9 @@ def fix_json(self, json):
228239
# Needs to go last to handle custom schemas
229240
if "pages" in json:
230241
return json["data"]
231-
return [json]
242+
if not isinstance(json, list):
243+
json = [json]
244+
return json
232245

233246
def _fix_json_rows(self, json):
234247
"""

0 commit comments

Comments
 (0)