Skip to content

Commit 1e88a54

Browse files
CLOUDP-271995: Fixes and tests
1 parent 477292b commit 1e88a54

File tree

7 files changed

+360
-20
lines changed

7 files changed

+360
-20
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,20 +120,19 @@ testRule('xgen-IPA-106-create-method-should-not-have-query-parameters', [
120120
errors: [
121121
{
122122
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
123-
message: 'Input parameter [filter]: Create operations should not have query parameters. http://go/ipa/106',
123+
message: 'Create operations should not have query parameters. Found [filter]. http://go/ipa/106',
124124
path: ['paths', '/resource', 'post'],
125125
severity: DiagnosticSeverity.Warning,
126126
},
127127
{
128128
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
129-
message: 'Input parameter [query-param]: Create operations should not have query parameters. http://go/ipa/106',
129+
message: 'Create operations should not have query parameters. Found [query-param]. http://go/ipa/106',
130130
path: ['paths', '/resourceTwo', 'post'],
131131
severity: DiagnosticSeverity.Warning,
132132
},
133133
{
134134
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
135-
message:
136-
'Input parameter [query-param-2]: Create operations should not have query parameters. http://go/ipa/106',
135+
message: 'Create operations should not have query parameters. Found [query-param-2]. http://go/ipa/106',
137136
path: ['paths', '/resourceTwo', 'post'],
138137
severity: DiagnosticSeverity.Warning,
139138
},
Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
import testRule from './__helpers__/testRule';
2+
import { DiagnosticSeverity } from '@stoplight/types';
3+
4+
const componentSchemas = {
5+
schemas: {
6+
Schema: {
7+
type: 'object',
8+
},
9+
},
10+
parameters: {
11+
QueryParam: {
12+
name: 'query-param',
13+
in: 'query',
14+
schema: {
15+
type: 'string',
16+
},
17+
},
18+
QueryParam2: {
19+
name: 'query-param-2',
20+
in: 'query',
21+
schema: {
22+
type: 'string',
23+
},
24+
},
25+
PathParam: {
26+
name: 'resource-id',
27+
in: 'path',
28+
schema: {
29+
type: 'string',
30+
},
31+
},
32+
envelope: {
33+
name: 'envelope',
34+
in: 'query',
35+
},
36+
pretty: {
37+
name: 'pretty',
38+
in: 'query',
39+
},
40+
},
41+
};
42+
43+
testRule('xgen-IPA-107-put-must-not-have-query-params', [
44+
{
45+
name: 'valid put',
46+
document: {
47+
components: componentSchemas,
48+
paths: {
49+
'/resource/{id}': {
50+
put: {
51+
parameters: [
52+
{
53+
name: 'header-param',
54+
in: 'header',
55+
schema: { type: 'string' },
56+
},
57+
{
58+
name: 'resource-id',
59+
in: 'path',
60+
schema: {
61+
$ref: '#/components/schemas/Schema',
62+
},
63+
},
64+
{
65+
$ref: '#/components/parameters/PathParam',
66+
},
67+
{
68+
$ref: '#/components/parameters/envelope',
69+
},
70+
{
71+
$ref: '#/components/parameters/pretty',
72+
},
73+
],
74+
},
75+
},
76+
'/resource/{id}/singleton': {
77+
put: {
78+
parameters: [],
79+
},
80+
},
81+
},
82+
},
83+
errors: [],
84+
},
85+
{
86+
name: 'invalid put',
87+
document: {
88+
components: componentSchemas,
89+
paths: {
90+
'/resource/{id}': {
91+
put: {
92+
parameters: [
93+
{
94+
name: 'filter',
95+
in: 'query',
96+
schema: { type: 'string' },
97+
},
98+
],
99+
},
100+
},
101+
'/resource/{id}/singleton': {
102+
put: {
103+
parameters: [
104+
{
105+
name: 'header-param',
106+
in: 'header',
107+
schema: { type: 'string' },
108+
},
109+
{
110+
$ref: '#/components/parameters/QueryParam',
111+
},
112+
{
113+
$ref: '#/components/parameters/QueryParam2',
114+
},
115+
],
116+
},
117+
},
118+
},
119+
},
120+
errors: [
121+
{
122+
code: 'xgen-IPA-107-put-must-not-have-query-params',
123+
message: 'Update operations must not have query parameters. Found [filter]. http://go/ipa-spectral#IPA-107',
124+
path: ['paths', '/resource/{id}', 'put'],
125+
severity: DiagnosticSeverity.Warning,
126+
},
127+
{
128+
code: 'xgen-IPA-107-put-must-not-have-query-params',
129+
message:
130+
'Update operations must not have query parameters. Found [query-param]. http://go/ipa-spectral#IPA-107',
131+
path: ['paths', '/resource/{id}/singleton', 'put'],
132+
severity: DiagnosticSeverity.Warning,
133+
},
134+
{
135+
code: 'xgen-IPA-107-put-must-not-have-query-params',
136+
message:
137+
'Update operations must not have query parameters. Found [query-param-2]. http://go/ipa-spectral#IPA-107',
138+
path: ['paths', '/resource/{id}/singleton', 'put'],
139+
severity: DiagnosticSeverity.Warning,
140+
},
141+
],
142+
},
143+
{
144+
name: 'invalid put with exceptions',
145+
document: {
146+
components: componentSchemas,
147+
paths: {
148+
'/resource/{id}': {
149+
put: {
150+
parameters: [
151+
{
152+
name: 'filter',
153+
in: 'query',
154+
schema: { type: 'string' },
155+
},
156+
],
157+
'x-xgen-IPA-exception': {
158+
'xgen-IPA-107-put-must-not-have-query-params': 'Reason',
159+
},
160+
},
161+
},
162+
'/resource/{id}/singleton': {
163+
put: {
164+
parameters: [
165+
{
166+
$ref: '#/components/parameters/QueryParam',
167+
},
168+
],
169+
'x-xgen-IPA-exception': {
170+
'xgen-IPA-107-put-must-not-have-query-params': 'Reason',
171+
},
172+
},
173+
},
174+
},
175+
},
176+
errors: [],
177+
},
178+
]);
179+
180+
testRule('xgen-IPA-107-patch-must-not-have-query-params', [
181+
{
182+
name: 'valid patch',
183+
document: {
184+
components: componentSchemas,
185+
paths: {
186+
'/resource/{id}': {
187+
patch: {
188+
parameters: [
189+
{
190+
name: 'header-param',
191+
in: 'header',
192+
schema: { type: 'string' },
193+
},
194+
{
195+
name: 'resource-id',
196+
in: 'path',
197+
schema: {
198+
$ref: '#/components/schemas/Schema',
199+
},
200+
},
201+
{
202+
$ref: '#/components/parameters/PathParam',
203+
},
204+
{
205+
$ref: '#/components/parameters/envelope',
206+
},
207+
{
208+
$ref: '#/components/parameters/pretty',
209+
},
210+
],
211+
},
212+
},
213+
'/resource/{id}/singleton': {
214+
patch: {
215+
parameters: [],
216+
},
217+
},
218+
},
219+
},
220+
errors: [],
221+
},
222+
{
223+
name: 'invalid patch',
224+
document: {
225+
components: componentSchemas,
226+
paths: {
227+
'/resource/{id}': {
228+
patch: {
229+
parameters: [
230+
{
231+
name: 'filter',
232+
in: 'query',
233+
schema: { type: 'string' },
234+
},
235+
],
236+
},
237+
},
238+
'/resource/{id}/singleton': {
239+
patch: {
240+
parameters: [
241+
{
242+
name: 'header-param',
243+
in: 'header',
244+
schema: { type: 'string' },
245+
},
246+
{
247+
$ref: '#/components/parameters/QueryParam',
248+
},
249+
{
250+
$ref: '#/components/parameters/QueryParam2',
251+
},
252+
],
253+
},
254+
},
255+
},
256+
},
257+
errors: [
258+
{
259+
code: 'xgen-IPA-107-patch-must-not-have-query-params',
260+
message: 'Update operations must not have query parameters. Found [filter]. http://go/ipa-spectral#IPA-107',
261+
path: ['paths', '/resource/{id}', 'patch'],
262+
severity: DiagnosticSeverity.Warning,
263+
},
264+
{
265+
code: 'xgen-IPA-107-patch-must-not-have-query-params',
266+
message:
267+
'Update operations must not have query parameters. Found [query-param]. http://go/ipa-spectral#IPA-107',
268+
path: ['paths', '/resource/{id}/singleton', 'patch'],
269+
severity: DiagnosticSeverity.Warning,
270+
},
271+
{
272+
code: 'xgen-IPA-107-patch-must-not-have-query-params',
273+
message:
274+
'Update operations must not have query parameters. Found [query-param-2]. http://go/ipa-spectral#IPA-107',
275+
path: ['paths', '/resource/{id}/singleton', 'patch'],
276+
severity: DiagnosticSeverity.Warning,
277+
},
278+
],
279+
},
280+
{
281+
name: 'invalid patch with exceptions',
282+
document: {
283+
components: componentSchemas,
284+
paths: {
285+
'/resource/{id}': {
286+
patch: {
287+
parameters: [
288+
{
289+
name: 'filter',
290+
in: 'query',
291+
schema: { type: 'string' },
292+
},
293+
],
294+
'x-xgen-IPA-exception': {
295+
'xgen-IPA-107-patch-must-not-have-query-params': 'Reason',
296+
},
297+
},
298+
},
299+
'/resource/{id}/singleton': {
300+
patch: {
301+
parameters: [
302+
{
303+
$ref: '#/components/parameters/QueryParam',
304+
},
305+
],
306+
'x-xgen-IPA-exception': {
307+
'xgen-IPA-107-patch-must-not-have-query-params': 'Reason',
308+
},
309+
},
310+
},
311+
},
312+
},
313+
errors: [],
314+
},
315+
]);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ rules:
2828
given: '$.paths[*].post'
2929
then:
3030
function: 'createMethodShouldNotHaveQueryParameters'
31-
ignoredValues: [ 'pretty', 'envelope' ]
31+
functionOptions:
32+
ignoredValues: ['pretty', 'envelope']
3233
xgen-IPA-106-create-method-request-body-is-get-method-response:
3334
description: >-
3435
Request body content of the Create method and response content of the Get method should refer to the same resource. http://go/ipa/106

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,34 @@ rules:
88
xgen-IPA-107-put-must-not-have-query-params:
99
description: >-
1010
Update operations must not accept query parameters. http://go/ipa/107
11-
message: '{{error}} http://go/ipa/107'
11+
12+
##### Implementation details
13+
14+
Validation checks the PUT method for single resource paths and singleton resources.
15+
16+
- Query parameters `envelope` and `pretty` are exempt from this rule
17+
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
18+
message: '{{error}} http://go/ipa-spectral#IPA-107'
1219
severity: warn
1320
given: '$.paths[*].put'
1421
then:
1522
function: 'updateMethodMustNotHaveQueryParams'
1623
functionOptions:
17-
ignoredValues: [ 'pretty', 'envelope' ]
24+
ignoredValues: ['pretty', 'envelope']
1825
xgen-IPA-107-patch-must-not-have-query-params:
1926
description: >-
2027
Update operations must not accept query parameters. http://go/ipa/107
21-
message: '{{error}} http://go/ipa/107'
28+
29+
##### Implementation details
30+
31+
Validation checks the PATCH method for single resource paths and singleton resources.
32+
33+
- Query parameters `envelope` and `pretty` are exempt from this rule
34+
- Operation objects with `x-xgen-IPA-exception` for this rule are excluded from validation
35+
message: '{{error}} http://go/ipa-spectral#IPA-107'
2236
severity: warn
2337
given: '$.paths[*].patch'
2438
then:
2539
function: 'updateMethodMustNotHaveQueryParams'
2640
functionOptions:
27-
ignoredValues: [ 'pretty', 'envelope' ]
41+
ignoredValues: ['pretty', 'envelope']

0 commit comments

Comments
 (0)