Skip to content

Commit 79d6af4

Browse files
split it into two guidelines
1 parent 52698c6 commit 79d6af4

9 files changed

+312
-173
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,15 @@ const componentSchemas = {
1111
},
1212
},
1313
PaginatedSchema: {
14-
type: 'object',
14+
type: 'array',
15+
},
16+
ArraySchema: {
1517
properties: {
16-
totalCount: {
17-
type: 'integer',
18-
},
1918
results: {
2019
type: 'array',
21-
items: {
22-
$ref: '#/components/schemas/Schema',
23-
},
2420
},
2521
},
2622
},
27-
ArraySchema: {
28-
type: 'array',
29-
},
3023
},
3124
};
3225

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ import { DiagnosticSeverity } from '@stoplight/types';
44
const componentSchemas = {
55
schemas: {
66
PaginatedResourceSchema: {
7-
type: 'object',
87
properties: {
9-
totalCount: {
10-
type: 'integer',
11-
},
128
results: {
139
type: 'array',
1410
items: {
@@ -21,11 +17,7 @@ const componentSchemas = {
2117
type: 'object',
2218
},
2319
PaginatedArraySchema: {
24-
type: 'object',
2520
properties: {
26-
totalCount: {
27-
type: 'integer',
28-
},
2921
results: {
3022
type: 'array',
3123
items: {
@@ -87,11 +79,7 @@ testRule('xgen-IPA-105-list-method-response-is-get-method-response', [
8779
content: {
8880
'application/vnd.atlas.2024-08-05+json': {
8981
schema: {
90-
type: 'object',
9182
properties: {
92-
totalCount: {
93-
type: 'integer',
94-
},
9583
results: {
9684
type: 'array',
9785
items: {
@@ -314,10 +302,6 @@ testRule('xgen-IPA-105-list-method-response-is-get-method-response', [
314302
'application/vnd.atlas.2024-08-05+json': {
315303
schema: {
316304
properties: {
317-
type: 'object',
318-
totalCount: {
319-
type: 'integer',
320-
},
321305
results: {
322306
type: 'array',
323307
items: {
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import testRule from './__helpers__/testRule';
2+
import { DiagnosticSeverity } from '@stoplight/types';
3+
4+
const componentSchemas = {
5+
Resource: {
6+
type: 'object',
7+
},
8+
PaginatedResourceList: {
9+
type: 'object',
10+
properties: {
11+
totalCount: {
12+
type: 'integer',
13+
},
14+
results: {
15+
type: 'array',
16+
items: {
17+
$ref: '#/components/schemas/Resource',
18+
},
19+
},
20+
},
21+
},
22+
ResourcePaginatedList: {
23+
type: 'object',
24+
properties: {
25+
totalCount: {
26+
type: 'integer',
27+
},
28+
results: {
29+
type: 'array',
30+
items: {
31+
$ref: '#/components/schemas/Resource',
32+
},
33+
},
34+
},
35+
},
36+
};
37+
38+
testRule('xgen-IPA-110-collections-response-define-results-array', [
39+
{
40+
name: 'valid schemas with Paginated prefix',
41+
document: {
42+
paths: {
43+
'/resources': {
44+
get: {
45+
responses: {
46+
200: {
47+
content: {
48+
'application/json': {
49+
schema: {
50+
$ref: '#/components/schemas/PaginatedResourceList',
51+
},
52+
},
53+
},
54+
},
55+
},
56+
},
57+
},
58+
'/resources/{id}': {
59+
get: {
60+
responses: {
61+
200: {
62+
content: {
63+
'application/json': {
64+
schema: {
65+
$ref: '#/components/schemas/Resource',
66+
},
67+
},
68+
},
69+
},
70+
},
71+
},
72+
},
73+
},
74+
components: {
75+
schemas: componentSchemas,
76+
},
77+
},
78+
errors: [],
79+
},
80+
{
81+
name: 'valid schemas without Paginated prefix but with correct structure',
82+
document: {
83+
paths: {
84+
'/resources': {
85+
get: {
86+
responses: {
87+
200: {
88+
content: {
89+
'application/json': {
90+
schema: {
91+
$ref: '#/components/schemas/ResourcePaginatedList',
92+
},
93+
},
94+
},
95+
},
96+
},
97+
},
98+
},
99+
'/resources/{id}': {
100+
get: {},
101+
},
102+
},
103+
components: {
104+
schemas: componentSchemas,
105+
},
106+
},
107+
errors: [],
108+
},
109+
{
110+
name: 'invalid schema missing results',
111+
document: {
112+
paths: {
113+
'/resources': {
114+
get: {
115+
responses: {
116+
200: {
117+
content: {
118+
'application/json': {
119+
schema: {
120+
$ref: '#/components/schemas/PaginatedMissingResults',
121+
},
122+
},
123+
},
124+
},
125+
},
126+
},
127+
},
128+
'/resources/{id}': {
129+
get: {},
130+
},
131+
},
132+
components: {
133+
schemas: {
134+
PaginatedMissingResults: {
135+
type: 'object',
136+
properties: {
137+
totalCount: {
138+
type: 'integer',
139+
},
140+
},
141+
},
142+
},
143+
},
144+
},
145+
errors: [
146+
{
147+
code: 'xgen-IPA-110-collections-response-define-results-array',
148+
message:
149+
'The response for collections must define an array of results containing the paginated resource. The response should reference a schema that contains "results" (array) field.',
150+
path: ['paths', '/resources', 'get', 'responses', '200', 'content', 'application/json'],
151+
severity: DiagnosticSeverity.Warning,
152+
},
153+
],
154+
},
155+
{
156+
name: 'valid inline schema instead of reference',
157+
document: {
158+
paths: {
159+
'/resources': {
160+
get: {
161+
responses: {
162+
200: {
163+
content: {
164+
'application/json': {
165+
schema: {
166+
type: 'object',
167+
properties: {
168+
totalCount: {
169+
type: 'integer',
170+
},
171+
results: {
172+
type: 'array',
173+
items: {
174+
$ref: '#/components/schemas/Resource',
175+
},
176+
},
177+
},
178+
},
179+
},
180+
},
181+
},
182+
},
183+
},
184+
},
185+
'/resources/{id}': {
186+
get: {},
187+
},
188+
},
189+
components: {
190+
schemas: componentSchemas,
191+
},
192+
},
193+
errors: [],
194+
},
195+
]);

0 commit comments

Comments
 (0)