first start of fix

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2022-06-11 17:42:00 -07:00
parent 9dc390a64d
commit 49b8d2747a
8 changed files with 56 additions and 45 deletions

1
.gitignore vendored
View File

@ -23,3 +23,4 @@ dmypy.json
/.coverage
poetry.lock
testing

View File

@ -110,12 +110,12 @@ def generatePath(
print(" endpoint: ", [endpoint])
f = open(file_path, "w")
endoint_refs = getEndpointRefs(endpoint, data)
endpoint_refs = getEndpointRefs(endpoint, data)
parameter_refs = getParameterRefs(endpoint)
request_body_refs = getRequestBodyRefs(endpoint)
request_body_type = getRequestBodyType(endpoint)
success_type = endoint_refs[0]
success_type = endpoint_refs[0]
if fn_name == 'get_file_conversion' or fn_name == 'create_file_conversion':
fn_name += '_with_base64_helper'
@ -173,7 +173,7 @@ response: Response[""" + success_type + """] = await """ + fn_name + """.asyncio
f.write("\n")
f.write("from ...client import Client\n")
# Import our references for responses.
for ref in endoint_refs:
for ref in endpoint_refs:
if ref.startswith('[') and ref.endswith(']'):
ref = ref.replace('[', '').replace(']', '')
f.write(
@ -270,7 +270,7 @@ response: Response[""" + success_type + """] = await """ + fn_name + """.asyncio
f.write(
"def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, " +
", ".join(endoint_refs) +
", ".join(endpoint_refs) +
"]]:\n")
# Iterate over the responses.
responses = endpoint['responses']
@ -353,7 +353,7 @@ response: Response[""" + success_type + """] = await """ + fn_name + """.asyncio
f.write("\n")
f.write(
"def _build_response(*, response: httpx.Response) -> Response[Union[Any, " +
", ".join(endoint_refs) +
", ".join(endpoint_refs) +
"]]:\n")
f.write("\treturn Response(\n")
f.write("\t\tstatus_code=response.status_code,\n")
@ -395,7 +395,7 @@ response: Response[""" + success_type + """] = await """ + fn_name + """.asyncio
f.write("\t*,\n")
f.write("\tclient: Client,\n")
f.write(") -> Response[Union[Any, " +
", ".join(endoint_refs) +
", ".join(endpoint_refs) +
"]]:\n")
f.write("\tkwargs = _get_kwargs(\n")
# Iterate over the parameters.
@ -464,7 +464,7 @@ response: Response[""" + success_type + """] = await """ + fn_name + """.asyncio
f.write("\t*,\n")
f.write("\tclient: Client,\n")
f.write(") -> Optional[Union[Any, " +
", ".join(endoint_refs) +
", ".join(endpoint_refs) +
"]]:\n")
if 'description' in endpoint:
f.write("\t\"\"\" " + endpoint['description'] + " \"\"\"\n")
@ -529,7 +529,7 @@ response: Response[""" + success_type + """] = await """ + fn_name + """.asyncio
f.write("\t*,\n")
f.write("\tclient: Client,\n")
f.write(") -> Response[Union[Any, " +
", ".join(endoint_refs) +
", ".join(endpoint_refs) +
"]]:\n")
f.write("\tkwargs = _get_kwargs(\n")
# Iterate over the parameters.
@ -596,7 +596,7 @@ response: Response[""" + success_type + """] = await """ + fn_name + """.asyncio
f.write("\t*,\n")
f.write("\tclient: Client,\n")
f.write(") -> Optional[Union[Any, " +
", ".join(endoint_refs) +
", ".join(endpoint_refs) +
"]]:\n")
if 'description' in endpoint:
f.write("\t\"\"\" " + endpoint['description'] + " \"\"\"\n")
@ -655,6 +655,7 @@ def generateTypes(cwd: str, parser: dict):
schema = schemas[key]
print("generating schema: ", key)
generateType(path, key, schema)
if 'oneOf' not in schema:
f.write("from ." + camel_to_snake(key) + " import " + key + "\n")
# Close the file.
@ -693,10 +694,6 @@ def generateType(path: str, name: str, schema: dict):
def generateOneOfType(path: str, name: str, schema: dict):
print("generating type: ", name, " at: ", path)
print(" schema: ", [schema])
f = open(path, "w")
for t in schema['oneOf']:
# Get the name for the reference.
if '$ref' in t:
@ -707,9 +704,6 @@ def generateOneOfType(path: str, name: str, schema: dict):
print(" oneOf must be a ref: ", name)
raise Exception(" oneOf must be a ref ", name)
# Close the file.
f.close()
def generateStringType(path: str, name: str, schema: dict, type_name: str):
print("generating type: ", name, " at: ", path)
@ -1312,7 +1306,18 @@ def getEndpointRefs(endpoint: dict, data: dict) -> [str]:
if content_type == 'application/json':
json = content[content_type]['schema']
if '$ref' in json:
ref = json['$ref'].replace('#/components/schemas/', '')
# If the reference is to a oneOf type, we want to return
# all the possible outcomes.
ref = json['$ref'].replace(
'#/components/schemas/', '')
schema = data['components']['schemas'][ref]
if 'oneOf' in schema:
for t in schema['oneOf']:
ref = t['$ref'].replace(
'#/components/schemas/', '')
if ref not in refs:
refs.append(ref)
else:
if ref not in refs:
refs.append(ref)
elif 'type' in json:

View File

@ -3,7 +3,9 @@ from typing import Any, Dict, Optional, Union, cast
import httpx
from ...client import Client
from ...models.async_api_call_output import AsyncApiCallOutput
from ...models.file_conversion import FileConversion
from ...models.file_mass import FileMass
from ...models.file_volume import FileVolume
from ...models.error import Error
from ...types import Response
@ -25,7 +27,7 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, AsyncApiCallOutput, Error]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
if response.status_code == 200:
response_200 = AsyncApiCallOutput.from_dict(response.json())
return response_200
@ -38,7 +40,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, AsyncApi
return None
def _build_response(*, response: httpx.Response) -> Response[Union[Any, AsyncApiCallOutput, Error]]:
def _build_response(*, response: httpx.Response) -> Response[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -51,7 +53,7 @@ def sync_detailed(
id: str,
*,
client: Client,
) -> Response[Union[Any, AsyncApiCallOutput, Error]]:
) -> Response[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
kwargs = _get_kwargs(
id=id,
client=client,
@ -69,7 +71,7 @@ def sync(
id: str,
*,
client: Client,
) -> Optional[Union[Any, AsyncApiCallOutput, Error]]:
) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
""" Get the status and output of an async operation.
This endpoint requires authentication by any KittyCAD user. It returns details of the requested async operation for the user.
If the user is not authenticated to view the specified async operation, then it is not returned.
@ -85,7 +87,7 @@ async def asyncio_detailed(
id: str,
*,
client: Client,
) -> Response[Union[Any, AsyncApiCallOutput, Error]]:
) -> Response[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
kwargs = _get_kwargs(
id=id,
client=client,
@ -101,7 +103,7 @@ async def asyncio(
id: str,
*,
client: Client,
) -> Optional[Union[Any, AsyncApiCallOutput, Error]]:
) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
""" Get the status and output of an async operation.
This endpoint requires authentication by any KittyCAD user. It returns details of the requested async operation for the user.
If the user is not authenticated to view the specified async operation, then it is not returned.

View File

@ -3,7 +3,9 @@ from typing import Any, Dict, Optional, Union, cast
import httpx
from ...client import Client
from ...models.async_api_call_output import AsyncApiCallOutput
from ...models.file_conversion import FileConversion
from ...models.file_mass import FileMass
from ...models.file_volume import FileVolume
from ...models.error import Error
from ...types import Response
@ -25,7 +27,7 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, AsyncApiCallOutput, Error]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
if response.status_code == 200:
response_200 = AsyncApiCallOutput.from_dict(response.json())
return response_200
@ -38,7 +40,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, AsyncApi
return None
def _build_response(*, response: httpx.Response) -> Response[Union[Any, AsyncApiCallOutput, Error]]:
def _build_response(*, response: httpx.Response) -> Response[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -51,7 +53,7 @@ def sync_detailed(
id: str,
*,
client: Client,
) -> Response[Union[Any, AsyncApiCallOutput, Error]]:
) -> Response[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
kwargs = _get_kwargs(
id=id,
client=client,
@ -69,7 +71,7 @@ def sync(
id: str,
*,
client: Client,
) -> Optional[Union[Any, AsyncApiCallOutput, Error]]:
) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
""" Get the status and output of an async file conversion.
This endpoint requires authentication by any KittyCAD user. It returns details of the requested file conversion for the user.
If the user is not authenticated to view the specified file conversion, then it is not returned.
@ -85,7 +87,7 @@ async def asyncio_detailed(
id: str,
*,
client: Client,
) -> Response[Union[Any, AsyncApiCallOutput, Error]]:
) -> Response[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
kwargs = _get_kwargs(
id=id,
client=client,
@ -101,7 +103,7 @@ async def asyncio(
id: str,
*,
client: Client,
) -> Optional[Union[Any, AsyncApiCallOutput, Error]]:
) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
""" Get the status and output of an async file conversion.
This endpoint requires authentication by any KittyCAD user. It returns details of the requested file conversion for the user.
If the user is not authenticated to view the specified file conversion, then it is not returned.

View File

@ -3,7 +3,9 @@ from typing import Any, Dict, Optional, Union, cast
import httpx
from ...client import Client
from ...models.async_api_call_output import AsyncApiCallOutput
from ...models.file_conversion import FileConversion
from ...models.file_mass import FileMass
from ...models.file_volume import FileVolume
from ...models.error import Error
from ...types import Response
@ -25,7 +27,7 @@ def _get_kwargs(
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, AsyncApiCallOutput, Error]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
if response.status_code == 200:
response_200 = AsyncApiCallOutput.from_dict(response.json())
return response_200
@ -38,7 +40,7 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[Any, AsyncApi
return None
def _build_response(*, response: httpx.Response) -> Response[Union[Any, AsyncApiCallOutput, Error]]:
def _build_response(*, response: httpx.Response) -> Response[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -51,7 +53,7 @@ def sync_detailed(
id: str,
*,
client: Client,
) -> Response[Union[Any, AsyncApiCallOutput, Error]]:
) -> Response[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
kwargs = _get_kwargs(
id=id,
client=client,
@ -69,7 +71,7 @@ def sync(
id: str,
*,
client: Client,
) -> Optional[Union[Any, AsyncApiCallOutput, Error]]:
) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
""" Get the status and output of an async file conversion. If completed, the contents of the converted file (`output`) will be returned as a base64 encoded string.
This endpoint requires authentication by any KittyCAD user. It returns details of the requested file conversion for the user. """
@ -83,7 +85,7 @@ async def asyncio_detailed(
id: str,
*,
client: Client,
) -> Response[Union[Any, AsyncApiCallOutput, Error]]:
) -> Response[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
kwargs = _get_kwargs(
id=id,
client=client,
@ -99,7 +101,7 @@ async def asyncio(
id: str,
*,
client: Client,
) -> Optional[Union[Any, AsyncApiCallOutput, Error]]:
) -> Optional[Union[Any, FileConversion, FileMass, FileVolume, Error]]:
""" Get the status and output of an async file conversion. If completed, the contents of the converted file (`output`) will be returned as a base64 encoded string.
This endpoint requires authentication by any KittyCAD user. It returns details of the requested file conversion for the user. """

View File

@ -8,7 +8,6 @@ from .api_call_with_price import ApiCallWithPrice
from .api_call_with_price_results_page import ApiCallWithPriceResultsPage
from .api_token import ApiToken
from .api_token_results_page import ApiTokenResultsPage
from .async_api_call_output import AsyncApiCallOutput
from .billing_info import BillingInfo
from .cache_metadata import CacheMetadata
from .card_details import CardDetails

View File

@ -3079,7 +3079,7 @@
"libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#APICallService.GetAsyncOperation"
},
"x-python": {
"example": "from kittycad.models import AsyncApiCallOutput\nfrom kittycad.api.api-calls import get_async_operation\nfrom kittycad.types import Response\n\nfc: AsyncApiCallOutput = get_async_operation.sync(client=client, id=)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[AsyncApiCallOutput] = get_async_operation.sync_detailed(client=client, id=)\n\n# OR run async\nfc: AsyncApiCallOutput = await get_async_operation.asyncio(client=client, id=)\n\n# OR run async with more info\nresponse: Response[AsyncApiCallOutput] = await get_async_operation.asyncio_detailed(client=client, id=)",
"example": "from kittycad.models import FileConversion\nfrom kittycad.api.api-calls import get_async_operation\nfrom kittycad.types import Response\n\nfc: FileConversion = get_async_operation.sync(client=client, id=)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[FileConversion] = get_async_operation.sync_detailed(client=client, id=)\n\n# OR run async\nfc: FileConversion = await get_async_operation.asyncio(client=client, id=)\n\n# OR run async with more info\nresponse: Response[FileConversion] = await get_async_operation.asyncio_detailed(client=client, id=)",
"libDocsLink": "https://python.api.docs.kittycad.io/modules/kittycad.api.api-calls.get_async_operation.html"
}
}
@ -3288,7 +3288,7 @@
"libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#FileService.GetConversion"
},
"x-python": {
"example": "from kittycad.models import AsyncApiCallOutput\nfrom kittycad.api.file import get_file_conversion_with_base64_helper\nfrom kittycad.types import Response\n\nfc: AsyncApiCallOutput = get_file_conversion_with_base64_helper.sync(client=client, id=)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[AsyncApiCallOutput] = get_file_conversion_with_base64_helper.sync_detailed(client=client, id=)\n\n# OR run async\nfc: AsyncApiCallOutput = await get_file_conversion_with_base64_helper.asyncio(client=client, id=)\n\n# OR run async with more info\nresponse: Response[AsyncApiCallOutput] = await get_file_conversion_with_base64_helper.asyncio_detailed(client=client, id=)",
"example": "from kittycad.models import FileConversion\nfrom kittycad.api.file import get_file_conversion_with_base64_helper\nfrom kittycad.types import Response\n\nfc: FileConversion = get_file_conversion_with_base64_helper.sync(client=client, id=)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[FileConversion] = get_file_conversion_with_base64_helper.sync_detailed(client=client, id=)\n\n# OR run async\nfc: FileConversion = await get_file_conversion_with_base64_helper.asyncio(client=client, id=)\n\n# OR run async with more info\nresponse: Response[FileConversion] = await get_file_conversion_with_base64_helper.asyncio_detailed(client=client, id=)",
"libDocsLink": "https://python.api.docs.kittycad.io/modules/kittycad.api.file.get_file_conversion_with_base64_helper.html"
}
}
@ -4854,7 +4854,7 @@
"libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#FileService.GetConversionForUser"
},
"x-python": {
"example": "from kittycad.models import AsyncApiCallOutput\nfrom kittycad.api.file import get_file_conversion_for_user\nfrom kittycad.types import Response\n\nfc: AsyncApiCallOutput = get_file_conversion_for_user.sync(client=client, id=)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[AsyncApiCallOutput] = get_file_conversion_for_user.sync_detailed(client=client, id=)\n\n# OR run async\nfc: AsyncApiCallOutput = await get_file_conversion_for_user.asyncio(client=client, id=)\n\n# OR run async with more info\nresponse: Response[AsyncApiCallOutput] = await get_file_conversion_for_user.asyncio_detailed(client=client, id=)",
"example": "from kittycad.models import FileConversion\nfrom kittycad.api.file import get_file_conversion_for_user\nfrom kittycad.types import Response\n\nfc: FileConversion = get_file_conversion_for_user.sync(client=client, id=)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[FileConversion] = get_file_conversion_for_user.sync_detailed(client=client, id=)\n\n# OR run async\nfc: FileConversion = await get_file_conversion_for_user.asyncio(client=client, id=)\n\n# OR run async with more info\nresponse: Response[FileConversion] = await get_file_conversion_for_user.asyncio_detailed(client=client, id=)",
"libDocsLink": "https://python.api.docs.kittycad.io/modules/kittycad.api.file.get_file_conversion_for_user.html"
}
}