Skip to content

Commit 1b6dcd4

Browse files
IPA-110: Pagination (links array and includeCount not required)
1 parent ec69a23 commit 1b6dcd4

File tree

6 files changed

+552
-0
lines changed

6 files changed

+552
-0
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import testRule from './__helpers__/testRule';
2+
import { DiagnosticSeverity } from '@stoplight/types';
3+
4+
const parameters = {
5+
parameters: {
6+
includeCount: {
7+
name: 'includeCount',
8+
in: 'query',
9+
schema: {
10+
type: 'boolean',
11+
default: true,
12+
},
13+
},
14+
itemsPerPage: {
15+
name: 'itemsPerPage',
16+
in: 'query',
17+
schema: {
18+
type: 'integer',
19+
default: 100,
20+
},
21+
},
22+
},
23+
};
24+
25+
testRule('xgen-IPA-110-collections-request-includeCount-not-required', [
26+
{
27+
name: 'valid',
28+
document: {
29+
paths: {
30+
'/resources': {
31+
get: {
32+
parameters: [
33+
{
34+
name: 'includeCount',
35+
in: 'query',
36+
schema: {
37+
type: 'boolean',
38+
},
39+
},
40+
],
41+
},
42+
},
43+
'resources/{resourceId}': {
44+
get: {},
45+
},
46+
'/resourcesTwo': {
47+
get: {
48+
parameters: [
49+
{
50+
$ref: '#/components/parameters/includeCount',
51+
},
52+
],
53+
},
54+
},
55+
'resourcesTwo/{resourceId}': {
56+
get: {},
57+
},
58+
},
59+
components: parameters,
60+
},
61+
errors: [],
62+
},
63+
{
64+
name: 'valid - includeCount not present',
65+
document: {
66+
paths: {
67+
'/resources': {
68+
get: {
69+
parameters: [
70+
{
71+
$ref: '#/components/parameters/itemsPerPage',
72+
},
73+
],
74+
},
75+
},
76+
'resources/{resourceId}': {
77+
get: {},
78+
},
79+
},
80+
components: parameters,
81+
},
82+
errors: [],
83+
},
84+
{
85+
name: 'valid - no parameters at all',
86+
document: {
87+
paths: {
88+
'/resources': {
89+
get: {},
90+
},
91+
'resources/{resourceId}': {
92+
get: {},
93+
},
94+
},
95+
},
96+
errors: [],
97+
},
98+
{
99+
name: 'invalid - includeCount is required',
100+
document: {
101+
paths: {
102+
'/resources': {
103+
get: {
104+
parameters: [
105+
{
106+
name: 'includeCount',
107+
in: 'query',
108+
required: true,
109+
schema: {
110+
type: 'boolean',
111+
},
112+
},
113+
],
114+
},
115+
},
116+
},
117+
},
118+
errors: [
119+
{
120+
code: 'xgen-IPA-110-collections-request-includeCount-not-required',
121+
message: 'includeCount query parameter of List method must not be required.',
122+
path: ['paths', '/resources', 'get'],
123+
severity: DiagnosticSeverity.Warning,
124+
},
125+
],
126+
},
127+
{
128+
name: 'invalid - referenced includeCount is required',
129+
document: {
130+
paths: {
131+
'/resources': {
132+
get: {
133+
parameters: [
134+
{
135+
$ref: '#/components/parameters/RequiredIncludeCount',
136+
},
137+
],
138+
},
139+
},
140+
},
141+
components: {
142+
parameters: {
143+
RequiredIncludeCount: {
144+
name: 'includeCount',
145+
in: 'query',
146+
required: true,
147+
schema: {
148+
type: 'boolean',
149+
},
150+
},
151+
},
152+
},
153+
},
154+
errors: [
155+
{
156+
code: 'xgen-IPA-110-collections-request-includeCount-not-required',
157+
message: 'includeCount query parameter of List method must not be required.',
158+
path: ['paths', '/resources', 'get'],
159+
severity: DiagnosticSeverity.Warning,
160+
},
161+
],
162+
},
163+
{
164+
name: 'valid - handles exception',
165+
document: {
166+
paths: {
167+
'/resources': {
168+
get: {
169+
parameters: [
170+
{
171+
name: 'includeCount',
172+
in: 'query',
173+
required: true,
174+
schema: {
175+
type: 'boolean',
176+
},
177+
},
178+
],
179+
'x-xgen-IPA-exception': {
180+
'xgen-IPA-110-collections-request-includeCount-not-required': 'Reason',
181+
},
182+
},
183+
},
184+
},
185+
},
186+
errors: [],
187+
},
188+
]);
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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+
links: {
21+
type: 'array',
22+
},
23+
},
24+
},
25+
};
26+
27+
testRule('xgen-IPA-110-collections-response-define-links-array', [
28+
{
29+
name: 'valid schema',
30+
document: {
31+
paths: {
32+
'/resources': {
33+
get: {
34+
responses: {
35+
200: {
36+
content: {
37+
'application/json': {
38+
schema: {
39+
$ref: '#/components/schemas/PaginatedResourceList',
40+
},
41+
},
42+
},
43+
},
44+
},
45+
},
46+
},
47+
'/resources/{id}': {
48+
get: {
49+
responses: {
50+
200: {
51+
content: {
52+
'application/json': {
53+
schema: {
54+
$ref: '#/components/schemas/Resource',
55+
},
56+
},
57+
},
58+
},
59+
},
60+
},
61+
},
62+
},
63+
components: {
64+
schemas: componentSchemas,
65+
},
66+
},
67+
errors: [],
68+
},
69+
{
70+
name: 'invalid schema missing links',
71+
document: {
72+
paths: {
73+
'/resources': {
74+
get: {
75+
responses: {
76+
200: {
77+
content: {
78+
'application/json': {
79+
schema: {
80+
$ref: '#/components/schemas/PaginatedMissingLinks',
81+
},
82+
},
83+
},
84+
},
85+
},
86+
},
87+
},
88+
'/resources/{id}': {
89+
get: {},
90+
},
91+
},
92+
components: {
93+
schemas: {
94+
PaginatedMissingLinks: {
95+
type: 'object',
96+
properties: {
97+
totalCount: {
98+
type: 'integer',
99+
},
100+
},
101+
},
102+
},
103+
},
104+
},
105+
errors: [
106+
{
107+
code: 'xgen-IPA-110-collections-response-define-links-array',
108+
message:
109+
'The response for collections should define a links array field, providing links to next and previous pages.',
110+
path: ['paths', '/resources', 'get', 'responses', '200', 'content', 'application/json'],
111+
severity: DiagnosticSeverity.Warning,
112+
},
113+
],
114+
},
115+
{
116+
name: 'valid inline schema instead of reference',
117+
document: {
118+
paths: {
119+
'/resources': {
120+
get: {
121+
responses: {
122+
200: {
123+
content: {
124+
'application/json': {
125+
schema: {
126+
type: 'object',
127+
properties: {
128+
totalCount: {
129+
type: 'integer',
130+
},
131+
results: {
132+
type: 'array',
133+
items: {
134+
$ref: '#/components/schemas/Resource',
135+
},
136+
},
137+
links: {
138+
type: 'array',
139+
},
140+
},
141+
},
142+
},
143+
},
144+
},
145+
},
146+
},
147+
},
148+
'/resources/{id}': {
149+
get: {},
150+
},
151+
},
152+
components: {
153+
schemas: componentSchemas,
154+
},
155+
},
156+
errors: [],
157+
},
158+
{
159+
name: 'invalid schema missing results with exceptions',
160+
document: {
161+
paths: {
162+
'/resources': {
163+
get: {
164+
responses: {
165+
200: {
166+
content: {
167+
'application/json': {
168+
schema: {
169+
$ref: '#/components/schemas/PaginatedMissingLinks',
170+
},
171+
'x-xgen-IPA-exception': {
172+
'xgen-IPA-110-collections-response-define-links-array': 'Reason',
173+
},
174+
},
175+
},
176+
},
177+
},
178+
},
179+
},
180+
'/resources/{id}': {
181+
get: {},
182+
},
183+
},
184+
components: {
185+
schemas: {
186+
PaginatedMissingLinks: {
187+
type: 'object',
188+
properties: {
189+
totalCount: {
190+
type: 'integer',
191+
},
192+
},
193+
},
194+
},
195+
},
196+
},
197+
errors: [],
198+
},
199+
]);

0 commit comments

Comments
 (0)