-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathschema.ts
More file actions
24 lines (20 loc) · 919 Bytes
/
Copy pathschema.ts
File metadata and controls
24 lines (20 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------------------------------------------*/
import type { ResponseSchema, ZodSchema } from "./types.js";
export function isZodSchema(value: unknown): value is ZodSchema {
return (
typeof value === "object" &&
value !== null &&
"toJSONSchema" in value &&
typeof value.toJSONSchema === "function"
);
}
export function toJsonSchema(
schema: ZodSchema | Record<string, unknown> | undefined
): Record<string, unknown> | undefined {
return isZodSchema(schema) ? schema.toJSONSchema() : schema;
}
export function isResponseSchema(value: unknown): value is ResponseSchema {
return isZodSchema(value) && "parse" in value && typeof value.parse === "function";
}