Skip to content
Merged
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
4 changes: 4 additions & 0 deletions packages/schema/src/plugins/zod/utils/schema-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ export function makeFieldSchema(field: DataModelField, respectDefault = false) {
schema += `.toUpperCase()`;
break;
}
case '@db.Uuid': {
schema += `.uuid()`;
break;
}
case '@datetime': {
schema += `.datetime({ offset: true${message ? ', message: ' + JSON.stringify(message) : ''} })`;
break;
Expand Down
5 changes: 5 additions & 0 deletions tests/integration/tests/plugins/zod.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/// <reference types="@types/jest" />

import { loadSchema } from '@zenstackhq/testtools';
import { randomUUID } from 'crypto';
import fs from 'fs';
import path from 'path';

Expand Down Expand Up @@ -235,6 +236,7 @@ describe('Zod plugin tests', () => {
o Int? @lt(1, 'must be less than 1')
p Int? @lte(1, 'must be less than or equal to 1')
q Int[]
r String? @db.Uuid
}
`;

Expand Down Expand Up @@ -295,6 +297,9 @@ describe('Zod plugin tests', () => {

expect(schema.safeParse({ q: [1] }).success).toBeTruthy();
expect(schema.safeParse({ q: ['abc'] }).success).toBeFalsy();

expect(schema.safeParse({ r: 'abc' }).success).toBeFalsy();
expect(schema.safeParse({ r: randomUUID() }).success).toBeTruthy();
});

it('refinement scalar fields', async () => {
Expand Down