better json

Signed-off-by: Jess Frazelle <github@jessfraz.com>
This commit is contained in:
Jess Frazelle
2022-02-27 22:19:21 -08:00
parent 5fcd6d048e
commit 65e95eae3d
2 changed files with 61 additions and 6 deletions

View File

@ -117,24 +117,51 @@ def generatePath(
request_body_type = getRequestBodyType(endpoint) request_body_type = getRequestBodyType(endpoint)
success_type = endoint_refs[0] 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 = "\"<uuid>\""
else:
parameter_type = "\"<string>\""
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 + """ 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 from kittycad.types import Response
fc: """ + success_type + """ = """+fn_name""".sync(client=client, id="<uuid_of_your_conversion>") fc: """ + success_type + """ = """ + fn_name + """.sync(client=client""" + params_str + """)
# OR if you need more info (e.g. status_code) # OR if you need more info (e.g. status_code)
response: Response[""" + success_type + """] = """+fn_name""".sync_detailed(client=client, id="<uuid_of_your_conversion>") response: Response[""" + success_type + """] = """ + fn_name + """.sync_detailed(client=client""" + params_str + """)
# OR run async # OR run async
fc: """ + success_type + """ = await """+fn_name""".asyncio(client=client, id="<uuid_of_your_conversion>") fc: """ + success_type + """ = await """ + fn_name + """.asyncio(client=client""" + params_str + """)
# OR run async with more info # OR run async with more info
response: Response[""" + success_type + """] = await """+fn_name""".asyncio_detailed(client=client, id="<uuid_of_your_conversion>")""" response: Response[""" + success_type + """] = await """ + fn_name + """.asyncio_detailed(client=client""" + params_str + """)"""
# Add our example to our json output. # Add our example to our json output.
data['paths'][name][method]['x-python'] = { data['paths'][name][method]['x-python'] = {
'example': example, 'example': example,
'libDocsLink': '',
} }
# Add our imports. # Add our imports.

View File

@ -365,6 +365,10 @@
"x-go": { "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()", "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" "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": { "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()", "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" "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": { "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()", "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" "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": { "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()", "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" "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": { "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)", "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" "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": { "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)", "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" "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": { "x-go": {
"example": "// Ping: Ping\n//\n// Simple ping to the server.\npongMessage, err := client.Meta.Ping()", "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" "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": ""
} }
} }
} }