Skip to content

Commit 1448759

Browse files
CLOUDP-271998: IPA-110: Pagination (Validate Paginated prefix and results array field) (#601)
1 parent 2103fae commit 1448759

File tree

8 files changed

+721
-6
lines changed

8 files changed

+721
-6
lines changed
Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
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: 'The response for collections must define an array of results containing the paginated resource.',
149+
path: ['paths', '/resources', 'get', 'responses', '200', 'content', 'application/json'],
150+
severity: DiagnosticSeverity.Warning,
151+
},
152+
],
153+
},
154+
{
155+
name: 'valid inline schema instead of reference',
156+
document: {
157+
paths: {
158+
'/resources': {
159+
get: {
160+
responses: {
161+
200: {
162+
content: {
163+
'application/json': {
164+
schema: {
165+
type: 'object',
166+
properties: {
167+
totalCount: {
168+
type: 'integer',
169+
},
170+
results: {
171+
type: 'array',
172+
items: {
173+
$ref: '#/components/schemas/Resource',
174+
},
175+
},
176+
},
177+
},
178+
},
179+
},
180+
},
181+
},
182+
},
183+
},
184+
'/resources/{id}': {
185+
get: {},
186+
},
187+
},
188+
components: {
189+
schemas: componentSchemas,
190+
},
191+
},
192+
errors: [],
193+
},
194+
{
195+
name: 'invalid schema missing results with exceptions',
196+
document: {
197+
paths: {
198+
'/resources': {
199+
get: {
200+
responses: {
201+
200: {
202+
content: {
203+
'application/json': {
204+
schema: {
205+
$ref: '#/components/schemas/PaginatedMissingResults',
206+
},
207+
'x-xgen-IPA-exception': {
208+
'xgen-IPA-110-collections-response-define-results-array': 'Reason',
209+
},
210+
},
211+
},
212+
},
213+
},
214+
},
215+
},
216+
'/resources/{id}': {
217+
get: {},
218+
},
219+
},
220+
components: {
221+
schemas: {
222+
PaginatedMissingResults: {
223+
type: 'object',
224+
properties: {
225+
totalCount: {
226+
type: 'integer',
227+
},
228+
},
229+
},
230+
},
231+
},
232+
},
233+
errors: [
234+
{
235+
code: 'xgen-IPA-110-collections-response-define-results-array',
236+
message: 'The response for collections must define an array of results containing the paginated resource.',
237+
path: ['paths', '/resources', 'get', 'responses', '200', 'content', 'application/json'],
238+
severity: DiagnosticSeverity.Warning,
239+
},
240+
],
241+
},
242+
]);

0 commit comments

Comments
 (0)