Skip to content

Commit

Permalink
fix: mark the ZodDate as string type in the OpenAPI schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamote committed Dec 10, 2024
1 parent 2204eef commit 3b6100a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/nestjs-zod/src/openapi/zod-to-openapi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,16 @@ describe.each([

expect(openApiObject).toMatchSnapshot()
})


it('should serialize dates', () => {
const schema = z.date()
const openApiObject = zodToOpenAPI(schema)

expect(openApiObject).toEqual({
type: 'string',
})
});

it('should serialize objects', () => {
const schema = z.object({
prop1: z.string(),
Expand Down
4 changes: 4 additions & 0 deletions packages/nestjs-zod/src/openapi/zod-to-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export function zodToOpenAPI(
}
}

if (is(zodType, z.ZodDate)) {
object.type = 'string'
}

if (is(zodType, z.ZodPassword)) {
const { checks } = zodType._def
const regex = zodType.buildFullRegExp()
Expand Down

0 comments on commit 3b6100a

Please sign in to comment.