Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2022-02-28 12:30:27 -08:00
parent aa723677a3
commit 6b6de6ddf2
2 changed files with 33 additions and 6 deletions

View File

@ -287,6 +287,29 @@ response: Response[""" + success_type + """] = await """ + fn_name + """.asyncio
" = " +
ref +
".from_dict(response.json())\n")
elif 'type' in json:
if json['type'] == 'array':
items = json['items']
if '$ref' in items:
ref = items['$ref'].replace(
'#/components/schemas/', '')
f.write(
"\t\tresponse_" +
response_code +
" = [\n")
f.write(
"\t\t\t" +
ref +
".from_dict(item)\n")
f.write(
"\t\t\tfor item in response.json()\n")
f.write("\t\t]\n")
else:
raise Exception("Unknown array type")
else:
raise Exception("Unknown type")
else:
raise Exception("Unknown type")
elif '$ref' in response:
schema_name = response['$ref'].replace(
'#/components/responses/', '')
@ -697,7 +720,7 @@ def generateType(path: str, name: str, schema: dict):
property_name +
": Union[Unset, bool] = False\n")
else:
raise (" unknown type: ", property_type)
raise Exception(" unknown type: ", property_type)
elif '$ref' in property_schema:
ref = property_schema['$ref'].replace(
'#/components/schemas/', '')
@ -708,7 +731,7 @@ def generateType(path: str, name: str, schema: dict):
ref +
"] = UNSET\n")
else:
raise (" unknown schema: ", property_schema)
raise Exception(" unknown schema: ", property_schema)
# Finish writing the class.
f.write("\n")
@ -770,7 +793,7 @@ def generateType(path: str, name: str, schema: dict):
property_name +
"\n")
else:
raise (" unknown type: ", property_type)
raise Exception(" unknown type: ", property_type)
elif '$ref' in property_schema:
ref = property_schema['$ref'].replace(
'#/components/schemas/', '')
@ -789,7 +812,7 @@ def generateType(path: str, name: str, schema: dict):
property_name +
".value\n")
else:
raise (" unknown schema: ", property_schema)
raise Exception(" unknown schema: ", property_schema)
# Finish writing the to_dict method.
f.write("\n")
@ -880,7 +903,7 @@ def generateType(path: str, name: str, schema: dict):
f.write("\n")
else:
print(" unknown type: ", property_type)
raise
raise Exception(" unknown type: ", property_type)
elif '$ref' in property_schema:
ref = property_schema['$ref'].replace(
'#/components/schemas/', '')
@ -903,7 +926,7 @@ def generateType(path: str, name: str, schema: dict):
f.write("\n")
else:
print(" unknown schema: ", property_schema)
raise
raise Exception(" unknown schema: ", property_schema)
# Finish writing the from_dict method.
f.write("\n")

View File

@ -25,6 +25,10 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, ErrorMessage]]:
if response.status_code == 200:
response_200 = [
GPUDevice.from_dict(item)
for item in response.json()
]
return response_200
if response.status_code == 401:
response_401 = ErrorMessage.from_dict(response.json())