@@ -19,7 +19,7 @@ import {
1919 isReferenceObject ,
2020 isSchemaObject ,
2121} from "src/generators/utils/openapi-schema.utils" ;
22- import { escapeControlCharacters , isPrimitiveType , wrapWithQuotesIfNeeded } from "src/generators/utils/openapi.utils" ;
22+ import { isPrimitiveType , wrapWithQuotesIfNeeded } from "src/generators/utils/openapi.utils" ;
2323import { match } from "ts-pattern" ;
2424import { getParentRef , ZodSchema , ZodSchemaMetaData } from "./ZodSchema.class" ;
2525import { getZodChain } from "./getZodChain" ;
@@ -345,33 +345,20 @@ function getPrimitiveZodSchema({ schema, zodSchema, resolver, meta, tag }: GetPa
345345 . with ( "integer" , ( ) => INT_SCHEMA )
346346 . otherwise ( ( ) => NUMBER_SCHEMA ) ,
347347 )
348- . with ( "string" , ( ) => {
349- if ( schema . pattern ) {
350- return `z.regex(${ formatPatternIfNeeded ( schema . pattern ) } )` ;
351- }
352- return match ( schema . format )
348+ . with ( "string" , ( ) =>
349+ match ( schema . format )
353350 . with ( "binary" , ( ) => BLOB_SCHEMA )
354351 . with ( "email" , ( ) => EMAIL_SCHEMA )
355352 . with ( "hostname" , "uri" , ( ) => URL_SCHEMA )
356353 . with ( "uuid" , ( ) => UUID_SCHEMA )
357354 . with ( "date-time" , ( ) => DATETIME_SCHEMA )
358- . otherwise ( ( ) => STRING_SCHEMA ) ;
359- } )
355+ . otherwise ( ( ) => STRING_SCHEMA ) ,
356+ )
360357 . otherwise ( ( type ) => `z.${ type } ()` ) ,
361358 ) ;
362359 }
363360}
364361
365- function formatPatternIfNeeded ( pattern : string ) {
366- if ( pattern . startsWith ( "/" ) && pattern . endsWith ( "/" ) ) {
367- pattern = pattern . slice ( 1 , - 1 ) ;
368- }
369-
370- pattern = escapeControlCharacters ( pattern ) ;
371-
372- return `/${ pattern } /` ;
373- }
374-
375362function getEnumZodSchema ( { resolver, schema, zodSchema, meta, tag } : GetPartialZodSchemaParams ) {
376363 if ( ! isSchemaObject ( schema ) ) {
377364 return ;
0 commit comments