Skip to content

Commit

Permalink
do not validate the schema in stringJSONSchemaToZuiString
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-botpress committed Feb 24, 2025
1 parent 8965f1d commit ac585da
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions zui/src/transforms/json-schema-to-zui-next/primitives/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ import { zodPatterns } from '../../zui-to-json-schema/parsers/string'
import z from '../../../z'
import * as datetime from '../../../z/types/string/datetime'

const stringSchema = z.object({
type: z.literal('string'),
format: z.enum(['cuid', 'cuid2', 'emoji', 'ulid', 'date-time', 'email', 'ipv4', 'ipv6', 'uri', 'uuid']).optional(),
pattern: z.string().optional(),
minLength: z.number().optional(),
maxLength: z.number().optional(),
})

export const stringJSONSchemaToZuiString = (schema: JSONSchema7): z.ZodString => {
export const stringJSONSchemaToZuiString = ({
format,
pattern,
minLength,
maxLength,
}: JSONSchema7 & { type: 'string' }): z.ZodString => {
let zodString = z.string()
const { format, pattern, minLength, maxLength } = stringSchema.parse(schema)

if (minLength && maxLength && minLength === maxLength) {
zodString = zodString.length(minLength)
Expand Down

0 comments on commit ac585da

Please sign in to comment.