diff --git a/generator/konfig-next-app/src/utils/__snapshots__/code-generator-python.test.ts.snap b/generator/konfig-next-app/src/utils/__snapshots__/code-generator-python.test.ts.snap index 63cf04dfa8..ee46e92cf7 100644 --- a/generator/konfig-next-app/src/utils/__snapshots__/code-generator-python.test.ts.snap +++ b/generator/konfig-next-app/src/utils/__snapshots__/code-generator-python.test.ts.snap @@ -1,5 +1,24 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`deeply nested objects with file 1`] = ` +"from pprint import pprint +from groundx import Groundx + +groundx = Groundx( + api_key="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" +) + +response = groundx.documents.upload_local([{ + "blob": open("file.txt", "rb"), + "metadata": { + "bucket_id": 321, + "file_name": "321", + "file_type": "docx" + } +}]) +pprint(response.body)" +`; + exports[`example with boolean 1`] = ` "from pprint import pprint from snaptrade_client import SnapTrade @@ -101,7 +120,6 @@ response = groundx.documents.upload_local([{ "bucket_id": 321, "file_name": "321", "file_type": "txt", - "metadata": "", "callback_data": "321", "callback_url": "3213" } @@ -110,10 +128,7 @@ response = groundx.documents.upload_local([{ "metadata": { "bucket_id": 321, "file_name": "321", - "file_type": "txt", - "metadata": "", - "callback_data": "", - "callback_url": "" + "file_type": "txt" } }]) pprint(response.body)" diff --git a/generator/konfig-next-app/src/utils/code-generator-python.test.ts b/generator/konfig-next-app/src/utils/code-generator-python.test.ts index 03b0bf0a93..3b6113fb8d 100644 --- a/generator/konfig-next-app/src/utils/code-generator-python.test.ts +++ b/generator/konfig-next-app/src/utils/code-generator-python.test.ts @@ -2,6 +2,117 @@ import { HttpMethodsEnum } from 'konfig-lib' import { CodeGeneratorConstructorArgs } from './code-generator' import { CodeGeneratorPython } from './code-generator-python' +test('deeply nested objects with file', async () => { + const args: CodeGeneratorConstructorArgs = { + httpMethod: HttpMethodsEnum.POST, + path: '/v1/ingest/documents/local', + parameters: [], + requestBody: { + name: '', + in: 'body', + schema: { + type: 'array', + items: { + type: 'object', + required: ['blob', 'metadata'], + properties: { + blob: { + description: 'The actual file being uploaded.', + type: 'string', + format: 'binary', + }, + metadata: { + type: 'object', + required: ['bucketId', 'fileName', 'fileType'], + properties: { + bucketId: { + type: 'integer', + example: 1234, + }, + fileName: { + type: 'string', + example: 'my_file.txt', + }, + fileType: { + type: 'string', + enum: ['txt', 'docx', 'pptx', 'xlsx', 'pdf', 'png', 'jpg'], + }, + metadata: { + type: 'object', + example: { + key: 'value', + }, + }, + callbackData: { + type: 'string', + example: 'my_callback_data', + }, + callbackUrl: { + type: 'string', + example: 'https://my.callback.url.com', + }, + }, + }, + }, + }, + }, + isRequestBody: true, + }, + securitySchemes: { + ApiKeyAuth: { + type: 'apiKey', + in: 'header', + name: 'X-API-Key', + }, + }, + formData: { + parameters: { + documentId: '', + }, + security: { + ApiKeyAuth: { + type: 'apiKey', + in: 'header', + key: 'X-API-Key', + value: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX', + }, + }, + requestBody: [ + { + blob: new File([], 'file.txt'), + metadata: { + bucketId: 321, + fileName: '321', + fileType: 'docx', + metadata: '', + callbackData: '', + callbackUrl: '', + }, + }, + ], + }, + languageConfigurations: { + typescript: { + clientName: 'Groundx', + packageName: 'groundx-typescript-sdk', + }, + python: { + clientName: 'Groundx', + packageName: 'groundx', + }, + }, + servers: ['https://api.groundx.ai/api'], + operationId: 'Document_uploadLocal', + tag: 'Documents', + basePath: 'https://api.groundx.ai/api', + oauthTokenUrl: null, + originalOauthTokenUrl: null, + requestBodyRequired: false, + } + const code = await new CodeGeneratorPython(args).snippet() + expect(code).toMatchSnapshot() +}) + test('nested objects does not have empty properties', async () => { const args: CodeGeneratorConstructorArgs = { httpMethod: HttpMethodsEnum.POST, diff --git a/generator/konfig-next-app/src/utils/code-generator-python.ts b/generator/konfig-next-app/src/utils/code-generator-python.ts index a76de15019..d0a0628d83 100644 --- a/generator/konfig-next-app/src/utils/code-generator-python.ts +++ b/generator/konfig-next-app/src/utils/code-generator-python.ts @@ -119,7 +119,9 @@ from ${this.packageName} import ${this.clientName}` get args(): string { if (this.isArrayRequestBody) { - const arrayValue = this.requestBodyValue + const arrayValue = this.recursivelyRemoveEmptyValues( + this.requestBodyValue + ) if (Array.isArray(arrayValue)) { return `[${arrayValue .map((v) => this.toPythonLiteralString(v)) diff --git a/generator/konfig-next-app/src/utils/code-generator.ts b/generator/konfig-next-app/src/utils/code-generator.ts index 26535d53fb..ba4f625397 100644 --- a/generator/konfig-next-app/src/utils/code-generator.ts +++ b/generator/konfig-next-app/src/utils/code-generator.ts @@ -237,6 +237,8 @@ export abstract class CodeGenerator { return filtered } + if (object instanceof File) return object + const clone = { ...object } Object.entries(object).forEach(([key, value]) => { if (typeof value === 'object') {