Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2022-02-27 21:34:21 -08:00
parent 0b9c32e6bf
commit 9c18ba2350
13 changed files with 205 additions and 183 deletions

View File

@ -64,10 +64,10 @@ def generatePaths(cwd: str, parser: OpenApiParser):
for p in paths:
for method in paths[p]:
endpoint = paths[p][method]
generatePath(path, p, method, endpoint)
generatePath(path, p, method, endpoint, data)
def generatePath(path: str, name: str, method: str, endpoint: dict):
def generatePath(path: str, name: str, method: str, endpoint: dict, data: dict):
# Generate the path.
file_name = camel_to_snake(endpoint['operationId']) + '.py'
# Add the tag to the path if it exists.
@ -79,7 +79,7 @@ def generatePath(path: str, name: str, method: str, endpoint: dict):
print(" endpoint: ", [endpoint])
f = open(file_path, "w")
endoint_refs = getEndpointRefs(endpoint)
endoint_refs = getEndpointRefs(endpoint, data)
parameter_refs = getParameterRefs(endpoint)
request_body_refs = getRequestBodyRefs(endpoint)
@ -198,6 +198,22 @@ def generatePath(path: str, name: str, method: str, endpoint: dict):
" = " +
ref +
".from_dict(response.json())\n")
elif '$ref' in response:
schema_name = response['$ref'].replace('#/components/responses/', '')
schema = data['components']['responses'][schema_name]
if 'content' in schema:
content = schema['content']
for content_type in content:
if content_type == 'application/json':
json = content[content_type]['schema']
if '$ref' in json:
ref = json['$ref'].replace('#/components/schemas/', '')
f.write(
"\t\tresponse_" +
response_code +
" = " +
ref +
".from_dict(response.json())\n")
else:
f.write("\t\tresponse_" + response_code + " = None\n")
@ -707,7 +723,7 @@ def generateType(path: str, name: str, schema: dict):
continue
f.write(
"\t" +
"\t\t" +
property_name +
" = d.pop(\"" +
property_name +
@ -715,7 +731,7 @@ def generateType(path: str, name: str, schema: dict):
f.write("\n")
elif property_type == 'integer':
f.write(
"\t" +
"\t\t" +
property_name +
" = d.pop(\"" +
property_name +
@ -723,7 +739,7 @@ def generateType(path: str, name: str, schema: dict):
f.write("\n")
elif property_type == 'number':
f.write(
"\t" +
"\t\t" +
property_name +
" = d.pop(\"" +
property_name +
@ -731,7 +747,7 @@ def generateType(path: str, name: str, schema: dict):
f.write("\n")
elif property_type == 'boolean':
f.write(
"\t" +
"\t\t" +
property_name +
" = d.pop(\"" +
property_name +
@ -776,7 +792,7 @@ def generateType(path: str, name: str, schema: dict):
f.write("\t\t)\n")
f.write("\n")
f.write("\t\t" + camel_to_snake(name) + ".additional_properties = d\n")
f.write("return " + camel_to_snake(name) + "\n")
f.write("\t\treturn " + camel_to_snake(name) + "\n")
# write the rest of the class.
f.write("\n")
@ -862,7 +878,7 @@ def getRefs(schema: dict) -> [str]:
return refs
def getEndpointRefs(endpoint: dict) -> [str]:
def getEndpointRefs(endpoint: dict, data: dict) -> [str]:
refs = []
responses = endpoint['responses']
@ -877,6 +893,18 @@ def getEndpointRefs(endpoint: dict) -> [str]:
ref = json['$ref'].replace('#/components/schemas/', '')
if ref not in refs:
refs.append(ref)
elif '$ref' in response:
schema_name = response['$ref'].replace('#/components/responses/', '')
schema = data['components']['responses'][schema_name]
if 'content' in schema:
content = schema['content']
for content_type in content:
if content_type == 'application/json':
json = content[content_type]['schema']
if '$ref' in json:
ref = json['$ref'].replace('#/components/schemas/', '')
if ref not in refs:
refs.append(ref)
return refs

View File

@ -4,6 +4,7 @@ import httpx
from ...client import Client
from ...models.file_conversion import FileConversion
from ...models.error_message import ErrorMessage
from ...types import Response
def _get_kwargs(
@ -24,29 +25,29 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion, ErrorMessage]]:
if response.status_code == 200:
response_200 = FileConversion.from_dict(response.json())
return response_200
if response.status_code == 401:
response_401 = None
response_401 = ErrorMessage.from_dict(response.json())
return response_401
if response.status_code == 403:
response_403 = None
response_403 = ErrorMessage.from_dict(response.json())
return response_403
if response.status_code == 404:
response_404 = None
response_404 = ErrorMessage.from_dict(response.json())
return response_404
if response.status_code == 406:
response_406 = None
response_406 = ErrorMessage.from_dict(response.json())
return response_406
if response.status_code == 500:
response_500 = None
response_500 = ErrorMessage.from_dict(response.json())
return response_500
return None
def _build_response(*, response: httpx.Response) -> Response[Union[Any, FileConversion]]:
def _build_response(*, response: httpx.Response) -> Response[Union[Any, FileConversion, ErrorMessage]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -59,7 +60,7 @@ def sync_detailed(
id: str,
*,
client: Client,
) -> Response[Union[Any, FileConversion]]:
) -> Response[Union[Any, FileConversion, ErrorMessage]]:
kwargs = _get_kwargs(
id=id,
client=client,
@ -77,7 +78,7 @@ def sync(
id: str,
*,
client: Client,
) -> Optional[Union[Any, FileConversion]]:
) -> Optional[Union[Any, FileConversion, ErrorMessage]]:
""" Get the status and output of an async file conversion. """
return sync_detailed(
@ -90,7 +91,7 @@ async def asyncio_detailed(
id: str,
*,
client: Client,
) -> Response[Union[Any, FileConversion]]:
) -> Response[Union[Any, FileConversion, ErrorMessage]]:
kwargs = _get_kwargs(
id=id,
client=client,
@ -106,7 +107,7 @@ async def asyncio(
id: str,
*,
client: Client,
) -> Optional[Union[Any, FileConversion]]:
) -> Optional[Union[Any, FileConversion, ErrorMessage]]:
""" Get the status and output of an async file conversion. """
return (

View File

@ -4,6 +4,7 @@ import httpx
from ...client import Client
from ...models.file_conversion import FileConversion
from ...models.error_message import ErrorMessage
from ...models.valid_source_file_format import ValidSourceFileFormat
from ...models.valid_output_file_format import ValidOutputFileFormat
from ...types import Response
@ -27,7 +28,7 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion, ErrorMessage]]:
if response.status_code == 200:
response_200 = FileConversion.from_dict(response.json())
return response_200
@ -35,24 +36,24 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConv
response_202 = FileConversion.from_dict(response.json())
return response_202
if response.status_code == 400:
response_400 = None
response_400 = ErrorMessage.from_dict(response.json())
return response_400
if response.status_code == 401:
response_401 = None
response_401 = ErrorMessage.from_dict(response.json())
return response_401
if response.status_code == 403:
response_403 = None
response_403 = ErrorMessage.from_dict(response.json())
return response_403
if response.status_code == 406:
response_406 = None
response_406 = ErrorMessage.from_dict(response.json())
return response_406
if response.status_code == 500:
response_500 = None
response_500 = ErrorMessage.from_dict(response.json())
return response_500
return None
def _build_response(*, response: httpx.Response) -> Response[Union[Any, FileConversion]]:
def _build_response(*, response: httpx.Response) -> Response[Union[Any, FileConversion, ErrorMessage]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -66,7 +67,7 @@ def sync_detailed(
output_format: ValidOutputFileFormat,
*,
client: Client,
) -> Response[Union[Any, FileConversion]]:
) -> Response[Union[Any, FileConversion, ErrorMessage]]:
kwargs = _get_kwargs(
source_format=source_format,
output_format=output_format,
@ -86,7 +87,7 @@ def sync(
output_format: ValidOutputFileFormat,
*,
client: Client,
) -> Optional[Union[Any, FileConversion]]:
) -> Optional[Union[Any, FileConversion, ErrorMessage]]:
""" Convert a CAD file from one format to another. If the file being converted is larger than 30MB, it will be performed asynchronously. """
return sync_detailed(
@ -101,7 +102,7 @@ async def asyncio_detailed(
output_format: ValidOutputFileFormat,
*,
client: Client,
) -> Response[Union[Any, FileConversion]]:
) -> Response[Union[Any, FileConversion, ErrorMessage]]:
kwargs = _get_kwargs(
source_format=source_format,
output_format=output_format,
@ -119,7 +120,7 @@ async def asyncio(
output_format: ValidOutputFileFormat,
*,
client: Client,
) -> Optional[Union[Any, FileConversion]]:
) -> Optional[Union[Any, FileConversion, ErrorMessage]]:
""" Convert a CAD file from one format to another. If the file being converted is larger than 30MB, it will be performed asynchronously. """
return (

View File

@ -3,6 +3,7 @@ from typing import Any, Dict, Optional, Union
import httpx
from ...client import Client
from ...models.error_message import ErrorMessage
from ...types import Response
def _get_kwargs(
@ -22,19 +23,19 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, ]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, ErrorMessage]]:
if response.status_code == 200:
return response_200
if response.status_code == 401:
response_401 = None
response_401 = ErrorMessage.from_dict(response.json())
return response_401
if response.status_code == 403:
response_403 = None
response_403 = ErrorMessage.from_dict(response.json())
return response_403
return None
def _build_response(*, response: httpx.Response) -> Response[Union[Any, ]]:
def _build_response(*, response: httpx.Response) -> Response[Union[Any, ErrorMessage]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -46,7 +47,7 @@ def _build_response(*, response: httpx.Response) -> Response[Union[Any, ]]:
def sync_detailed(
*,
client: Client,
) -> Response[Union[Any, ]]:
) -> Response[Union[Any, ErrorMessage]]:
kwargs = _get_kwargs(
client=client,
)
@ -62,7 +63,7 @@ def sync_detailed(
def sync(
*,
client: Client,
) -> Optional[Union[Any, ]]:
) -> Optional[Union[Any, ErrorMessage]]:
""" Get information about GPU devices on this server. This is primarily used for debugging. This endpoint can only be used by specific KittyCAD employees. """
return sync_detailed(
@ -73,7 +74,7 @@ def sync(
async def asyncio_detailed(
*,
client: Client,
) -> Response[Union[Any, ]]:
) -> Response[Union[Any, ErrorMessage]]:
kwargs = _get_kwargs(
client=client,
)
@ -87,7 +88,7 @@ async def asyncio_detailed(
async def asyncio(
*,
client: Client,
) -> Optional[Union[Any, ]]:
) -> Optional[Union[Any, ErrorMessage]]:
""" Get information about GPU devices on this server. This is primarily used for debugging. This endpoint can only be used by specific KittyCAD employees. """
return (

View File

@ -4,6 +4,7 @@ import httpx
from ...client import Client
from ...models.file_conversion import FileConversion
from ...models.error_message import ErrorMessage
from ...types import Response
def _get_kwargs(
@ -23,23 +24,23 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion, ErrorMessage]]:
if response.status_code == 200:
response_200 = FileConversion.from_dict(response.json())
return response_200
if response.status_code == 401:
response_401 = None
response_401 = ErrorMessage.from_dict(response.json())
return response_401
if response.status_code == 403:
response_403 = None
response_403 = ErrorMessage.from_dict(response.json())
return response_403
if response.status_code == 404:
response_404 = None
response_404 = ErrorMessage.from_dict(response.json())
return response_404
return None
def _build_response(*, response: httpx.Response) -> Response[Union[Any, FileConversion]]:
def _build_response(*, response: httpx.Response) -> Response[Union[Any, FileConversion, ErrorMessage]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -51,7 +52,7 @@ def _build_response(*, response: httpx.Response) -> Response[Union[Any, FileConv
def sync_detailed(
*,
client: Client,
) -> Response[Union[Any, FileConversion]]:
) -> Response[Union[Any, FileConversion, ErrorMessage]]:
kwargs = _get_kwargs(
client=client,
)
@ -67,7 +68,7 @@ def sync_detailed(
def sync(
*,
client: Client,
) -> Optional[Union[Any, FileConversion]]:
) -> Optional[Union[Any, FileConversion, ErrorMessage]]:
""" Stop all async conversions that are currently running. This endpoint can only be used by specific KittyCAD employees. """
return sync_detailed(
@ -78,7 +79,7 @@ def sync(
async def asyncio_detailed(
*,
client: Client,
) -> Response[Union[Any, FileConversion]]:
) -> Response[Union[Any, FileConversion, ErrorMessage]]:
kwargs = _get_kwargs(
client=client,
)
@ -92,7 +93,7 @@ async def asyncio_detailed(
async def asyncio(
*,
client: Client,
) -> Optional[Union[Any, FileConversion]]:
) -> Optional[Union[Any, FileConversion, ErrorMessage]]:
""" Stop all async conversions that are currently running. This endpoint can only be used by specific KittyCAD employees. """
return (

View File

@ -4,6 +4,7 @@ import httpx
from ...client import Client
from ...models.auth_session import AuthSession
from ...models.error_message import ErrorMessage
from ...types import Response
def _get_kwargs(
@ -23,20 +24,20 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, AuthSession]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, AuthSession, ErrorMessage]]:
if response.status_code == 200:
response_200 = AuthSession.from_dict(response.json())
return response_200
if response.status_code == 401:
response_401 = None
response_401 = ErrorMessage.from_dict(response.json())
return response_401
if response.status_code == 403:
response_403 = None
response_403 = ErrorMessage.from_dict(response.json())
return response_403
return None
def _build_response(*, response: httpx.Response) -> Response[Union[Any, AuthSession]]:
def _build_response(*, response: httpx.Response) -> Response[Union[Any, AuthSession, ErrorMessage]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -48,7 +49,7 @@ def _build_response(*, response: httpx.Response) -> Response[Union[Any, AuthSess
def sync_detailed(
*,
client: Client,
) -> Response[Union[Any, AuthSession]]:
) -> Response[Union[Any, AuthSession, ErrorMessage]]:
kwargs = _get_kwargs(
client=client,
)
@ -64,7 +65,7 @@ def sync_detailed(
def sync(
*,
client: Client,
) -> Optional[Union[Any, AuthSession]]:
) -> Optional[Union[Any, AuthSession, ErrorMessage]]:
""" Get information about your API request session. This is primarily used for debugging. """
return sync_detailed(
@ -75,7 +76,7 @@ def sync(
async def asyncio_detailed(
*,
client: Client,
) -> Response[Union[Any, AuthSession]]:
) -> Response[Union[Any, AuthSession, ErrorMessage]]:
kwargs = _get_kwargs(
client=client,
)
@ -89,7 +90,7 @@ async def asyncio_detailed(
async def asyncio(
*,
client: Client,
) -> Optional[Union[Any, AuthSession]]:
) -> Optional[Union[Any, AuthSession, ErrorMessage]]:
""" Get information about your API request session. This is primarily used for debugging. """
return (

View File

@ -4,6 +4,7 @@ import httpx
from ...client import Client
from ...models.instance import Instance
from ...models.error_message import ErrorMessage
from ...types import Response
def _get_kwargs(
@ -23,20 +24,20 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, Instance]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, Instance, ErrorMessage]]:
if response.status_code == 200:
response_200 = Instance.from_dict(response.json())
return response_200
if response.status_code == 401:
response_401 = None
response_401 = ErrorMessage.from_dict(response.json())
return response_401
if response.status_code == 403:
response_403 = None
response_403 = ErrorMessage.from_dict(response.json())
return response_403
return None
def _build_response(*, response: httpx.Response) -> Response[Union[Any, Instance]]:
def _build_response(*, response: httpx.Response) -> Response[Union[Any, Instance, ErrorMessage]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -48,7 +49,7 @@ def _build_response(*, response: httpx.Response) -> Response[Union[Any, Instance
def sync_detailed(
*,
client: Client,
) -> Response[Union[Any, Instance]]:
) -> Response[Union[Any, Instance, ErrorMessage]]:
kwargs = _get_kwargs(
client=client,
)
@ -64,7 +65,7 @@ def sync_detailed(
def sync(
*,
client: Client,
) -> Optional[Union[Any, Instance]]:
) -> Optional[Union[Any, Instance, ErrorMessage]]:
""" Get information about this specific API server instance. This is primarily used for debugging. """
return sync_detailed(
@ -75,7 +76,7 @@ def sync(
async def asyncio_detailed(
*,
client: Client,
) -> Response[Union[Any, Instance]]:
) -> Response[Union[Any, Instance, ErrorMessage]]:
kwargs = _get_kwargs(
client=client,
)
@ -89,7 +90,7 @@ async def asyncio_detailed(
async def asyncio(
*,
client: Client,
) -> Optional[Union[Any, Instance]]:
) -> Optional[Union[Any, Instance, ErrorMessage]]:
""" Get information about this specific API server instance. This is primarily used for debugging. """
return (

View File

@ -93,8 +93,6 @@ class AuthSession:
)
auth_session.additional_properties = d
return auth_session
@property

View File

@ -49,8 +49,6 @@ class ErrorMessage:
)
error_message.additional_properties = d
return error_message
@property

View File

@ -131,8 +131,6 @@ class FileConversion:
)
file_conversion.additional_properties = d
return file_conversion
@property

View File

@ -63,8 +63,6 @@ class GPUDevice:
)
gpu_device.additional_properties = d
return gpu_device
@property

View File

@ -113,8 +113,6 @@ class Instance:
)
instance.additional_properties = d
return instance
@property

View File

@ -43,8 +43,6 @@ class PongMessage:
)
pong_message.additional_properties = d
return pong_message
@property