diff --git a/README.md b/README.md index ed549ee..ca0dd9a 100644 --- a/README.md +++ b/README.md @@ -560,6 +560,8 @@ The list of all supported types as of now is: - `.uuid()` - `.email()` - `.url()` + - `.duration()` + - `.time()` - adding `pattern` for `.regex()` is also supported diff --git a/spec/types/string.spec.ts b/spec/types/string.spec.ts index 83af082..c54ffee 100644 --- a/spec/types/string.spec.ts +++ b/spec/types/string.spec.ts @@ -51,6 +51,8 @@ describe('string', () => { ${'url'} | ${z.string().url()} | ${'uri'} ${'date'} | ${z.string().date()} | ${'date'} ${'datetime'} | ${z.string().datetime()} | ${'date-time'} + ${'duration'} | ${z.string().duration()} | ${'duration'} + ${'time'} | ${z.string().time()} | ${'time'} `( 'maps a ZodString $format to $expected format', ({ zodString, expected }: { zodString: ZodString; expected: string }) => { @@ -69,7 +71,11 @@ describe('string', () => { .openapi('RegexString'), ], { - RegexString: { type: 'string', pattern: '^hello world' }, + RegexString: { + type: 'string', + pattern: '^hello world', + format: 'regex', + }, } ); }); diff --git a/src/transformers/string.ts b/src/transformers/string.ts index 9bc22c9..66e897a 100644 --- a/src/transformers/string.ts +++ b/src/transformers/string.ts @@ -40,6 +40,9 @@ export class StringTransformer { if (zodString.isULID) return 'ulid'; if (zodString.isIP) return 'ip'; if (zodString.isEmoji) return 'emoji'; + if (zodString.isTime) return 'time'; + if (zodString.isDuration) return 'duration'; + if (this.getZodStringCheck(zodString, 'regex')) return 'regex'; return undefined; }