@@ -293,6 +293,40 @@ describe('validation plugin - semantic - operations-shared', function() {
293
293
expect ( res . warnings . length ) . toEqual ( 0 ) ;
294
294
} ) ;
295
295
296
+ it ( 'should complain about an anonymous array response model with no type but an `items` field' , function ( ) {
297
+ const spec = {
298
+ paths : {
299
+ '/stuff' : {
300
+ get : {
301
+ summary : 'list stuff' ,
302
+ operationId : 'list_stuff' ,
303
+ produces : [ 'application/json' ] ,
304
+ responses : {
305
+ 200 : {
306
+ description : 'successful operation' ,
307
+ schema : {
308
+ items : {
309
+ type : 'string'
310
+ }
311
+ }
312
+ }
313
+ }
314
+ }
315
+ }
316
+ }
317
+ } ;
318
+
319
+ const res = validate ( { resolvedSpec : spec } , config ) ;
320
+ expect ( res . errors . length ) . toEqual ( 1 ) ;
321
+ expect ( res . errors [ 0 ] . path ) . toEqual (
322
+ 'paths./stuff.get.responses.200.schema'
323
+ ) ;
324
+ expect ( res . errors [ 0 ] . message ) . toEqual (
325
+ 'Arrays MUST NOT be returned as the top-level structure in a response body.'
326
+ ) ;
327
+ expect ( res . warnings . length ) . toEqual ( 0 ) ;
328
+ } ) ;
329
+
296
330
it ( 'should not complain about an empty summary within a vendor extension' , function ( ) {
297
331
const spec = {
298
332
paths : {
@@ -726,6 +760,57 @@ describe('validation plugin - semantic - operations-shared', function() {
726
760
expect ( res . warnings . length ) . toEqual ( 0 ) ;
727
761
} ) ;
728
762
763
+ it ( 'should complain about a top-level array response without a type but with an `items` field' , function ( ) {
764
+ const spec = {
765
+ paths : {
766
+ '/' : {
767
+ put : {
768
+ operationId : 'get_everything' ,
769
+ summary : 'get everything as a string or an array' ,
770
+ requestBody : {
771
+ description : 'simple body' ,
772
+ content : {
773
+ 'application/json' : {
774
+ schema : {
775
+ type : 'string'
776
+ }
777
+ }
778
+ }
779
+ } ,
780
+ responses : {
781
+ '200' : {
782
+ content : {
783
+ 'text/plain' : {
784
+ schema : {
785
+ type : 'string'
786
+ }
787
+ } ,
788
+ 'application/json' : {
789
+ schema : {
790
+ items : {
791
+ type : 'string'
792
+ }
793
+ }
794
+ }
795
+ }
796
+ }
797
+ }
798
+ }
799
+ }
800
+ }
801
+ } ;
802
+
803
+ const res = validate ( { resolvedSpec : spec , isOAS3 : true } , config ) ;
804
+ expect ( res . errors . length ) . toEqual ( 1 ) ;
805
+ expect ( res . errors [ 0 ] . path ) . toEqual (
806
+ 'paths./.put.responses.200.content.application/json.schema'
807
+ ) ;
808
+ expect ( res . errors [ 0 ] . message ) . toEqual (
809
+ 'Arrays MUST NOT be returned as the top-level structure in a response body.'
810
+ ) ;
811
+ expect ( res . warnings . length ) . toEqual ( 0 ) ;
812
+ } ) ;
813
+
729
814
it ( 'should complain about an unused tag' , function ( ) {
730
815
const spec = {
731
816
tags : [
0 commit comments