@@ -843,4 +843,69 @@ describe('sibling $ref resolution by spec', () => {
843843 expect ( problems ) . toHaveLength ( 0 ) ;
844844 expect ( res . parsed ) . toMatchSnapshot ( ) ;
845845 } ) ;
846+
847+ it ( 'should bundle nested external refs inside Schema $ref sibling properties' , async ( ) => {
848+ const { bundle : res , problems } = await bundle ( {
849+ config : await createConfig ( { } ) ,
850+ ref : path . join (
851+ __dirname ,
852+ 'fixtures/sibling-refs/openapi-schema-ref-sibling-nested-external.yaml'
853+ ) ,
854+ } ) ;
855+
856+ const parsed = res . parsed as any ;
857+ const nestedSiblingRef =
858+ parsed . paths [ '/sample' ] . get . responses [ '200' ] . content [ 'application/json' ] . schema . properties
859+ . second . $ref ;
860+
861+ expect ( problems ) . toHaveLength ( 0 ) ;
862+ expect ( nestedSiblingRef ) . toBe ( '#/components/schemas/Second' ) ;
863+ expect ( parsed . components . schemas . Second ) . toMatchObject ( {
864+ title : 'Referenced model' ,
865+ type : 'string' ,
866+ } ) ;
867+ } ) ;
868+
869+ it ( 'should keep sibling fields defined next to a schema $ref wrapper' , async ( ) => {
870+ const {
871+ bundle : { parsed } ,
872+ problems,
873+ } = await bundleFromString ( {
874+ source : outdent `
875+ openapi: 3.1.0
876+ info:
877+ title: Sibling fields on schema $ref wrapper
878+ version: 1.0.0
879+ paths:
880+ /sample:
881+ get:
882+ responses:
883+ '200':
884+ description: OK
885+ content:
886+ application/json:
887+ schema:
888+ $ref: '#/components/schemas/IdReadOnly'
889+ components:
890+ schemas:
891+ Id:
892+ type: integer
893+ description: A generic id
894+ IdReadOnly:
895+ $ref: '#/components/schemas/Id'
896+ readOnly: true
897+ description: A generic id that is specifically read only
898+ ` ,
899+ config : await createConfig ( { } ) ,
900+ } ) ;
901+
902+ const wrappedSchema = ( parsed as any ) . components . schemas . IdReadOnly ;
903+
904+ expect ( problems ) . toHaveLength ( 0 ) ;
905+ expect ( wrappedSchema ) . toMatchObject ( {
906+ $ref : '#/components/schemas/Id' ,
907+ readOnly : true ,
908+ description : 'A generic id that is specifically read only' ,
909+ } ) ;
910+ } ) ;
846911} ) ;
0 commit comments