Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions js/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@opentelemetry/sdk-node": "^0.49.0",
"@opentelemetry/sdk-trace-base": "^1.22.0",
"ajv": "^8.12.0",
"ajv-formats": "^3.0.1",
"async-mutex": "^0.5.0",
"express": "^4.19.2",
"json-schema": "^0.4.0",
Expand Down
2 changes: 2 additions & 0 deletions js/core/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/

import Ajv, { ErrorObject, JSONSchemaType } from 'ajv';
import addFormats from 'ajv-formats';
import { z } from 'zod';
import zodToJsonSchema from 'zod-to-json-schema';
import { GenkitError } from './error.js';
const ajv = new Ajv();
addFormats(ajv);

export { z }; // provide a consistent zod to use throughout genkit
export type JSONSchema = JSONSchemaType<any> | any;
Expand Down
6 changes: 6 additions & 0 deletions js/core/tests/schema_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ describe('validate()', () => {
valid: false,
errors: [{ path: 'foo', message: 'must be boolean' }],
},
{
it: 'should allow for date types',
schema: z.object({ date: z.string().datetime() }),
data: { date: '2024-05-22T17:00:00Z' },
valid: true,
},
{
it: 'should return dotted path for errors',
schema: z.object({ foo: z.array(z.object({ bar: z.boolean() })) }),
Expand Down
15 changes: 15 additions & 0 deletions js/pnpm-lock.yaml

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