@@ -20,7 +20,7 @@ describe('validation plugin - semantic - operations - oas3', function() {
20
20
}
21
21
} ;
22
22
23
- const res = validate ( { resolvedSpec : spec } , config ) ;
23
+ const res = validate ( { resolvedSpec : spec , jsSpec : spec } , config ) ;
24
24
expect ( res . errors . length ) . toEqual ( 1 ) ;
25
25
expect ( res . errors [ 0 ] . path ) . toEqual ( 'paths./pets.post.requestBody' ) ;
26
26
expect ( res . errors [ 0 ] . message ) . toEqual (
@@ -29,7 +29,7 @@ describe('validation plugin - semantic - operations - oas3', function() {
29
29
expect ( res . warnings . length ) . toEqual ( 0 ) ;
30
30
} ) ;
31
31
32
- it ( 'should warn about an operation with a non-form request body that does not set a name' , function ( ) {
32
+ it ( 'should warn about an operation with a non-form, array schema request body that does not set a name' , function ( ) {
33
33
const spec = {
34
34
paths : {
35
35
'/pets' : {
@@ -41,7 +41,10 @@ describe('validation plugin - semantic - operations - oas3', function() {
41
41
content : {
42
42
'application/json' : {
43
43
schema : {
44
- type : 'string'
44
+ type : 'array' ,
45
+ items : {
46
+ type : 'string'
47
+ }
45
48
}
46
49
}
47
50
}
@@ -51,7 +54,7 @@ describe('validation plugin - semantic - operations - oas3', function() {
51
54
}
52
55
} ;
53
56
54
- const res = validate ( { resolvedSpec : spec } , config ) ;
57
+ const res = validate ( { resolvedSpec : spec , jsSpec : spec } , config ) ;
55
58
expect ( res . warnings . length ) . toEqual ( 1 ) ;
56
59
expect ( res . warnings [ 0 ] . path ) . toEqual ( 'paths./pets.post' ) ;
57
60
expect ( res . warnings [ 0 ] . message ) . toEqual (
@@ -60,6 +63,33 @@ describe('validation plugin - semantic - operations - oas3', function() {
60
63
expect ( res . errors . length ) . toEqual ( 0 ) ;
61
64
} ) ;
62
65
66
+ it ( 'should not warn about an operation with a non-array json request body that does not set a name' , function ( ) {
67
+ const spec = {
68
+ paths : {
69
+ '/pets' : {
70
+ post : {
71
+ summary : 'this is a summary' ,
72
+ operationId : 'operationId' ,
73
+ requestBody : {
74
+ description : 'body for request' ,
75
+ content : {
76
+ 'application/json' : {
77
+ schema : {
78
+ type : 'string'
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ } ;
87
+
88
+ const res = validate ( { resolvedSpec : spec , jsSpec : spec } , config ) ;
89
+ expect ( res . warnings . length ) . toEqual ( 0 ) ;
90
+ expect ( res . errors . length ) . toEqual ( 0 ) ;
91
+ } ) ;
92
+
63
93
it ( 'should not warn about an operation with a non-form request body that sets a name' , function ( ) {
64
94
const spec = {
65
95
paths : {
@@ -83,12 +113,11 @@ describe('validation plugin - semantic - operations - oas3', function() {
83
113
}
84
114
} ;
85
115
86
- const res = validate ( { resolvedSpec : spec } , config ) ;
116
+ const res = validate ( { resolvedSpec : spec , jsSpec : spec } , config ) ;
87
117
expect ( res . warnings . length ) . toEqual ( 0 ) ;
88
118
expect ( res . errors . length ) . toEqual ( 0 ) ;
89
119
} ) ;
90
120
91
- // should not warn about a form request body
92
121
it ( 'should not warn about an operation with a form request body that does not set a name' , function ( ) {
93
122
const spec = {
94
123
paths : {
@@ -116,7 +145,47 @@ describe('validation plugin - semantic - operations - oas3', function() {
116
145
}
117
146
} ;
118
147
119
- const res = validate ( { resolvedSpec : spec } , config ) ;
148
+ const res = validate ( { resolvedSpec : spec , jsSpec : spec } , config ) ;
149
+ expect ( res . warnings . length ) . toEqual ( 0 ) ;
150
+ expect ( res . errors . length ) . toEqual ( 0 ) ;
151
+ } ) ;
152
+
153
+ it ( 'should not warn about an operation with a referenced request body that does not set a name' , function ( ) {
154
+ const resolvedSpec = {
155
+ paths : {
156
+ '/pets' : {
157
+ post : {
158
+ summary : 'this is a summary' ,
159
+ operationId : 'operationId' ,
160
+ requestBody : {
161
+ content : {
162
+ 'application/json' : {
163
+ schema : {
164
+ type : 'string'
165
+ }
166
+ }
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+ } ;
173
+
174
+ const jsSpec = {
175
+ paths : {
176
+ '/pets' : {
177
+ post : {
178
+ summary : 'this is a summary' ,
179
+ operationId : 'operationId' ,
180
+ requestBody : {
181
+ $ref : '#/components/requestBodies/SomeBody'
182
+ }
183
+ }
184
+ }
185
+ }
186
+ } ;
187
+
188
+ const res = validate ( { resolvedSpec, jsSpec } , config ) ;
120
189
expect ( res . warnings . length ) . toEqual ( 0 ) ;
121
190
expect ( res . errors . length ) . toEqual ( 0 ) ;
122
191
} ) ;
0 commit comments