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: zod additional properties error #972

Closed
Closed
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
3 changes: 3 additions & 0 deletions packages/zod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ export const parseZodValidationSchemaDefinition = (
}

if (fn === 'additionalProperties') {
if (isBoolean(args)) {
return args === true ? 'zod.record().passthrough()' : 'zod.record()'; //by default zod strips out non-specified properties, if additional properties are allowed, we want to make sure they are passed through
}
const value = args.functions.map(parseProperty).join('');
const valueWithZod = `${value.startsWith('.') ? 'zod' : ''}${value}`;
consts += args.consts;
Expand Down
9 changes: 9 additions & 0 deletions tests/configs/zod.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ export default defineConfig({
target: '../specifications/arrays.yaml',
},
},
additionalProperties: {
output: {
target: '../generated/zod',
client: 'zod',
},
input: {
target: '../specifications/additional-properties.yaml',
},
},
});
27 changes: 27 additions & 0 deletions tests/specifications/additional-properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
openapi: 3.0.0
info:
title: Additional properties
version: 0.0.0
paths:
/example:
get:
summary: Example
responses:
'200':
description: 'Example'
content:
application/json:
schema:
$ref: '#/components/schemas/Node'
components:
schemas:
Node:
type: object
properties:
id:
type: integer
name:
type: string
child:
type: object
additionalProperties: true
Loading