Schema
/ API Reference / Converters
Schema
/ API Reference / Converters

toZodEnum

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

ParameterTypeDescription
schemaT_JSONSchemaEnumThe JSON enum schema to convert to a Zod enum schema.

Returns

(ZodEnum) A Zod enum schema.

On this page