Skip to content

Commit efecc4a

Browse files
Merge branch 'main' into CLOUDP-304053
2 parents 2734424 + 3cd6df5 commit efecc4a

10 files changed

+474
-17
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +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:
124-
'Input parameter [filter]: Create operations should not have query parameters. http://go/ipa-spectral#IPA-106',
123+
message: 'Create operations should not have query parameters. Found [filter]. http://go/ipa/106',
125124
path: ['paths', '/resource', 'post'],
126125
severity: DiagnosticSeverity.Warning,
127126
},
128127
{
129128
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
130-
message:
131-
'Input parameter [query-param]: Create operations should not have query parameters. http://go/ipa-spectral#IPA-106',
129+
message: 'Create operations should not have query parameters. Found [query-param]. http://go/ipa/106',
132130
path: ['paths', '/resourceTwo', 'post'],
133131
severity: DiagnosticSeverity.Warning,
134132
},
135133
{
136134
code: 'xgen-IPA-106-create-method-should-not-have-query-parameters',
137-
message:
138-
'Input parameter [query-param-2]: Create operations should not have query parameters. http://go/ipa-spectral#IPA-106',
135+
message: 'Create operations should not have query parameters. Found [query-param-2]. http://go/ipa/106',
139136
path: ['paths', '/resourceTwo', 'post'],
140137
severity: DiagnosticSeverity.Warning,
141138
},
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/ipa-spectral.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extends:
44
- ./rulesets/IPA-104.yaml
55
- ./rulesets/IPA-105.yaml
66
- ./rulesets/IPA-106.yaml
7+
- ./rulesets/IPA-107.yaml
78
- ./rulesets/IPA-108.yaml
89
- ./rulesets/IPA-109.yaml
910
- ./rulesets/IPA-113.yaml

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ functions:
77
rules:
88
xgen-IPA-005-exception-extension-format:
99
description: |
10-
IPA exception extensions must follow the correct format. http://go/ipa/5
10+
IPA exception extensions must follow the correct format.
1111
1212
##### Implementation details
1313
Rule checks for the following conditions:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ rules:
3232
function: 'eachResourceHasListMethod'
3333
xgen-IPA-105-list-method-response-is-get-method-response:
3434
description: >-
35-
The response body of the List method should consist of the same resource object returned by the Get method. http://go/ipa/105
35+
The response body of the List method should consist of the same resource object returned by the Get method.
3636
3737
##### Implementation details
3838

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ rules:
3434
given: '$.paths[*].post'
3535
then:
3636
function: 'createMethodShouldNotHaveQueryParameters'
37+
functionOptions:
38+
ignoredValues: ['pretty', 'envelope']
3739
xgen-IPA-106-create-method-request-body-is-get-method-response:
3840
description: >-
3941
Request body content of the Create method and response content of the Get method should refer to the same resource.

0 commit comments

Comments
 (0)