Skip to content

Commit 86096a7

Browse files
CLOUDP-304943: IPA rule for Update request schema suffix (#569)
1 parent 475abee commit 86096a7

9 files changed

+425
-65
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
152152
errors: [
153153
{
154154
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
155-
message: 'The response body schema must reference a schema with a Response suffix.',
155+
message: 'The schema must reference a schema with a Response suffix.',
156156
path: [
157157
'paths',
158158
'/resource/{id}',
@@ -166,7 +166,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
166166
},
167167
{
168168
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
169-
message: 'The response body schema must reference a schema with a Response suffix.',
169+
message: 'The schema must reference a schema with a Response suffix.',
170170
path: [
171171
'paths',
172172
'/resource/{id}',
@@ -180,7 +180,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
180180
},
181181
{
182182
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
183-
message: 'The response body schema must reference a schema with a Response suffix.',
183+
message: 'The schema must reference a schema with a Response suffix.',
184184
path: [
185185
'paths',
186186
'/resource/{id}',
@@ -194,7 +194,7 @@ testRule('xgen-IPA-104-get-method-returns-response-suffixed-object', [
194194
},
195195
{
196196
code: 'xgen-IPA-104-get-method-returns-response-suffixed-object',
197-
message: 'The response body schema must reference a schema with a Response suffix.',
197+
message: 'The schema must reference a schema with a Response suffix.',
198198
path: [
199199
'paths',
200200
'/resource/{id}/singleton',

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,31 +154,31 @@ testRule('xgen-IPA-106-create-method-request-body-is-request-suffixed-object', [
154154
errors: [
155155
{
156156
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
157-
message: 'The response body schema must reference a schema with a Request suffix. ',
157+
message: 'The schema must reference a schema with a Request suffix.',
158158
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
159159
severity: DiagnosticSeverity.Warning,
160160
},
161161
{
162162
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
163-
message: 'The response body schema must reference a schema with a Request suffix. ',
163+
message: 'The schema must reference a schema with a Request suffix.',
164164
path: ['paths', '/resource', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
165165
severity: DiagnosticSeverity.Warning,
166166
},
167167
{
168168
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
169-
message: 'The response body schema must reference a schema with a Request suffix. ',
169+
message: 'The schema must reference a schema with a Request suffix.',
170170
path: ['paths', '/resourceTwo', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
171171
severity: DiagnosticSeverity.Warning,
172172
},
173173
{
174174
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
175-
message: 'The response body schema must reference a schema with a Request suffix. ',
175+
message: 'The schema must reference a schema with a Request suffix.',
176176
path: ['paths', '/resourceTwo', 'post', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
177177
severity: DiagnosticSeverity.Warning,
178178
},
179179
{
180180
code: 'xgen-IPA-106-create-method-request-body-is-request-suffixed-object',
181-
message: 'The response body schema is defined inline and must reference a predefined schema. ',
181+
message: 'The schema is defined inline and must reference a predefined schema.',
182182
path: ['paths', '/resourceThree', 'post', 'requestBody', 'content', 'application/vnd.atlas.2023-01-01+json'],
183183
severity: DiagnosticSeverity.Warning,
184184
},
Lines changed: 300 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,300 @@
1+
import testRule from './__helpers__/testRule';
2+
import { DiagnosticSeverity } from '@stoplight/types';
3+
4+
const componentSchemas = {
5+
schemas: {
6+
SchemaUpdateRequest: {
7+
type: 'object',
8+
},
9+
Schema: {
10+
type: 'object',
11+
},
12+
},
13+
};
14+
15+
testRule('xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object', [
16+
{
17+
name: 'valid schema names names',
18+
document: {
19+
paths: {
20+
'/resource/{id}': {
21+
patch: {
22+
requestBody: {
23+
content: {
24+
'application/vnd.atlas.2024-01-01+json': {
25+
schema: {
26+
$ref: '#/components/schemas/SchemaUpdateRequest',
27+
},
28+
},
29+
'application/vnd.atlas.2025-01-01+json': {
30+
schema: {
31+
type: 'array',
32+
items: {
33+
$ref: '#/components/schemas/SchemaUpdateRequest',
34+
},
35+
},
36+
},
37+
},
38+
},
39+
},
40+
put: {
41+
requestBody: {
42+
content: {
43+
'application/vnd.atlas.2024-01-01+json': {
44+
schema: {
45+
$ref: '#/components/schemas/SchemaUpdateRequest',
46+
},
47+
},
48+
'application/vnd.atlas.2025-01-01+json': {
49+
schema: {
50+
type: 'array',
51+
items: {
52+
$ref: '#/components/schemas/SchemaUpdateRequest',
53+
},
54+
},
55+
},
56+
},
57+
},
58+
},
59+
},
60+
'/resourceTwo/{id}': {
61+
patch: {
62+
requestBody: {
63+
content: {
64+
'application/vnd.atlas.2024-08-05+json': {
65+
type: 'string',
66+
},
67+
},
68+
},
69+
},
70+
},
71+
'/resource/{id}/singleton': {
72+
patch: {
73+
requestBody: {
74+
content: {
75+
'application/vnd.atlas.2024-08-05+json': {
76+
schema: {
77+
$ref: '#/components/schemas/SchemaUpdateRequest',
78+
},
79+
},
80+
},
81+
},
82+
},
83+
},
84+
},
85+
components: componentSchemas,
86+
},
87+
errors: [],
88+
},
89+
{
90+
name: 'invalid resources',
91+
document: {
92+
paths: {
93+
'/resource/{id}': {
94+
patch: {
95+
requestBody: {
96+
content: {
97+
'application/vnd.atlas.2024-01-01+json': {
98+
schema: {
99+
$ref: '#/components/schemas/Schema',
100+
},
101+
},
102+
'application/vnd.atlas.2025-01-01+json': {
103+
schema: {
104+
type: 'array',
105+
items: {
106+
$ref: '#/components/schemas/Schema',
107+
},
108+
},
109+
},
110+
},
111+
},
112+
},
113+
put: {
114+
requestBody: {
115+
content: {
116+
'application/vnd.atlas.2024-01-01+json': {
117+
schema: {
118+
$ref: '#/components/schemas/Schema',
119+
},
120+
},
121+
'application/vnd.atlas.2025-01-01+json': {
122+
schema: {
123+
type: 'array',
124+
items: {
125+
$ref: '#/components/schemas/Schema',
126+
},
127+
},
128+
},
129+
},
130+
},
131+
},
132+
},
133+
'/resource/{id}/singleton': {
134+
patch: {
135+
requestBody: {
136+
content: {
137+
'application/vnd.atlas.2024-08-05+json': {
138+
schema: {
139+
$ref: '#/components/schemas/Schema',
140+
},
141+
},
142+
},
143+
},
144+
},
145+
put: {
146+
requestBody: {
147+
content: {
148+
'application/vnd.atlas.2024-08-05+json': {
149+
schema: {
150+
$ref: '#/components/schemas/Schema',
151+
},
152+
},
153+
},
154+
},
155+
},
156+
},
157+
},
158+
components: componentSchemas,
159+
},
160+
errors: [
161+
{
162+
code: 'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object',
163+
message: 'The schema must reference a schema with a UpdateRequest suffix.',
164+
path: ['paths', '/resource/{id}', 'patch', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
165+
severity: DiagnosticSeverity.Warning,
166+
},
167+
{
168+
code: 'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object',
169+
message: 'The schema must reference a schema with a UpdateRequest suffix.',
170+
path: ['paths', '/resource/{id}', 'patch', 'requestBody', 'content', 'application/vnd.atlas.2025-01-01+json'],
171+
severity: DiagnosticSeverity.Warning,
172+
},
173+
{
174+
code: 'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object',
175+
message: 'The schema must reference a schema with a UpdateRequest suffix.',
176+
path: ['paths', '/resource/{id}', 'put', 'requestBody', 'content', 'application/vnd.atlas.2024-01-01+json'],
177+
severity: DiagnosticSeverity.Warning,
178+
},
179+
{
180+
code: 'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object',
181+
message: 'The schema must reference a schema with a UpdateRequest suffix.',
182+
path: ['paths', '/resource/{id}', 'put', 'requestBody', 'content', 'application/vnd.atlas.2025-01-01+json'],
183+
severity: DiagnosticSeverity.Warning,
184+
},
185+
{
186+
code: 'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object',
187+
message: 'The schema must reference a schema with a UpdateRequest suffix.',
188+
path: [
189+
'paths',
190+
'/resource/{id}/singleton',
191+
'patch',
192+
'requestBody',
193+
'content',
194+
'application/vnd.atlas.2024-08-05+json',
195+
],
196+
severity: DiagnosticSeverity.Warning,
197+
},
198+
{
199+
code: 'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object',
200+
message: 'The schema must reference a schema with a UpdateRequest suffix.',
201+
path: [
202+
'paths',
203+
'/resource/{id}/singleton',
204+
'put',
205+
'requestBody',
206+
'content',
207+
'application/vnd.atlas.2024-08-05+json',
208+
],
209+
severity: DiagnosticSeverity.Warning,
210+
},
211+
],
212+
},
213+
{
214+
name: 'invalid resources with exceptions',
215+
document: {
216+
paths: {
217+
'/resource/{id}': {
218+
patch: {
219+
requestBody: {
220+
'application/vnd.atlas.2024-01-01+json': {
221+
'x-xgen-IPA-exception': {
222+
'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object': 'reason',
223+
},
224+
schema: {
225+
$ref: '#/components/schemas/Schema',
226+
},
227+
},
228+
'application/vnd.atlas.2025-01-01+json': {
229+
'x-xgen-IPA-exception': {
230+
'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object': 'reason',
231+
},
232+
schema: {
233+
type: 'array',
234+
items: {
235+
$ref: '#/components/schemas/Schema',
236+
},
237+
},
238+
},
239+
},
240+
},
241+
put: {
242+
requestBody: {
243+
'application/vnd.atlas.2024-01-01+json': {
244+
'x-xgen-IPA-exception': {
245+
'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object': 'reason',
246+
},
247+
schema: {
248+
$ref: '#/components/schemas/Schema',
249+
},
250+
},
251+
'application/vnd.atlas.2025-01-01+json': {
252+
'x-xgen-IPA-exception': {
253+
'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object': 'reason',
254+
},
255+
schema: {
256+
type: 'array',
257+
items: {
258+
$ref: '#/components/schemas/Schema',
259+
},
260+
},
261+
},
262+
},
263+
},
264+
},
265+
'/resource/{id}/singleton': {
266+
patch: {
267+
requestBody: {
268+
content: {
269+
'application/vnd.atlas.2024-08-05+json': {
270+
'x-xgen-IPA-exception': {
271+
'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object': 'reason',
272+
},
273+
schema: {
274+
$ref: '#/components/schemas/Schema',
275+
},
276+
},
277+
},
278+
},
279+
},
280+
put: {
281+
requestBody: {
282+
content: {
283+
'application/vnd.atlas.2024-08-05+json': {
284+
'x-xgen-IPA-exception': {
285+
'xgen-IPA-107-update-method-request-body-is-update-request-suffixed-object': 'reason',
286+
},
287+
schema: {
288+
$ref: '#/components/schemas/Schema',
289+
},
290+
},
291+
},
292+
},
293+
},
294+
},
295+
},
296+
components: componentSchemas,
297+
},
298+
errors: [],
299+
},
300+
]);

0 commit comments

Comments
 (0)