@@ -82,6 +82,39 @@ components:
8282 )
8383 expect ( oas . api ?. info . title ) . toBe ( 'Swagger PetStore' )
8484 } )
85+
86+ test ( 'parse a spec with an external file $ref preserves the $ref pointer' , async ( ) => {
87+ const specPath = path . resolve ( __dirname , '../mocks/petStoreExternalFileRef.yaml' )
88+ const oas = await parse ( specPath )
89+
90+ expect ( oas ) . toBeDefined ( )
91+ expect ( oas . api ?. info . title ) . toBe ( 'PetStore with external file ref' )
92+ // The $ref pointer must be preserved (not inlined) so SchemaGenerator can emit a named type reference
93+ const petSchema = ( oas . api as any ) . components ?. schemas ?. Pet
94+ expect ( petSchema ) . toBeDefined ( )
95+ expect ( petSchema . type ) . toBe ( 'object' )
96+ expect ( petSchema . required ) . toEqual ( [ 'id' , 'name' ] )
97+ expect ( petSchema . properties . id ) . toEqual ( { type : 'integer' , format : 'int64' } )
98+ expect ( petSchema . properties . name ) . toEqual ( { type : 'string' } )
99+ expect ( petSchema . properties . category . $ref ) . toBe ( './category.yaml#/components/schemas/Category' )
100+ } )
101+
102+ test ( 'parse a spec with an external URL $ref preserves the $ref pointer' , async ( ) => {
103+ const specPath = path . resolve ( __dirname , '../../plugin-ts/mocks/petStore.yaml' )
104+ const oas = await parse ( specPath )
105+
106+ expect ( oas ) . toBeDefined ( )
107+ expect ( oas . api ?. info . title ) . toBe ( 'Swagger PetStore' )
108+ // The external HTTP $ref must be preserved (not inlined) so SchemaGenerator can emit a named type reference
109+ const petSchema = ( oas . api as any ) . components ?. schemas ?. Pet
110+ expect ( petSchema ) . toBeDefined ( )
111+ expect ( petSchema . type ) . toBe ( 'object' )
112+ expect ( petSchema . required ) . toEqual ( [ 'id' , 'name' ] )
113+ expect ( petSchema . properties . id ) . toEqual ( { type : 'integer' , format : 'int64' } )
114+ expect ( petSchema . properties . name ) . toEqual ( { type : 'string' } )
115+ expect ( petSchema . properties . tag ) . toEqual ( { type : 'string' } )
116+ expect ( petSchema . properties . category . $ref ) . toBe ( 'https://petstore3.swagger.io/api/v3/openapi.json#/components/schemas/Category' )
117+ } )
85118} )
86119
87120describe ( 'parseFromConfig' , ( ) => {
0 commit comments