@@ -64,7 +64,11 @@ describe('bundle', () => {
6464 config : await createConfig ( { } ) ,
6565 ref : path . join ( __dirname , 'fixtures/refs/openapi-with-external-refs.yaml' ) ,
6666 } ) ;
67- expect ( problems ) . toHaveLength ( 0 ) ;
67+ expect ( problems ) . toHaveLength ( 1 ) ;
68+ expect ( problems [ 0 ] . severity ) . toBe ( 'warn' ) ;
69+ expect ( problems [ 0 ] . message ) . toEqual (
70+ `Two schemas are referenced with the same name but different content. Renamed first to first-2.`
71+ ) ;
6872 expect ( res . parsed ) . toMatchSnapshot ( ) ;
6973 } ) ;
7074
@@ -119,6 +123,67 @@ describe('bundle', () => {
119123 ) ;
120124 } ) ;
121125
126+ it ( 'should bundle external pointer refs and warn for conflicting names' , async ( ) => {
127+ const { bundle : res , problems } = await bundle ( {
128+ config : await createConfig ( { } ) ,
129+ ref : path . join (
130+ __dirname ,
131+ 'fixtures/refs/openapi-with-external-refs-pointer-conflicting-names.yaml'
132+ ) ,
133+ } ) ;
134+ expect ( problems ) . toHaveLength ( 1 ) ;
135+ expect ( problems [ 0 ] . severity ) . toBe ( 'warn' ) ;
136+ expect ( problems [ 0 ] . message ) . toEqual (
137+ `Two schemas are referenced with the same name but different content. Renamed User to User-2.`
138+ ) ;
139+ expect ( res . parsed ) . toMatchSnapshot ( ) ;
140+ } ) ;
141+
142+ it ( 'should bundle external pointer refs and do not show warnings for conflicting names' , async ( ) => {
143+ const { problems } = await bundle ( {
144+ config : await createConfig ( { } ) ,
145+ ref : path . join (
146+ __dirname ,
147+ 'fixtures/refs/openapi-with-external-refs-pointer-conflicting-names.yaml'
148+ ) ,
149+ componentRenamingConflicts : 'off' ,
150+ } ) ;
151+ expect ( problems ) . toHaveLength ( 0 ) ;
152+ } ) ;
153+
154+ it ( 'should report error-severity problems for conflicting pointer ref names' , async ( ) => {
155+ const { problems } = await bundle ( {
156+ config : await createConfig ( { } ) ,
157+ ref : path . join (
158+ __dirname ,
159+ 'fixtures/refs/openapi-with-external-refs-pointer-conflicting-names.yaml'
160+ ) ,
161+ componentRenamingConflicts : 'error' ,
162+ } ) ;
163+ expect ( problems ) . toHaveLength ( 1 ) ;
164+ expect ( problems [ 0 ] . severity ) . toBe ( 'error' ) ;
165+ expect ( problems [ 0 ] . message ) . toEqual (
166+ `Two schemas are referenced with the same name but different content. Renamed User to User-2.`
167+ ) ;
168+ } ) ;
169+
170+ it ( 'should keep dotted JSON pointer schema keys and rename conflicting User schemas' , async ( ) => {
171+ const { bundle : res , problems } = await bundle ( {
172+ config : await createConfig ( { } ) ,
173+ ref : path . join (
174+ __dirname ,
175+ 'fixtures/refs/openapi-bundle-external-schema-names-and-user-conflict.yaml'
176+ ) ,
177+ } ) ;
178+
179+ expect ( problems ) . toHaveLength ( 0 ) ;
180+ const schemas = ( res . parsed as { components : { schemas : Record < string , unknown > } } ) . components
181+ . schemas ;
182+ expect ( schemas [ 'my.org.User' ] ) . toBeDefined ( ) ;
183+ expect ( schemas [ 'my.User' ] ) . toBeDefined ( ) ;
184+ expect ( res . parsed ) . toMatchSnapshot ( ) ;
185+ } ) ;
186+
122187 it ( 'should dereferenced correctly when used with dereference' , async ( ) => {
123188 const { bundle : res , problems } = await bundleDocument ( {
124189 externalRefResolver : new BaseResolver ( ) ,
0 commit comments