diff --git a/generate/generate.py b/generate/generate.py index 0b7833e41..c12c20bc8 100755 --- a/generate/generate.py +++ b/generate/generate.py @@ -100,7 +100,7 @@ def generatePath( data: dict) -> dict: # Generate the path. fn_name = camel_to_snake(endpoint['operationId']) - file_name = fn_name + '.py' + file_name = fn_name + '.py' tag_name = '' # Add the tag to the path if it exists. if 'tags' in endpoint: @@ -117,24 +117,51 @@ def generatePath( request_body_type = getRequestBodyType(endpoint) success_type = endoint_refs[0] + + if fn_name == 'file_conversion_status' or fn_name == 'post_file_conversion': + fn_name = 'file_conversion_status_with_base64_helper' + + # Iterate over the parameters. + params_str = '' + if 'parameters' in endpoint: + parameters = endpoint['parameters'] + for parameter in parameters: + parameter_name = parameter['name'] + parameter_type = '' + if 'type' in parameter['schema']: + if 'format' in parameter['schema']: + if parameter['schema']['format'] == 'uuid': + parameter_type = "\"\"" + else: + parameter_type = "\"\"" + elif '$ref' in parameter['schema']: + parameter_type = parameter['schema']['$ref'].replace( + '#/components/schemas/', '') + else: + print(" parameter: ", parameter) + raise Exception("Unknown parameter type") + params_str += ', ' + \ + camel_to_snake(parameter_name) + '=' + parameter_type + example = """from kittycad.models import """ + success_type + """ -from kittycad.api."""+tag_name+""" import """+fn_name+""" +from kittycad.api.""" + tag_name + """ import """ + fn_name + """ from kittycad.types import Response -fc: """ + success_type + """ = """+fn_name""".sync(client=client, id="") +fc: """ + success_type + """ = """ + fn_name + """.sync(client=client""" + params_str + """) # OR if you need more info (e.g. status_code) -response: Response[""" + success_type + """] = """+fn_name""".sync_detailed(client=client, id="") +response: Response[""" + success_type + """] = """ + fn_name + """.sync_detailed(client=client""" + params_str + """) # OR run async -fc: """ + success_type + """ = await """+fn_name""".asyncio(client=client, id="") +fc: """ + success_type + """ = await """ + fn_name + """.asyncio(client=client""" + params_str + """) # OR run async with more info -response: Response[""" + success_type + """] = await """+fn_name""".asyncio_detailed(client=client, id="")""" +response: Response[""" + success_type + """] = await """ + fn_name + """.asyncio_detailed(client=client""" + params_str + """)""" # Add our example to our json output. data['paths'][name][method]['x-python'] = { 'example': example, + 'libDocsLink': '', } # Add our imports. diff --git a/spec.json b/spec.json index 54f8965e6..4f30a659e 100644 --- a/spec.json +++ b/spec.json @@ -365,6 +365,10 @@ "x-go": { "example": "// StopAsyncConversions: Stop all async conversions\n//\n// Stop all async conversions that are currently running. This endpoint can only be used by specific KittyCAD employees.\nfileConversion, err := client.Internal.StopAsyncConversions()", "libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#InternalService.StopAsyncConversions" + }, + "x-python": { + "example": "from kittycad.models import FileConversion\nfrom kittycad.api.internal import stop_async_conversions\nfrom kittycad.types import Response\n\nfc: FileConversion = stop_async_conversions.sync(client=client)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[FileConversion] = stop_async_conversions.sync_detailed(client=client)\n\n# OR run async\nfc: FileConversion = await stop_async_conversions.asyncio(client=client)\n\n# OR run async with more info\nresponse: Response[FileConversion] = await stop_async_conversions.asyncio_detailed(client=client)", + "libDocsLink": "" } } }, @@ -405,6 +409,10 @@ "x-go": { "example": "// GPUDevices: Get GPU devices\n//\n// Get information about GPU devices on this server. This is primarily used for debugging. This endpoint can only be used by specific KittyCAD employees.\nGPUDevice, err := client.Internal.GPUDevices()", "libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#InternalService.GPUDevices" + }, + "x-python": { + "example": "from kittycad.models import ErrorMessage\nfrom kittycad.api.internal import gpu_devices\nfrom kittycad.types import Response\n\nfc: ErrorMessage = gpu_devices.sync(client=client)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[ErrorMessage] = gpu_devices.sync_detailed(client=client)\n\n# OR run async\nfc: ErrorMessage = await gpu_devices.asyncio(client=client)\n\n# OR run async with more info\nresponse: Response[ErrorMessage] = await gpu_devices.asyncio_detailed(client=client)", + "libDocsLink": "" } } }, @@ -442,6 +450,10 @@ "x-go": { "example": "// InstanceMetadata: Get instance metadata\n//\n// Get information about this specific API server instance. This is primarily used for debugging.\ninstance, err := client.Meta.InstanceMetadata()", "libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#MetaService.InstanceMetadata" + }, + "x-python": { + "example": "from kittycad.models import Instance\nfrom kittycad.api.meta import instance_metadata\nfrom kittycad.types import Response\n\nfc: Instance = instance_metadata.sync(client=client)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[Instance] = instance_metadata.sync_detailed(client=client)\n\n# OR run async\nfc: Instance = await instance_metadata.asyncio(client=client)\n\n# OR run async with more info\nresponse: Response[Instance] = await instance_metadata.asyncio_detailed(client=client)", + "libDocsLink": "" } } }, @@ -479,6 +491,10 @@ "x-go": { "example": "// AuthSession: Get auth session\n//\n// Get information about your API request session. This is primarily used for debugging.\nauthSession, err := client.Meta.AuthSession()", "libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#MetaService.AuthSession" + }, + "x-python": { + "example": "from kittycad.models import AuthSession\nfrom kittycad.api.meta import auth_session\nfrom kittycad.types import Response\n\nfc: AuthSession = auth_session.sync(client=client)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[AuthSession] = auth_session.sync_detailed(client=client)\n\n# OR run async\nfc: AuthSession = await auth_session.asyncio(client=client)\n\n# OR run async with more info\nresponse: Response[AuthSession] = await auth_session.asyncio_detailed(client=client)", + "libDocsLink": "" } } }, @@ -537,6 +553,10 @@ "x-go": { "example": "// ConversionStatus: Get a file conversion\n//\n// Get the status and output of an async file conversion.\n//\n// Parameters:\n//\t- `id`: The id of the file conversion.\nfileConversion, err := client.File.ConversionStatus(id)", "libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#FileService.ConversionStatus" + }, + "x-python": { + "example": "from kittycad.models import FileConversion\nfrom kittycad.api.file import file_conversion_status_with_base64_helper\nfrom kittycad.types import Response\n\nfc: FileConversion = file_conversion_status_with_base64_helper.sync(client=client, id=)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[FileConversion] = file_conversion_status_with_base64_helper.sync_detailed(client=client, id=)\n\n# OR run async\nfc: FileConversion = await file_conversion_status_with_base64_helper.asyncio(client=client, id=)\n\n# OR run async with more info\nresponse: Response[FileConversion] = await file_conversion_status_with_base64_helper.asyncio_detailed(client=client, id=)", + "libDocsLink": "" } } }, @@ -624,6 +644,10 @@ "x-go": { "example": "// PostConversion: Convert CAD file\n//\n// Convert a CAD file from one format to another. If the file being converted is larger than 30MB, it will be performed asynchronously.\n//\n// Parameters:\n//\t- `outputFormat`: The format the file should be converted to.\n//\t- `sourceFormat`: The format of the file to convert.\nfileConversion, err := client.File.PostConversion(sourceFormat, outputFormat)", "libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#FileService.PostConversion" + }, + "x-python": { + "example": "from kittycad.models import FileConversion\nfrom kittycad.api.file import file_conversion_status_with_base64_helper\nfrom kittycad.types import Response\n\nfc: FileConversion = file_conversion_status_with_base64_helper.sync(client=client, source_format=ValidSourceFileFormat, output_format=ValidOutputFileFormat)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[FileConversion] = file_conversion_status_with_base64_helper.sync_detailed(client=client, source_format=ValidSourceFileFormat, output_format=ValidOutputFileFormat)\n\n# OR run async\nfc: FileConversion = await file_conversion_status_with_base64_helper.asyncio(client=client, source_format=ValidSourceFileFormat, output_format=ValidOutputFileFormat)\n\n# OR run async with more info\nresponse: Response[FileConversion] = await file_conversion_status_with_base64_helper.asyncio_detailed(client=client, source_format=ValidSourceFileFormat, output_format=ValidOutputFileFormat)", + "libDocsLink": "" } } }, @@ -650,6 +674,10 @@ "x-go": { "example": "// Ping: Ping\n//\n// Simple ping to the server.\npongMessage, err := client.Meta.Ping()", "libDocsLink": "https://pkg.go.dev/github.com/kittycad/kittycad.go/#MetaService.Ping" + }, + "x-python": { + "example": "from kittycad.models import PongMessage\nfrom kittycad.api.meta import ping\nfrom kittycad.types import Response\n\nfc: PongMessage = ping.sync(client=client)\n\n# OR if you need more info (e.g. status_code)\nresponse: Response[PongMessage] = ping.sync_detailed(client=client)\n\n# OR run async\nfc: PongMessage = await ping.asyncio(client=client)\n\n# OR run async with more info\nresponse: Response[PongMessage] = await ping.asyncio_detailed(client=client)", + "libDocsLink": "" } } }