Schema
/ API Reference / ConvertersSchema
/ API Reference / ConverterstoZodEnum
A function that converts a JSON enum schema to a Zod enum schema.
The Gist
import { toZodArray, T_JSONSchemaEnum } from '@weser/schema'
const json: T_JSONSchemaEnum = {
enum: ['foo', 'bar'],
}
const schema = toZodEnum(json)
// You can now use the schema as is
schema.safeParse('foo')
Parameters
Parameter | Type | Description |
---|---|---|
schema | T_JSONSchemaEnum | The JSON enum schema to convert to a Zod enum schema. |
Returns
(ZodEnum
) A Zod enum schema.
© 2024-present Robin Weser. All Rights Reserved.