Skip to content

Commit 11c8411

Browse files
CLOUDP-304946: IPA rule update must return 200 ok
1 parent 3cd6df5 commit 11c8411

File tree

9 files changed

+418
-73
lines changed

9 files changed

+418
-73
lines changed
Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
import testRule from './__helpers__/testRule';
2+
import { DiagnosticSeverity } from '@stoplight/types';
3+
4+
testRule('xgen-IPA-107-put-method-response-code-is-200', [
5+
{
6+
name: 'valid methods',
7+
document: {
8+
paths: {
9+
'/resource/{id}': {
10+
put: {
11+
responses: {
12+
200: {},
13+
400: {},
14+
500: {},
15+
},
16+
},
17+
},
18+
'/resource/{id}/singleton': {
19+
put: {
20+
responses: {
21+
200: {},
22+
400: {},
23+
500: {},
24+
},
25+
},
26+
},
27+
},
28+
},
29+
errors: [],
30+
},
31+
{
32+
name: 'invalid methods',
33+
document: {
34+
paths: {
35+
'/resourceOne/{id}': {
36+
put: {
37+
responses: {
38+
201: {},
39+
400: {},
40+
500: {},
41+
},
42+
},
43+
},
44+
'/resourceTwo/{id}': {
45+
put: {
46+
responses: {
47+
400: {},
48+
500: {},
49+
},
50+
},
51+
},
52+
'/resourceThree/{id}': {
53+
put: {
54+
responses: {
55+
200: {},
56+
201: {},
57+
400: {},
58+
500: {},
59+
},
60+
},
61+
},
62+
'/resource/{id}/singleton': {
63+
put: {
64+
responses: {
65+
202: {},
66+
400: {},
67+
500: {},
68+
},
69+
},
70+
},
71+
},
72+
},
73+
errors: [
74+
{
75+
code: 'xgen-IPA-107-put-method-response-code-is-200',
76+
message:
77+
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107',
78+
path: ['paths', '/resourceOne/{id}', 'put'],
79+
severity: DiagnosticSeverity.Warning,
80+
},
81+
{
82+
code: 'xgen-IPA-107-put-method-response-code-is-200',
83+
message:
84+
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107',
85+
path: ['paths', '/resourceTwo/{id}', 'put'],
86+
severity: DiagnosticSeverity.Warning,
87+
},
88+
{
89+
code: 'xgen-IPA-107-put-method-response-code-is-200',
90+
message:
91+
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107',
92+
path: ['paths', '/resourceThree/{id}', 'put'],
93+
severity: DiagnosticSeverity.Warning,
94+
},
95+
{
96+
code: 'xgen-IPA-107-put-method-response-code-is-200',
97+
message:
98+
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107',
99+
path: ['paths', '/resource/{id}/singleton', 'put'],
100+
severity: DiagnosticSeverity.Warning,
101+
},
102+
],
103+
},
104+
{
105+
name: 'invalid method with exception',
106+
document: {
107+
paths: {
108+
'/resourceOne/{id}': {
109+
put: {
110+
responses: {
111+
201: {},
112+
400: {},
113+
500: {},
114+
},
115+
'x-xgen-IPA-exception': {
116+
'xgen-IPA-107-put-method-response-code-is-200': 'reason',
117+
},
118+
},
119+
},
120+
'/resourceTwo/{id}': {
121+
put: {
122+
responses: {
123+
400: {},
124+
500: {},
125+
},
126+
'x-xgen-IPA-exception': {
127+
'xgen-IPA-107-put-method-response-code-is-200': 'reason',
128+
},
129+
},
130+
},
131+
'/resource/{id}/singleton': {
132+
put: {
133+
responses: {
134+
202: {},
135+
400: {},
136+
500: {},
137+
},
138+
'x-xgen-IPA-exception': {
139+
'xgen-IPA-107-put-method-response-code-is-200': 'reason',
140+
},
141+
},
142+
},
143+
},
144+
},
145+
errors: [],
146+
},
147+
]);
148+
149+
testRule('xgen-IPA-107-patch-method-response-code-is-200', [
150+
{
151+
name: 'valid methods',
152+
document: {
153+
paths: {
154+
'/resource/{id}': {
155+
patch: {
156+
responses: {
157+
200: {},
158+
400: {},
159+
500: {},
160+
},
161+
},
162+
},
163+
'/resource/{id}/singleton': {
164+
patch: {
165+
responses: {
166+
200: {},
167+
400: {},
168+
500: {},
169+
},
170+
},
171+
},
172+
},
173+
},
174+
errors: [],
175+
},
176+
{
177+
name: 'invalid methods',
178+
document: {
179+
paths: {
180+
'/resourceOne/{id}': {
181+
patch: {
182+
responses: {
183+
201: {},
184+
400: {},
185+
500: {},
186+
},
187+
},
188+
},
189+
'/resourceTwo/{id}': {
190+
patch: {
191+
responses: {
192+
400: {},
193+
500: {},
194+
},
195+
},
196+
},
197+
'/resourceThree/{id}': {
198+
patch: {
199+
responses: {
200+
200: {},
201+
201: {},
202+
400: {},
203+
500: {},
204+
},
205+
},
206+
},
207+
'/resource/{id}/singleton': {
208+
patch: {
209+
responses: {
210+
202: {},
211+
400: {},
212+
500: {},
213+
},
214+
},
215+
},
216+
},
217+
},
218+
errors: [
219+
{
220+
code: 'xgen-IPA-107-patch-method-response-code-is-200',
221+
message:
222+
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107',
223+
path: ['paths', '/resourceOne/{id}', 'patch'],
224+
severity: DiagnosticSeverity.Warning,
225+
},
226+
{
227+
code: 'xgen-IPA-107-patch-method-response-code-is-200',
228+
message:
229+
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107',
230+
path: ['paths', '/resourceTwo/{id}', 'patch'],
231+
severity: DiagnosticSeverity.Warning,
232+
},
233+
{
234+
code: 'xgen-IPA-107-patch-method-response-code-is-200',
235+
message:
236+
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107',
237+
path: ['paths', '/resourceThree/{id}', 'patch'],
238+
severity: DiagnosticSeverity.Warning,
239+
},
240+
{
241+
code: 'xgen-IPA-107-patch-method-response-code-is-200',
242+
message:
243+
'The Update method response status code should be 200 OK. This method either lacks a 200 OK response or defines a different 2xx status code. http://go/ipa-spectral#IPA-107',
244+
path: ['paths', '/resource/{id}/singleton', 'patch'],
245+
severity: DiagnosticSeverity.Warning,
246+
},
247+
],
248+
},
249+
{
250+
name: 'invalid method with exception',
251+
document: {
252+
paths: {
253+
'/resourceOne/{id}': {
254+
patch: {
255+
responses: {
256+
201: {},
257+
400: {},
258+
500: {},
259+
},
260+
'x-xgen-IPA-exception': {
261+
'xgen-IPA-107-patch-method-response-code-is-200': 'reason',
262+
},
263+
},
264+
},
265+
'/resourceTwo/{id}': {
266+
patch: {
267+
responses: {
268+
400: {},
269+
500: {},
270+
},
271+
'x-xgen-IPA-exception': {
272+
'xgen-IPA-107-patch-method-response-code-is-200': 'reason',
273+
},
274+
},
275+
},
276+
'/resource/{id}/singleton': {
277+
patch: {
278+
responses: {
279+
202: {},
280+
400: {},
281+
500: {},
282+
},
283+
'x-xgen-IPA-exception': {
284+
'xgen-IPA-107-patch-method-response-code-is-200': 'reason',
285+
},
286+
},
287+
},
288+
},
289+
},
290+
errors: [],
291+
},
292+
]);

tools/spectral/ipa/rulesets/IPA-107.yaml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
functions:
55
- updateMethodMustNotHaveQueryParams
6+
- updateResponseCodeShouldBe200OK
67

78
rules:
89
xgen-IPA-107-put-must-not-have-query-params:
@@ -24,7 +25,7 @@ rules:
2425
ignoredValues: ['pretty', 'envelope']
2526
xgen-IPA-107-patch-must-not-have-query-params:
2627
description: >-
27-
Update operations must not accept query parameters.
28+
Update operations must not accept query parameters.
2829
2930
##### Implementation details
3031
@@ -39,3 +40,31 @@ rules:
3940
function: 'updateMethodMustNotHaveQueryParams'
4041
functionOptions:
4142
ignoredValues: ['pretty', 'envelope']
43+
xgen-IPA-107-put-method-response-code-is-200:
44+
description: >-
45+
The Update method response status code should be 200 OK.
46+
47+
##### Implementation details
48+
49+
Validation checks the PUT method for single resource paths and singleton resources.
50+
51+
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
52+
message: '{{error}} http://go/ipa-spectral#IPA-107'
53+
severity: warn
54+
given: '$.paths[*].put'
55+
then:
56+
function: 'updateResponseCodeShouldBe200OK'
57+
xgen-IPA-107-patch-method-response-code-is-200:
58+
description: >-
59+
The Update method response status code should be 200 OK.
60+
61+
##### Implementation details
62+
63+
Validation checks the PATCH method for single resource paths and singleton resources.
64+
65+
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
66+
message: '{{error}} http://go/ipa-spectral#IPA-107'
67+
severity: warn
68+
given: '$.paths[*].patch'
69+
then:
70+
function: 'updateResponseCodeShouldBe200OK'

tools/spectral/ipa/rulesets/README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,28 @@ Validation checks the PUT method for single resource paths and singleton resourc
158158
#### xgen-IPA-107-patch-must-not-have-query-params
159159

160160
![warn](https://img.shields.io/badge/warning-yellow)
161-
Update operations must not accept query parameters.
161+
Update operations must not accept query parameters.
162162
##### Implementation details
163163
Validation checks the PATCH method for single resource paths and singleton resources.
164164

165165
- Query parameters `envelope` and `pretty` are exempt from this rule
166166
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
167+
#### xgen-IPA-107-put-method-response-code-is-200
168+
169+
![warn](https://img.shields.io/badge/warning-yellow)
170+
The Update method response status code should be 200 OK.
171+
##### Implementation details
172+
Validation checks the PUT method for single resource paths and singleton resources.
173+
174+
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
175+
#### xgen-IPA-107-patch-method-response-code-is-200
176+
177+
![warn](https://img.shields.io/badge/warning-yellow)
178+
The Update method response status code should be 200 OK.
179+
##### Implementation details
180+
Validation checks the PATCH method for single resource paths and singleton resources.
181+
182+
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
167183

168184

169185
### IPA-108

0 commit comments

Comments
 (0)