Skip to content

Commit 7ea4363

Browse files
CLOUDP-306572: Adds rule for "well defined schema"
1 parent 78968b9 commit 7ea4363

File tree

8 files changed

+718
-3
lines changed

8 files changed

+718
-3
lines changed
Lines changed: 371 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,371 @@
1+
import testRule from './__helpers__/testRule';
2+
import { DiagnosticSeverity } from '@stoplight/types';
3+
4+
testRule('xgen-IPA-117-objects-must-be-well-defined', [
5+
{
6+
name: 'valid objects',
7+
document: {
8+
paths: {
9+
'/resource/{id}': {
10+
get: {
11+
responses: {
12+
200: {
13+
content: {
14+
'application/vnd.atlas.2024-08-05+json': {
15+
type: 'object',
16+
schema: {},
17+
},
18+
'application/vnd.atlas.2023-08-05+json': {
19+
type: 'object',
20+
properties: {
21+
name: {
22+
type: 'object',
23+
properties: {},
24+
},
25+
hobbies: {
26+
type: 'array',
27+
items: {
28+
type: 'object',
29+
example: 'test',
30+
},
31+
},
32+
},
33+
},
34+
},
35+
},
36+
},
37+
requestBody: {
38+
content: {
39+
'application/vnd.atlas.2023-08-05+json': {
40+
type: 'object',
41+
examples: {},
42+
},
43+
},
44+
},
45+
},
46+
},
47+
},
48+
components: {
49+
schemas: {
50+
SchemaOneOf: {
51+
type: 'object',
52+
oneOf: {},
53+
},
54+
SchemaAllOf: {
55+
type: 'object',
56+
allOf: {},
57+
},
58+
SchemaAnyOf: {
59+
type: 'object',
60+
anyOf: {},
61+
},
62+
ArraySchema: {
63+
type: 'array',
64+
items: {
65+
type: 'object',
66+
schema: {},
67+
},
68+
},
69+
},
70+
},
71+
},
72+
errors: [],
73+
},
74+
{
75+
name: 'valid schema ref',
76+
document: {
77+
paths: {
78+
'/resource/{id}': {
79+
get: {
80+
responses: {
81+
200: {
82+
content: {
83+
'application/vnd.atlas.2024-08-05+json': {
84+
$ref: '#/components/schemas/Schema',
85+
},
86+
},
87+
},
88+
},
89+
},
90+
},
91+
},
92+
components: {
93+
schemas: {
94+
Schema: {
95+
type: 'object',
96+
properties: {},
97+
},
98+
},
99+
},
100+
},
101+
errors: [],
102+
},
103+
{
104+
name: 'invalid objects',
105+
document: {
106+
paths: {
107+
'/resource/{id}': {
108+
get: {
109+
responses: {
110+
200: {
111+
content: {
112+
'application/vnd.atlas.2024-08-05+json': {
113+
type: 'object',
114+
},
115+
'application/vnd.atlas.2023-08-05+json': {
116+
type: 'object',
117+
properties: {
118+
name: {
119+
type: 'object',
120+
},
121+
hobbies: {
122+
type: 'array',
123+
items: {
124+
type: 'object',
125+
},
126+
},
127+
},
128+
},
129+
},
130+
},
131+
},
132+
requestBody: {
133+
content: {
134+
'application/vnd.atlas.2023-08-05+json': {
135+
type: 'object',
136+
},
137+
},
138+
},
139+
},
140+
},
141+
},
142+
components: {
143+
schemas: {
144+
SchemaOneOf: {
145+
type: 'object',
146+
},
147+
SchemaAllOf: {
148+
type: 'object',
149+
},
150+
SchemaAnyOf: {
151+
type: 'object',
152+
},
153+
ArraySchema: {
154+
type: 'array',
155+
items: {
156+
type: 'object',
157+
},
158+
},
159+
},
160+
},
161+
},
162+
errors: [
163+
{
164+
code: 'xgen-IPA-117-objects-must-be-well-defined',
165+
message:
166+
'Components of type "object" must be well-defined with for example a schema, example(s) or properties.',
167+
path: [
168+
'paths',
169+
'/resource/{id}',
170+
'get',
171+
'responses',
172+
'200',
173+
'content',
174+
'application/vnd.atlas.2024-08-05+json',
175+
],
176+
severity: DiagnosticSeverity.Warning,
177+
},
178+
{
179+
code: 'xgen-IPA-117-objects-must-be-well-defined',
180+
message:
181+
'Components of type "object" must be well-defined with for example a schema, example(s) or properties.',
182+
path: [
183+
'paths',
184+
'/resource/{id}',
185+
'get',
186+
'responses',
187+
'200',
188+
'content',
189+
'application/vnd.atlas.2023-08-05+json',
190+
'properties',
191+
'name',
192+
],
193+
severity: DiagnosticSeverity.Warning,
194+
},
195+
{
196+
code: 'xgen-IPA-117-objects-must-be-well-defined',
197+
message:
198+
'Components of type "object" must be well-defined with for example a schema, example(s) or properties.',
199+
path: [
200+
'paths',
201+
'/resource/{id}',
202+
'get',
203+
'responses',
204+
'200',
205+
'content',
206+
'application/vnd.atlas.2023-08-05+json',
207+
'properties',
208+
'hobbies',
209+
'items',
210+
],
211+
severity: DiagnosticSeverity.Warning,
212+
},
213+
{
214+
code: 'xgen-IPA-117-objects-must-be-well-defined',
215+
message:
216+
'Components of type "object" must be well-defined with for example a schema, example(s) or properties.',
217+
path: ['paths', '/resource/{id}', 'get', 'requestBody', 'content', 'application/vnd.atlas.2023-08-05+json'],
218+
severity: DiagnosticSeverity.Warning,
219+
},
220+
{
221+
code: 'xgen-IPA-117-objects-must-be-well-defined',
222+
message:
223+
'Components of type "object" must be well-defined with for example a schema, example(s) or properties.',
224+
path: ['components', 'schemas', 'SchemaOneOf'],
225+
severity: DiagnosticSeverity.Warning,
226+
},
227+
{
228+
code: 'xgen-IPA-117-objects-must-be-well-defined',
229+
message:
230+
'Components of type "object" must be well-defined with for example a schema, example(s) or properties.',
231+
path: ['components', 'schemas', 'SchemaAllOf'],
232+
severity: DiagnosticSeverity.Warning,
233+
},
234+
{
235+
code: 'xgen-IPA-117-objects-must-be-well-defined',
236+
message:
237+
'Components of type "object" must be well-defined with for example a schema, example(s) or properties.',
238+
path: ['components', 'schemas', 'SchemaAnyOf'],
239+
severity: DiagnosticSeverity.Warning,
240+
},
241+
{
242+
code: 'xgen-IPA-117-objects-must-be-well-defined',
243+
message:
244+
'Components of type "object" must be well-defined with for example a schema, example(s) or properties.',
245+
path: ['components', 'schemas', 'ArraySchema', 'items'],
246+
severity: DiagnosticSeverity.Warning,
247+
},
248+
],
249+
},
250+
{
251+
name: 'invalid schema ref',
252+
document: {
253+
paths: {
254+
'/resource/{id}': {
255+
get: {
256+
responses: {
257+
200: {
258+
content: {
259+
'application/vnd.atlas.2024-08-05+json': {
260+
$ref: '#/components/schemas/Schema',
261+
},
262+
},
263+
},
264+
},
265+
},
266+
},
267+
},
268+
components: {
269+
schemas: {
270+
Schema: {
271+
type: 'object',
272+
},
273+
},
274+
},
275+
},
276+
errors: [
277+
{
278+
code: 'xgen-IPA-117-objects-must-be-well-defined',
279+
message:
280+
'Components of type "object" must be well-defined with for example a schema, example(s) or properties.',
281+
path: ['components', 'schemas', 'Schema'],
282+
severity: DiagnosticSeverity.Warning,
283+
},
284+
],
285+
},
286+
{
287+
name: 'invalid OAS with exceptions',
288+
document: {
289+
paths: {
290+
'/resource/{id}': {
291+
get: {
292+
responses: {
293+
200: {
294+
content: {
295+
'application/vnd.atlas.2024-08-05+json': {
296+
type: 'object',
297+
'x-xgen-IPA-exception': {
298+
'xgen-IPA-117-objects-must-be-well-defined': 'reason',
299+
},
300+
},
301+
'application/vnd.atlas.2023-08-05+json': {
302+
type: 'object',
303+
properties: {
304+
name: {
305+
type: 'object',
306+
'x-xgen-IPA-exception': {
307+
'xgen-IPA-117-objects-must-be-well-defined': 'reason',
308+
},
309+
},
310+
hobbies: {
311+
type: 'array',
312+
items: {
313+
type: 'object',
314+
'x-xgen-IPA-exception': {
315+
'xgen-IPA-117-objects-must-be-well-defined': 'reason',
316+
},
317+
},
318+
},
319+
},
320+
},
321+
},
322+
},
323+
},
324+
requestBody: {
325+
content: {
326+
'application/vnd.atlas.2023-08-05+json': {
327+
type: 'object',
328+
'x-xgen-IPA-exception': {
329+
'xgen-IPA-117-objects-must-be-well-defined': 'reason',
330+
},
331+
},
332+
},
333+
},
334+
},
335+
},
336+
},
337+
components: {
338+
schemas: {
339+
SchemaOneOf: {
340+
type: 'object',
341+
'x-xgen-IPA-exception': {
342+
'xgen-IPA-117-objects-must-be-well-defined': 'reason',
343+
},
344+
},
345+
SchemaAllOf: {
346+
type: 'object',
347+
'x-xgen-IPA-exception': {
348+
'xgen-IPA-117-objects-must-be-well-defined': 'reason',
349+
},
350+
},
351+
SchemaAnyOf: {
352+
type: 'object',
353+
'x-xgen-IPA-exception': {
354+
'xgen-IPA-117-objects-must-be-well-defined': 'reason',
355+
},
356+
},
357+
ArraySchema: {
358+
type: 'array',
359+
items: {
360+
type: 'object',
361+
'x-xgen-IPA-exception': {
362+
'xgen-IPA-117-objects-must-be-well-defined': 'reason',
363+
},
364+
},
365+
},
366+
},
367+
},
368+
},
369+
errors: [],
370+
},
371+
]);

0 commit comments

Comments
 (0)