@@ -237,4 +237,253 @@ describe('resolver', () => {
237237 } )
238238 }
239239 } )
240+
241+ const DOCUMENT_ORIGINAL = {
242+ swagger : '2.0' ,
243+ paths : {
244+ '/pet' : {
245+ post : {
246+ tags : [
247+ 'pet'
248+ ] ,
249+ summary : 'Add a new pet to the store' ,
250+ operationId : 'addPet' ,
251+ parameters : [
252+ {
253+ in : 'body' ,
254+ name : 'body' ,
255+ description : 'Pet object that needs to be added to the store' ,
256+ required : true ,
257+ schema : {
258+ $ref : '#/definitions/Pet'
259+ }
260+ }
261+ ] ,
262+ responses : {
263+ 405 : {
264+ description : 'Invalid input'
265+ }
266+ }
267+ }
268+ }
269+ } ,
270+ definitions : {
271+ Category : {
272+ type : 'object' ,
273+ properties : {
274+ id : {
275+ type : 'integer' ,
276+ format : 'int64'
277+ } ,
278+ name : {
279+ type : 'string'
280+ }
281+ }
282+ } ,
283+ Pet : {
284+ type : 'object' ,
285+ required : [
286+ 'category'
287+ ] ,
288+ properties : {
289+ category : {
290+ $ref : '#/definitions/Category'
291+ }
292+ }
293+ }
294+ }
295+ }
296+
297+ describe ( 'Swagger usage' , function ( ) {
298+ it . skip ( 'should be able to resolve a Swagger document with $refs' , ( ) => {
299+ // When
300+ return Swagger . resolve ( { spec : DOCUMENT_ORIGINAL , allowMetaPatches : false } )
301+ . then ( handleResponse )
302+
303+ // Then
304+ function handleResponse ( obj ) {
305+ expect ( obj . errors ) . toEqual ( [ ] )
306+ expect ( obj . spec ) . toEqual ( {
307+ swagger : '2.0' ,
308+ paths : {
309+ '/pet' : {
310+ post : {
311+ tags : [
312+ 'pet'
313+ ] ,
314+ summary : 'Add a new pet to the store' ,
315+ operationId : 'addPet' ,
316+ __originalOperationId : 'addPet' ,
317+ parameters : [
318+ {
319+ in : 'body' ,
320+ name : 'body' ,
321+ description : 'Pet object that needs to be added to the store' ,
322+ required : true ,
323+ schema : {
324+ type : 'object' ,
325+ required : [
326+ 'category'
327+ ] ,
328+ properties : {
329+ category : {
330+ type : 'object' ,
331+ properties : {
332+ id : {
333+ type : 'integer' ,
334+ format : 'int64'
335+ } ,
336+ name : {
337+ type : 'string'
338+ }
339+ }
340+ }
341+ }
342+ }
343+ }
344+ ] ,
345+ responses : {
346+ 405 : {
347+ description : 'Invalid input'
348+ }
349+ }
350+ }
351+ }
352+ } ,
353+ definitions : {
354+ Category : {
355+ type : 'object' ,
356+ properties : {
357+ id : {
358+ type : 'integer' ,
359+ format : 'int64'
360+ } ,
361+ name : {
362+ type : 'string'
363+ }
364+ }
365+ } ,
366+ Pet : {
367+ type : 'object' ,
368+ required : [
369+ 'category'
370+ ] ,
371+ properties : {
372+ category : {
373+ type : 'object' ,
374+ properties : {
375+ id : {
376+ type : 'integer' ,
377+ format : 'int64'
378+ } ,
379+ name : {
380+ type : 'string'
381+ }
382+ }
383+ }
384+ }
385+ }
386+ }
387+ } )
388+ }
389+ } )
390+
391+ it ( 'should be able to resolve a Swagger document with $refs when allowMetaPatches is enabled' , ( ) => {
392+ // When
393+ return Swagger . resolve ( { spec : DOCUMENT_ORIGINAL , allowMetaPatches : true } )
394+ . then ( handleResponse )
395+
396+ // Then
397+ function handleResponse ( obj ) {
398+ expect ( obj . errors ) . toEqual ( [ ] )
399+ expect ( obj . spec ) . toEqual ( {
400+ swagger : '2.0' ,
401+ paths : {
402+ '/pet' : {
403+ post : {
404+ tags : [
405+ 'pet'
406+ ] ,
407+ summary : 'Add a new pet to the store' ,
408+ operationId : 'addPet' ,
409+ __originalOperationId : 'addPet' ,
410+ parameters : [
411+ {
412+ in : 'body' ,
413+ name : 'body' ,
414+ description : 'Pet object that needs to be added to the store' ,
415+ required : true ,
416+ schema : {
417+ $$ref : '#/definitions/Pet' ,
418+ type : 'object' ,
419+ required : [
420+ 'category'
421+ ] ,
422+ properties : {
423+ category : {
424+ $$ref : '#/definitions/Category' ,
425+ type : 'object' ,
426+ properties : {
427+ id : {
428+ type : 'integer' ,
429+ format : 'int64'
430+ } ,
431+ name : {
432+ type : 'string'
433+ }
434+ }
435+ }
436+ }
437+ }
438+ }
439+ ] ,
440+ responses : {
441+ 405 : {
442+ description : 'Invalid input'
443+ }
444+ }
445+ }
446+ }
447+ } ,
448+ definitions : {
449+ Category : {
450+ $$ref : '#/definitions/Category' , // FIXME: benign, but this should not be present
451+ type : 'object' ,
452+ properties : {
453+ id : {
454+ type : 'integer' ,
455+ format : 'int64'
456+ } ,
457+ name : {
458+ type : 'string'
459+ }
460+ }
461+ } ,
462+ Pet : {
463+ $$ref : '#/definitions/Pet' ,
464+ type : 'object' ,
465+ required : [
466+ 'category'
467+ ] ,
468+ properties : {
469+ category : {
470+ $$ref : '#/definitions/Category' , // FIXME: benign, but this should not be present
471+ type : 'object' ,
472+ properties : {
473+ id : {
474+ type : 'integer' ,
475+ format : 'int64'
476+ } ,
477+ name : {
478+ type : 'string'
479+ }
480+ }
481+ }
482+ }
483+ }
484+ }
485+ } )
486+ }
487+ } )
488+ } )
240489} )
0 commit comments