Skip to content

Commit b402dad

Browse files
CLOUDP-307110: Combine separated put and patch IPA rules (#568)
1 parent 170820f commit b402dad

File tree

4 files changed

+44
-88
lines changed

4 files changed

+44
-88
lines changed

tools/spectral/ipa/__tests__/IPA107UpdateMethodMustNotHaveQueryParams.test.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ const componentSchemas = {
4040
},
4141
};
4242

43-
testRule('xgen-IPA-107-put-must-not-have-query-params', [
43+
// Put
44+
testRule('xgen-IPA-107-update-must-not-have-query-params', [
4445
{
4546
name: 'valid put',
4647
document: {
@@ -119,19 +120,19 @@ testRule('xgen-IPA-107-put-must-not-have-query-params', [
119120
},
120121
errors: [
121122
{
122-
code: 'xgen-IPA-107-put-must-not-have-query-params',
123+
code: 'xgen-IPA-107-update-must-not-have-query-params',
123124
message: 'Update operations must not have query parameters. Found [filter].',
124125
path: ['paths', '/resource/{id}', 'put'],
125126
severity: DiagnosticSeverity.Warning,
126127
},
127128
{
128-
code: 'xgen-IPA-107-put-must-not-have-query-params',
129+
code: 'xgen-IPA-107-update-must-not-have-query-params',
129130
message: 'Update operations must not have query parameters. Found [query-param].',
130131
path: ['paths', '/resource/{id}/singleton', 'put'],
131132
severity: DiagnosticSeverity.Warning,
132133
},
133134
{
134-
code: 'xgen-IPA-107-put-must-not-have-query-params',
135+
code: 'xgen-IPA-107-update-must-not-have-query-params',
135136
message: 'Update operations must not have query parameters. Found [query-param-2].',
136137
path: ['paths', '/resource/{id}/singleton', 'put'],
137138
severity: DiagnosticSeverity.Warning,
@@ -153,7 +154,7 @@ testRule('xgen-IPA-107-put-must-not-have-query-params', [
153154
},
154155
],
155156
'x-xgen-IPA-exception': {
156-
'xgen-IPA-107-put-must-not-have-query-params': 'Reason',
157+
'xgen-IPA-107-update-must-not-have-query-params': 'Reason',
157158
},
158159
},
159160
},
@@ -165,7 +166,7 @@ testRule('xgen-IPA-107-put-must-not-have-query-params', [
165166
},
166167
],
167168
'x-xgen-IPA-exception': {
168-
'xgen-IPA-107-put-must-not-have-query-params': 'Reason',
169+
'xgen-IPA-107-update-must-not-have-query-params': 'Reason',
169170
},
170171
},
171172
},
@@ -175,7 +176,8 @@ testRule('xgen-IPA-107-put-must-not-have-query-params', [
175176
},
176177
]);
177178

178-
testRule('xgen-IPA-107-patch-must-not-have-query-params', [
179+
// Patch
180+
testRule('xgen-IPA-107-update-must-not-have-query-params', [
179181
{
180182
name: 'valid patch',
181183
document: {
@@ -254,19 +256,19 @@ testRule('xgen-IPA-107-patch-must-not-have-query-params', [
254256
},
255257
errors: [
256258
{
257-
code: 'xgen-IPA-107-patch-must-not-have-query-params',
259+
code: 'xgen-IPA-107-update-must-not-have-query-params',
258260
message: 'Update operations must not have query parameters. Found [filter].',
259261
path: ['paths', '/resource/{id}', 'patch'],
260262
severity: DiagnosticSeverity.Warning,
261263
},
262264
{
263-
code: 'xgen-IPA-107-patch-must-not-have-query-params',
265+
code: 'xgen-IPA-107-update-must-not-have-query-params',
264266
message: 'Update operations must not have query parameters. Found [query-param].',
265267
path: ['paths', '/resource/{id}/singleton', 'patch'],
266268
severity: DiagnosticSeverity.Warning,
267269
},
268270
{
269-
code: 'xgen-IPA-107-patch-must-not-have-query-params',
271+
code: 'xgen-IPA-107-update-must-not-have-query-params',
270272
message: 'Update operations must not have query parameters. Found [query-param-2].',
271273
path: ['paths', '/resource/{id}/singleton', 'patch'],
272274
severity: DiagnosticSeverity.Warning,
@@ -288,7 +290,7 @@ testRule('xgen-IPA-107-patch-must-not-have-query-params', [
288290
},
289291
],
290292
'x-xgen-IPA-exception': {
291-
'xgen-IPA-107-patch-must-not-have-query-params': 'Reason',
293+
'xgen-IPA-107-update-must-not-have-query-params': 'Reason',
292294
},
293295
},
294296
},
@@ -300,7 +302,7 @@ testRule('xgen-IPA-107-patch-must-not-have-query-params', [
300302
},
301303
],
302304
'x-xgen-IPA-exception': {
303-
'xgen-IPA-107-patch-must-not-have-query-params': 'Reason',
305+
'xgen-IPA-107-update-must-not-have-query-params': 'Reason',
304306
},
305307
},
306308
},

tools/spectral/ipa/__tests__/IPA107UpdateResponseCodeShouldBe200OK.test.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import testRule from './__helpers__/testRule';
22
import { DiagnosticSeverity } from '@stoplight/types';
33

4-
testRule('xgen-IPA-107-put-method-response-code-is-200', [
4+
// Put
5+
testRule('xgen-IPA-107-update-method-response-code-is-200', [
56
{
67
name: 'valid methods',
78
document: {
@@ -72,28 +73,28 @@ testRule('xgen-IPA-107-put-method-response-code-is-200', [
7273
},
7374
errors: [
7475
{
75-
code: 'xgen-IPA-107-put-method-response-code-is-200',
76+
code: 'xgen-IPA-107-update-method-response-code-is-200',
7677
message:
7778
'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.',
7879
path: ['paths', '/resourceOne/{id}', 'put'],
7980
severity: DiagnosticSeverity.Warning,
8081
},
8182
{
82-
code: 'xgen-IPA-107-put-method-response-code-is-200',
83+
code: 'xgen-IPA-107-update-method-response-code-is-200',
8384
message:
8485
'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.',
8586
path: ['paths', '/resourceTwo/{id}', 'put'],
8687
severity: DiagnosticSeverity.Warning,
8788
},
8889
{
89-
code: 'xgen-IPA-107-put-method-response-code-is-200',
90+
code: 'xgen-IPA-107-update-method-response-code-is-200',
9091
message:
9192
'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.',
9293
path: ['paths', '/resourceThree/{id}', 'put'],
9394
severity: DiagnosticSeverity.Warning,
9495
},
9596
{
96-
code: 'xgen-IPA-107-put-method-response-code-is-200',
97+
code: 'xgen-IPA-107-update-method-response-code-is-200',
9798
message:
9899
'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.',
99100
path: ['paths', '/resource/{id}/singleton', 'put'],
@@ -113,7 +114,7 @@ testRule('xgen-IPA-107-put-method-response-code-is-200', [
113114
500: {},
114115
},
115116
'x-xgen-IPA-exception': {
116-
'xgen-IPA-107-put-method-response-code-is-200': 'reason',
117+
'xgen-IPA-107-update-method-response-code-is-200': 'reason',
117118
},
118119
},
119120
},
@@ -124,7 +125,7 @@ testRule('xgen-IPA-107-put-method-response-code-is-200', [
124125
500: {},
125126
},
126127
'x-xgen-IPA-exception': {
127-
'xgen-IPA-107-put-method-response-code-is-200': 'reason',
128+
'xgen-IPA-107-update-method-response-code-is-200': 'reason',
128129
},
129130
},
130131
},
@@ -136,7 +137,7 @@ testRule('xgen-IPA-107-put-method-response-code-is-200', [
136137
500: {},
137138
},
138139
'x-xgen-IPA-exception': {
139-
'xgen-IPA-107-put-method-response-code-is-200': 'reason',
140+
'xgen-IPA-107-update-method-response-code-is-200': 'reason',
140141
},
141142
},
142143
},
@@ -146,7 +147,8 @@ testRule('xgen-IPA-107-put-method-response-code-is-200', [
146147
},
147148
]);
148149

149-
testRule('xgen-IPA-107-patch-method-response-code-is-200', [
150+
// Patch
151+
testRule('xgen-IPA-107-update-method-response-code-is-200', [
150152
{
151153
name: 'valid methods',
152154
document: {
@@ -217,28 +219,28 @@ testRule('xgen-IPA-107-patch-method-response-code-is-200', [
217219
},
218220
errors: [
219221
{
220-
code: 'xgen-IPA-107-patch-method-response-code-is-200',
222+
code: 'xgen-IPA-107-update-method-response-code-is-200',
221223
message:
222224
'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.',
223225
path: ['paths', '/resourceOne/{id}', 'patch'],
224226
severity: DiagnosticSeverity.Warning,
225227
},
226228
{
227-
code: 'xgen-IPA-107-patch-method-response-code-is-200',
229+
code: 'xgen-IPA-107-update-method-response-code-is-200',
228230
message:
229231
'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.',
230232
path: ['paths', '/resourceTwo/{id}', 'patch'],
231233
severity: DiagnosticSeverity.Warning,
232234
},
233235
{
234-
code: 'xgen-IPA-107-patch-method-response-code-is-200',
236+
code: 'xgen-IPA-107-update-method-response-code-is-200',
235237
message:
236238
'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.',
237239
path: ['paths', '/resourceThree/{id}', 'patch'],
238240
severity: DiagnosticSeverity.Warning,
239241
},
240242
{
241-
code: 'xgen-IPA-107-patch-method-response-code-is-200',
243+
code: 'xgen-IPA-107-update-method-response-code-is-200',
242244
message:
243245
'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.',
244246
path: ['paths', '/resource/{id}/singleton', 'patch'],
@@ -258,7 +260,7 @@ testRule('xgen-IPA-107-patch-method-response-code-is-200', [
258260
500: {},
259261
},
260262
'x-xgen-IPA-exception': {
261-
'xgen-IPA-107-patch-method-response-code-is-200': 'reason',
263+
'xgen-IPA-107-update-method-response-code-is-200': 'reason',
262264
},
263265
},
264266
},
@@ -269,7 +271,7 @@ testRule('xgen-IPA-107-patch-method-response-code-is-200', [
269271
500: {},
270272
},
271273
'x-xgen-IPA-exception': {
272-
'xgen-IPA-107-patch-method-response-code-is-200': 'reason',
274+
'xgen-IPA-107-update-method-response-code-is-200': 'reason',
273275
},
274276
},
275277
},
@@ -281,7 +283,7 @@ testRule('xgen-IPA-107-patch-method-response-code-is-200', [
281283
500: {},
282284
},
283285
'x-xgen-IPA-exception': {
284-
'xgen-IPA-107-patch-method-response-code-is-200': 'reason',
286+
'xgen-IPA-107-update-method-response-code-is-200': 'reason',
285287
},
286288
},
287289
},

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

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,66 +9,35 @@ functions:
99
- IPA107UpdateMethodRequestBodyIsGetResponse
1010

1111
rules:
12-
xgen-IPA-107-put-must-not-have-query-params:
12+
xgen-IPA-107-update-must-not-have-query-params:
1313
description: >-
1414
Update operations must not accept query parameters.
1515
1616
##### Implementation details
1717
18-
Validation checks the PUT method for single resource paths and singleton resources.
18+
Validation checks the PATCH/PUT methods for single resource paths and singleton resources.
1919
2020
- Query parameters `envelope` and `pretty` are exempt from this rule
2121
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
22-
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-put-must-not-have-query-params'
22+
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-update-must-not-have-query-params'
2323
severity: warn
24-
given: '$.paths[*].put'
24+
given: '$.paths[*][put,patch]'
2525
then:
2626
function: 'IPA107UpdateMethodMustNotHaveQueryParams'
2727
functionOptions:
2828
ignoredValues: ['pretty', 'envelope']
29-
xgen-IPA-107-patch-must-not-have-query-params:
30-
description: >-
31-
Update operations must not accept query parameters.
32-
33-
##### Implementation details
34-
35-
Validation checks the PATCH method for single resource paths and singleton resources.
36-
37-
- Query parameters `envelope` and `pretty` are exempt from this rule
38-
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
39-
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-patch-must-not-have-query-params'
40-
severity: warn
41-
given: '$.paths[*].patch'
42-
then:
43-
function: 'IPA107UpdateMethodMustNotHaveQueryParams'
44-
functionOptions:
45-
ignoredValues: ['pretty', 'envelope']
46-
xgen-IPA-107-put-method-response-code-is-200:
47-
description: >-
48-
The Update method response status code should be 200 OK.
49-
50-
##### Implementation details
51-
52-
Validation checks the PUT method for single resource paths and [singleton resources](https://go/ipa/113).
53-
54-
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
55-
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-put-method-response-code-is-200'
56-
severity: warn
57-
given: '$.paths[*].put'
58-
then:
59-
function: 'IPA107UpdateResponseCodeShouldBe200OK'
60-
xgen-IPA-107-patch-method-response-code-is-200:
29+
xgen-IPA-107-update-method-response-code-is-200:
6130
description: >-
6231
The Update method response status code should be 200 OK.
6332
6433
##### Implementation details
6534
66-
Validation checks the PATCH method for single resource paths and [singleton resources](https://go/ipa/113).
35+
Validation checks the PATCH/PUT methods for single resource paths and [singleton resources](https://go/ipa/113).
6736
6837
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
69-
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-patch-method-response-code-is-200'
38+
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-107-update-method-response-code-is-200'
7039
severity: warn
71-
given: '$.paths[*].patch'
40+
given: '$.paths[*][put,patch]'
7241
then:
7342
function: 'IPA107UpdateResponseCodeShouldBe200OK'
7443
xgen-IPA-107-update-method-response-is-get-method-response:

tools/spectral/ipa/rulesets/README.md

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -279,38 +279,21 @@ Rule checks for the following conditions:
279279

280280
Rules are based on [http://go/ipa/IPA-107](http://go/ipa/IPA-107).
281281

282-
#### xgen-IPA-107-put-must-not-have-query-params
282+
#### xgen-IPA-107-update-must-not-have-query-params
283283

284284
![warn](https://img.shields.io/badge/warning-yellow)
285285
Update operations must not accept query parameters.
286286
##### Implementation details
287-
Validation checks the PUT method for single resource paths and singleton resources.
287+
Validation checks the PATCH/PUT methods for single resource paths and singleton resources.
288288

289289
- Query parameters `envelope` and `pretty` are exempt from this rule
290290
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
291-
#### xgen-IPA-107-patch-must-not-have-query-params
292-
293-
![warn](https://img.shields.io/badge/warning-yellow)
294-
Update operations must not accept query parameters.
295-
##### Implementation details
296-
Validation checks the PATCH method for single resource paths and singleton resources.
297-
298-
- Query parameters `envelope` and `pretty` are exempt from this rule
299-
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
300-
#### xgen-IPA-107-put-method-response-code-is-200
301-
302-
![warn](https://img.shields.io/badge/warning-yellow)
303-
The Update method response status code should be 200 OK.
304-
##### Implementation details
305-
Validation checks the PUT method for single resource paths and [singleton resources](https://go/ipa/113).
306-
307-
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
308-
#### xgen-IPA-107-patch-method-response-code-is-200
291+
#### xgen-IPA-107-update-method-response-code-is-200
309292

310293
![warn](https://img.shields.io/badge/warning-yellow)
311294
The Update method response status code should be 200 OK.
312295
##### Implementation details
313-
Validation checks the PATCH method for single resource paths and [singleton resources](https://go/ipa/113).
296+
Validation checks the PATCH/PUT methods for single resource paths and [singleton resources](https://go/ipa/113).
314297

315298
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
316299
#### xgen-IPA-107-update-method-response-is-get-method-response

0 commit comments

Comments
 (0)