Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix handling of array of objects #20 #23

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/genSchema/getDetailsFromDefinition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ describe('getDetailsFromDefinition', () => {

expect(result.zodString).toBe('z.object({}).passthrough()')
})

it('returns a array schema with item type any', () => {
const result = getDetailsFromDefinition('DEFINE FIELD list ON TABLE product TYPE array;', isInputSchema)

expect(result.zodString).toBe('z.array(z.any())')
})

it('returns a array schema with item type array<string>', () => {
const result = getDetailsFromDefinition('DEFINE FIELD list ON TABLE product TYPE array<string>;', isInputSchema)

expect(result.zodString).toBe('z.array(z.string())')
})
})

describe('output schema', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/genSchema/mergeNested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { type FieldDetail, getDetailsFromDefinition } from './getDetailsFromDefi

export const mergeNested = (fields: Record<string, string>, isInputSchema: boolean) => {
const inputFields = Object.entries(fields)
// TODO: fix filter:
.filter(([fname, _definition]) => !fname.includes('['))
.map(([_fname, definition]) => {
return getDetailsFromDefinition(definition, isInputSchema)
})
Expand Down