@@ -167,7 +167,7 @@ const intersect = (
167167 children : Array < JSONSchema . BaseSchema > ,
168168) : JSONSchema . ObjectSchema => {
169169 const [ left , right ] = children
170- . map ( ( { _ref , ... rest } ) => ( _ref ? { ... rest , ... _ref } : rest ) )
170+ . map ( unref )
171171 . filter (
172172 ( schema ) : schema is JSONSchema . ObjectSchema => schema . type === "object" ,
173173 )
@@ -204,7 +204,8 @@ const isSupportedType = (subject: string): subject is SchemaObjectType =>
204204export const onDateIn : Overrider = ( { jsonSchema } , ctx ) => {
205205 if ( ctx . isResponse )
206206 throw new DocumentationError ( "Please use ez.dateOut() for output." , ctx ) ;
207- delete jsonSchema . _ref ; // undo default
207+ unref ( jsonSchema ) ;
208+ delete jsonSchema . anyOf ; // undo default
208209 Object . assign ( jsonSchema , {
209210 description : "YYYY-MM-DDTHH:mm:ss.sssZ" ,
210211 type : "string" ,
@@ -295,13 +296,14 @@ export const onPipeline: Overrider = ({ zodSchema, jsonSchema }, ctx) => {
295296} ;
296297
297298export const onRaw : Overrider = ( { jsonSchema } ) => {
298- if ( ! jsonSchema . _ref ) return ;
299- if ( jsonSchema . _ref . type !== "object" ) return ;
300- const objSchema = jsonSchema . _ref as JSONSchema . ObjectSchema ;
299+ unref ( jsonSchema ) ;
300+ if ( jsonSchema . type !== "object" ) return ;
301+ const objSchema = jsonSchema as JSONSchema . ObjectSchema ;
301302 if ( ! objSchema . properties ) return ;
302303 if ( ! ( "raw" in objSchema . properties ) ) return ;
303- delete jsonSchema . _ref ; // undo
304304 Object . assign ( jsonSchema , objSchema . properties . raw ) ;
305+ delete jsonSchema . properties ; // undo default
306+ delete jsonSchema . required ;
305307} ;
306308
307309const enumerateExamples = ( examples : unknown [ ] ) : ExamplesObject | undefined =>
@@ -476,6 +478,18 @@ const fixReferences = (
476478 return subject as SchemaObject ; // @todo ideally, there should be a method to ensure that
477479} ;
478480
481+ /** @link https://github.com/colinhacks/zod/issues/4275 */
482+ const unref = (
483+ subject : JSONSchema . BaseSchema ,
484+ ) : Omit < JSONSchema . BaseSchema , "_ref" > => {
485+ while ( subject . _ref ) {
486+ const copy = { ...subject . _ref } ;
487+ delete subject . _ref ;
488+ Object . assign ( subject , copy ) ;
489+ }
490+ return subject ;
491+ } ;
492+
479493const depict = (
480494 subject : $ZodType ,
481495 { ctx, rules = overrides } : { ctx : OpenAPIContext ; rules ?: BrandHandling } ,
0 commit comments