Skip to content

Commit

Permalink
Support .date(), .time() and .duration() string formats (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
samchungy authored Apr 20, 2024
1 parent 1367ed8 commit 82fcd7b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"openapi3-ts": "4.3.1",
"skuba": "8.0.0",
"yaml": "2.4.1",
"zod": "3.22.4"
"zod": "3.23.0-beta.2"
},
"peerDependencies": {
"zod": "^3.21.4"
Expand Down
8 changes: 6 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/create/schema/parsers/string.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ describe('createStringSchema', () => {
${z.string().email()} | ${'email'}
${z.string().url()} | ${'uri'}
${z.string().datetime()} | ${'date-time'}
${z.string().date()} | ${'date'}
${z.string().time()} | ${'time'}
${z.string().duration()} | ${'duration'}
`(
'creates a string schema with $format',
({ zodString, format }: { zodString: ZodString; format: string }) => {
Expand Down
12 changes: 12 additions & 0 deletions src/create/schema/parsers/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ const mapStringFormat = (
return 'date-time';
}

if (zodStringChecks.date) {
return 'date';
}

if (zodStringChecks.time) {
return 'time';
}

if (zodStringChecks.duration) {
return 'duration';
}

if (zodStringChecks.email) {
return 'email';
}
Expand Down

0 comments on commit 82fcd7b

Please sign in to comment.