Skip to content

Commit

Permalink
fix(zod): proper date handling (#1050)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware authored Nov 15, 2023
1 parent e7aad27 commit 67856c2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/zod/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ const generateZodValidationSchemaDefinition = (
break;
}

functions.push([type as string, undefined]);

if (schema.format === 'date') {
functions.push(['regex', 'new RegExp(/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/)']);
functions.push(['date', undefined]);
break;
}

functions.push([type as string, undefined]);

if (schema.format === 'date-time') {
functions.push(['datetime', undefined]);
break;
Expand Down Expand Up @@ -204,7 +204,7 @@ const generateZodValidationSchemaDefinition = (
matches.slice(isStartWithSlash ? 1 : 0, isEndWithSlash ? -1 : undefined),
)}')`;

consts.push(`export const ${name}RegExp = ${regexp};`);
consts.push(`export const ${name}RegExp = ${regexp};\n`);
functions.push(['regex', `${name}RegExp`]);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/specifications/circular.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Node'
parameters:
- name: limit
in: query
description: How many items to return at one time (max 100)
required: false
schema:
type: string
pattern: '^\+\d{10, 15}'
- name: birthdate
in: query
description: birth date
required: false
schema:
type: string
format: 'date'
components:
schemas:
Node:
Expand Down

0 comments on commit 67856c2

Please sign in to comment.