File tree Expand file tree Collapse file tree
packages/zod-openapi/src/lib Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -851,9 +851,11 @@ describe('zodOpenapi', () => {
851851 const [ schemas , vocabulary ] = generateVocabulary ( [ schema ] ) ;
852852
853853 expect ( schemas )
854- . toEqual ( [ { "type" : "string" } ] ) ;
854+ . toEqual ( { "coolstring" : { "type" : "string" } } ) ;
855+
855856 expect ( generateSchema ( schema , { vocabulary } ) )
856857 . toEqual ( { "$ref" : "#/components/schemas/coolstring" } ) ;
858+
857859 expect ( generateSchema ( z . object ( { string : schema } ) , { vocabulary } ) )
858860 . toEqual ( {
859861 "properties" : {
Original file line number Diff line number Diff line change @@ -577,20 +577,20 @@ export function generateSchema(
577577
578578export const fragmentName = Symbol ( 'fragmentName' ) ;
579579
580- export function generateVocabulary ( objects : OpenApiZodAny [ ] ) : [ SchemaObject [ ] , Set < string > ] {
580+ export function generateVocabulary ( objects : OpenApiZodAny [ ] ) : [ { [ key : string ] : SchemaObject } , Set < string > ] {
581581 const fragments = objects . filter ( object => getNameFromSchemas ( getSchemasForZodObject ( object ) ) ) ;
582582 const fragmentNames = new Set ( fragments . map (
583583 object => getNameFromSchemas ( getSchemasForZodObject ( object ) ) as string
584584 ) ) ;
585- const fragmentSchemas = fragments . map ( fragment => {
585+ const fragmentSchemas = Object . fromEntries ( fragments . map ( fragment => {
586586 const name = getNameFromSchemas ( getSchemasForZodObject ( fragment ) ) as string ;
587587 fragmentNames . delete ( name ) ;
588588 // assumption: schemas cannot have 2 different names
589589 const schema = generateSchema ( fragment , { vocabulary : fragmentNames } ) as SchemaObject ;
590590 fragmentNames . add ( name ) ;
591591
592- return schema ;
593- } ) ;
592+ return [ name , schema ] ;
593+ } ) ) ;
594594
595595 return [ fragmentSchemas , fragmentNames ] ;
596596}
You can’t perform that action at this time.
0 commit comments