File tree 2 files changed +44
-4
lines changed
src/plugins/validation/2and3/semantic-validators
test/plugins/validation/2and3
2 files changed +44
-4
lines changed Original file line number Diff line number Diff line change @@ -73,14 +73,18 @@ module.exports.validate = function({ resolvedSpec }) {
73
73
return param ;
74
74
} ) ;
75
75
76
- each ( path , ( thing , thingName ) => {
77
- if ( thing && thing . parameters ) {
76
+ each ( path , ( operation , operationName ) => {
77
+ if (
78
+ operation &&
79
+ operation . parameters &&
80
+ Array . isArray ( operation . parameters )
81
+ ) {
78
82
availableParameters . push (
79
- ...thing . parameters . map ( ( param , i ) => {
83
+ ...operation . parameters . map ( ( param , i ) => {
80
84
if ( ! isObject ( param ) ) {
81
85
return ;
82
86
}
83
- param . $$path = `paths.${ pathName } .${ thingName } .parameters[${ i } ]` ;
87
+ param . $$path = `paths.${ pathName } .${ operationName } .parameters[${ i } ]` ;
84
88
return param ;
85
89
} )
86
90
) ;
Original file line number Diff line number Diff line change @@ -352,4 +352,40 @@ describe('validation plugin - semantic - paths', function() {
352
352
expect ( res . warnings ) . toEqual ( [ ] ) ;
353
353
} ) ;
354
354
} ) ;
355
+
356
+ it ( 'should not crash when `parameters` is not an array' , function ( ) {
357
+ const spec = {
358
+ paths : {
359
+ '/resource' : {
360
+ get : {
361
+ operationId : 'listResources' ,
362
+ description : 'operation with bad parameters...' ,
363
+ summary : '...but it should not crash the code' ,
364
+ parameters : {
365
+ allOf : [
366
+ {
367
+ name : 'one' ,
368
+ type : 'string'
369
+ } ,
370
+ {
371
+ name : 'two' ,
372
+ type : 'string'
373
+ }
374
+ ]
375
+ } ,
376
+ responses : {
377
+ '200' : {
378
+ description : 'response'
379
+ }
380
+ }
381
+ }
382
+ }
383
+ }
384
+ } ;
385
+
386
+ const res = validate ( { resolvedSpec : spec } ) ;
387
+ // errors/warnings would be caught it parameters-ibm.js
388
+ expect ( res . errors . length ) . toBe ( 0 ) ;
389
+ expect ( res . warnings . length ) . toBe ( 0 ) ;
390
+ } ) ;
355
391
} ) ;
You can’t perform that action at this time.
0 commit comments