Skip to content

Commit

Permalink
fix nested values not being pruned
Browse files Browse the repository at this point in the history
  • Loading branch information
dphuang2 committed Oct 27, 2023
1 parent d989d96 commit e6088d0
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ response = snaptrade.options.get_option_strategy()
pprint(response.body)"
`;

exports[`nested objects does not have empty properties 1`] = `
"from pprint import pprint
from groundx import Groundx
groundx = Groundx(
api_key="XXXXX"
)
response = groundx.documents.upload_remote(
documents=[
{
"bucket_id": 1
}
]
)
pprint(response.body)"
`;

exports[`request body with blob values 1`] = `
"from pprint import pprint
from groundx import Groundx
Expand Down
165 changes: 165 additions & 0 deletions generator/konfig-next-app/src/utils/code-generator-python.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,171 @@ import { HttpMethodsEnum } from 'konfig-lib'
import { CodeGeneratorConstructorArgs } from './code-generator'
import { CodeGeneratorPython } from './code-generator-python'

test('nested objects does not have empty properties', async () => {
const args: CodeGeneratorConstructorArgs = {
httpMethod: HttpMethodsEnum.POST,
path: '/',
parameters: [
{
name: 'documents',
in: 'body',
schema: {
type: 'array',
items: {
type: 'object',
required: ['bucketId', 'sourceUrl'],
properties: {
bucketId: {
type: 'integer',
example: 1234,
},
sourceUrl: {
type: 'string',
example: 'https://my.source.url.com/file.txt',
},
callbackData: {
type: 'string',
example: 'my_callback_data',
},
callbackUrl: {
type: 'string',
example: 'https://my.callback.url.com',
},
metadata: {
type: 'object',
example: {
key: 'value',
},
},
type: {
type: 'string',
enum: ['txt', 'docx', 'pptx', 'xlsx', 'pdf', 'png', 'jpg'],
},
},
},
},
required: true,
},
],
requestBody: {
name: '',
in: 'body',
schema: {
type: 'object',
required: ['documents'],
properties: {
documents: {
type: 'array',
items: {
type: 'object',
required: ['bucketId', 'sourceUrl'],
properties: {
bucketId: {
type: 'integer',
example: 1234,
},
sourceUrl: {
type: 'string',
example: 'https://my.source.url.com/file.txt',
},
callbackData: {
type: 'string',
example: 'my_callback_data',
},
callbackUrl: {
type: 'string',
example: 'https://my.callback.url.com',
},
metadata: {
type: 'object',
example: {
key: 'value',
},
},
type: {
type: 'string',
enum: ['txt', 'docx', 'pptx', 'xlsx', 'pdf', 'png', 'jpg'],
},
},
},
},
},
},
isRequestBody: true,
},
securitySchemes: {
ApiKeyAuth: {
type: 'apiKey',
in: 'header',
name: 'X-API-Key',
},
},
formData: {
parameters: {
documents: [
{
bucketId: 1,
sourceUrl: '',
callbackData: '',
callbackUrl: '',
metadata: '',
type: '',
},
],
bucketId: '',
bucket: {
name: '',
},
documentId: '',
n: '',
nextToken: '',
id: '',
processId: '2fe69d3d-badf-43df-a665-0a49d00ba206',
},
security: {
ApiKeyAuth: {
type: 'apiKey',
in: 'header',
key: 'X-API-Key',
value: 'mykey',
},
},
requestBody: [
{
blob: {},
metadata: {
bucketId: 6124,
fileName: 'file.txt',
fileType: 'txt',
metadata: '',
callbackData: '',
callbackUrl: '',
},
},
],
},
languageConfigurations: {
typescript: {
clientName: 'Groundx',
packageName: 'groundx-typescript-sdk',
},
python: {
clientName: 'Groundx',
packageName: 'groundx',
},
},
servers: ['https://api.groundx.ai/api'],
operationId: 'Document_uploadRemote',
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('request body with blob values', async () => {
const args: CodeGeneratorConstructorArgs = {
parameters: [],
Expand Down
4 changes: 3 additions & 1 deletion generator/konfig-next-app/src/utils/code-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ export abstract class CodeGenerator {

if (Array.isArray(object)) {
// remove all empty values from array and return
const filtered = (object as any).filter((p: any) => this.isNonEmpty(p))
const filtered = (object as any)
.filter((p: any) => this.isNonEmpty(p))
.map((p: any) => this.recursivelyRemoveEmptyValues(p))
return filtered
}

Expand Down

0 comments on commit e6088d0

Please sign in to comment.