@redocly/openapi-core 1.0.0-beta.98 → 1.0.0-beta.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/bundle.d.ts +2 -0
- package/lib/bundle.js +6 -3
- package/lib/config/all.js +1 -0
- package/lib/ref-utils.js +1 -0
- package/lib/rules/common/response-contains-header.d.ts +2 -0
- package/lib/rules/common/response-contains-header.js +29 -0
- package/lib/rules/common/scalar-property-missing-example.d.ts +2 -0
- package/lib/rules/common/scalar-property-missing-example.js +41 -0
- package/lib/rules/oas2/index.d.ts +3 -0
- package/lib/rules/oas2/index.js +6 -0
- package/lib/rules/oas2/response-contains-property.d.ts +2 -0
- package/lib/rules/oas2/response-contains-property.js +38 -0
- package/lib/rules/oas3/index.js +6 -0
- package/lib/rules/oas3/response-contains-property.d.ts +2 -0
- package/lib/rules/oas3/response-contains-property.js +40 -0
- package/lib/types/oas3.js +17 -6
- package/lib/types/oas3_1.js +9 -7
- package/lib/types/redocly-yaml.js +10 -0
- package/lib/typings/openapi.d.ts +3 -2
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +3 -1
- package/package.json +1 -1
- package/{__tests__ → src/__tests__}/__snapshots__/bundle.test.ts.snap +26 -0
- package/{__tests__ → src/__tests__}/bundle.test.ts +30 -6
- package/{__tests__ → src/__tests__}/codeframes.test.ts +3 -3
- package/{__tests__ → src/__tests__}/fixtures/extension.js +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/definitions.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/examples.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/external-request-body.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/externalref.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/hosted.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/openapi-with-external-refs-conflicting-names.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/openapi-with-external-refs.yaml +0 -0
- package/src/__tests__/fixtures/refs/openapi-with-url-refs.yaml +18 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/param-b.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/param-c.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/rename.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/requestBody.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/schema-a.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/simple.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/refs/vendor.schema.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/External.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/External2.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/description.md +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/externalInfo.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/externalLicense.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/openapi-with-back.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/openapi-with-md-description.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/openapi.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/schemas/type-a.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/schemas/type-b.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/transitive/a.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/transitive/components.yaml +0 -0
- package/{__tests__ → src/__tests__}/fixtures/resolve/transitive/schemas.yaml +0 -0
- package/src/__tests__/lint.test.ts +13 -0
- package/{__tests__ → src/__tests__}/login.test.ts +1 -1
- package/{__tests__ → src/__tests__}/normalizeVisitors.test.ts +4 -4
- package/{__tests__ → src/__tests__}/ref-utils.test.ts +5 -5
- package/{__tests__ → src/__tests__}/resolve-http.test.ts +4 -4
- package/{__tests__ → src/__tests__}/resolve.test.ts +4 -4
- package/src/__tests__/utils.test.ts +12 -1
- package/{__tests__ → src/__tests__}/walk.test.ts +5 -5
- package/src/bundle.ts +18 -3
- package/src/config/__tests__/config-resolvers.test.ts +1 -1
- package/src/config/all.ts +1 -0
- package/src/ref-utils.ts +1 -0
- package/src/rules/common/__tests__/scalar-property-missing-example.test.ts +207 -0
- package/src/rules/common/response-contains-header.ts +30 -0
- package/src/rules/common/scalar-property-missing-example.ts +55 -0
- package/src/rules/oas2/__tests__/response-contains-header.test.ts +174 -0
- package/src/rules/oas2/__tests__/response-contains-property.test.ts +155 -0
- package/src/rules/oas2/index.ts +6 -0
- package/src/rules/oas2/response-contains-property.ts +36 -0
- package/src/rules/oas3/__tests__/response-contains-header.test.ts +273 -0
- package/src/rules/oas3/__tests__/response-contains-property.test.ts +403 -0
- package/src/rules/oas3/index.ts +6 -0
- package/src/rules/oas3/response-contains-property.ts +38 -0
- package/src/types/oas3.ts +15 -6
- package/src/types/oas3_1.ts +9 -7
- package/src/types/redocly-yaml.ts +10 -0
- package/src/typings/openapi.ts +2 -1
- package/src/utils.ts +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/__tests__/lint.test.ts +0 -17
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { outdent } from 'outdent';
|
|
2
|
+
import { lintDocument } from '../../../lint';
|
|
3
|
+
import { parseYamlToDocument, makeConfig } from '../../../../__tests__/utils';
|
|
4
|
+
import { BaseResolver } from '../../../resolve';
|
|
5
|
+
|
|
6
|
+
describe('Oas3 response-contains-property', () => {
|
|
7
|
+
it('should report a response object not containing the property', async () => {
|
|
8
|
+
const document = parseYamlToDocument(outdent`
|
|
9
|
+
openapi: 3.0.3
|
|
10
|
+
info:
|
|
11
|
+
version: 3.0.0
|
|
12
|
+
paths:
|
|
13
|
+
/store/subscribe:
|
|
14
|
+
post:
|
|
15
|
+
responses:
|
|
16
|
+
'201':
|
|
17
|
+
content:
|
|
18
|
+
application/json:
|
|
19
|
+
schema:
|
|
20
|
+
type: object
|
|
21
|
+
properties:
|
|
22
|
+
subscriptionId:
|
|
23
|
+
type: string
|
|
24
|
+
example: AAA-123-BBB-456
|
|
25
|
+
`);
|
|
26
|
+
const results = await lintDocument({
|
|
27
|
+
externalRefResolver: new BaseResolver(),
|
|
28
|
+
document,
|
|
29
|
+
config: await makeConfig({
|
|
30
|
+
'response-contains-property': {
|
|
31
|
+
severity: 'error',
|
|
32
|
+
names: { 201: ['id'] },
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
expect(results).toMatchInlineSnapshot(`
|
|
37
|
+
Array [
|
|
38
|
+
Object {
|
|
39
|
+
"location": Array [
|
|
40
|
+
Object {
|
|
41
|
+
"pointer": "#/paths/~1store~1subscribe/post/responses/201/content/application~1json/schema/properties",
|
|
42
|
+
"reportOnKey": true,
|
|
43
|
+
"source": Source {
|
|
44
|
+
"absoluteRef": "",
|
|
45
|
+
"body": "openapi: 3.0.3
|
|
46
|
+
info:
|
|
47
|
+
version: 3.0.0
|
|
48
|
+
paths:
|
|
49
|
+
/store/subscribe:
|
|
50
|
+
post:
|
|
51
|
+
responses:
|
|
52
|
+
'201':
|
|
53
|
+
content:
|
|
54
|
+
application/json:
|
|
55
|
+
schema:
|
|
56
|
+
type: object
|
|
57
|
+
properties:
|
|
58
|
+
subscriptionId:
|
|
59
|
+
type: string
|
|
60
|
+
example: AAA-123-BBB-456",
|
|
61
|
+
"mimeType": undefined,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
"message": "Response object must contain a top-level \\"id\\" property.",
|
|
66
|
+
"ruleId": "response-contains-property",
|
|
67
|
+
"severity": "error",
|
|
68
|
+
"suggest": Array [],
|
|
69
|
+
},
|
|
70
|
+
]
|
|
71
|
+
`);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should report response objects not containing props for a subset of status codes', async () => {
|
|
75
|
+
const document = parseYamlToDocument(outdent`
|
|
76
|
+
openapi: 3.0.3
|
|
77
|
+
info:
|
|
78
|
+
version: 3.0.0
|
|
79
|
+
paths:
|
|
80
|
+
/store/subscribe:
|
|
81
|
+
post:
|
|
82
|
+
responses:
|
|
83
|
+
'201':
|
|
84
|
+
content:
|
|
85
|
+
application/json:
|
|
86
|
+
schema:
|
|
87
|
+
type: object
|
|
88
|
+
properties:
|
|
89
|
+
subscriptionId:
|
|
90
|
+
type: string
|
|
91
|
+
example: AAA-123-BBB-456
|
|
92
|
+
400:
|
|
93
|
+
content:
|
|
94
|
+
application/json:
|
|
95
|
+
schema:
|
|
96
|
+
type: object
|
|
97
|
+
properties:
|
|
98
|
+
status:
|
|
99
|
+
type: integer
|
|
100
|
+
description: error
|
|
101
|
+
`);
|
|
102
|
+
const results = await lintDocument({
|
|
103
|
+
externalRefResolver: new BaseResolver(),
|
|
104
|
+
document,
|
|
105
|
+
config: await makeConfig({
|
|
106
|
+
'response-contains-property': {
|
|
107
|
+
severity: 'error',
|
|
108
|
+
names: { '2xx': ['id'], '400': ['error'] },
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
});
|
|
112
|
+
expect(results).toMatchInlineSnapshot(`
|
|
113
|
+
Array [
|
|
114
|
+
Object {
|
|
115
|
+
"location": Array [
|
|
116
|
+
Object {
|
|
117
|
+
"pointer": "#/paths/~1store~1subscribe/post/responses/201/content/application~1json/schema/properties",
|
|
118
|
+
"reportOnKey": true,
|
|
119
|
+
"source": Source {
|
|
120
|
+
"absoluteRef": "",
|
|
121
|
+
"body": "openapi: 3.0.3
|
|
122
|
+
info:
|
|
123
|
+
version: 3.0.0
|
|
124
|
+
paths:
|
|
125
|
+
/store/subscribe:
|
|
126
|
+
post:
|
|
127
|
+
responses:
|
|
128
|
+
'201':
|
|
129
|
+
content:
|
|
130
|
+
application/json:
|
|
131
|
+
schema:
|
|
132
|
+
type: object
|
|
133
|
+
properties:
|
|
134
|
+
subscriptionId:
|
|
135
|
+
type: string
|
|
136
|
+
example: AAA-123-BBB-456
|
|
137
|
+
400:
|
|
138
|
+
content:
|
|
139
|
+
application/json:
|
|
140
|
+
schema:
|
|
141
|
+
type: object
|
|
142
|
+
properties:
|
|
143
|
+
status:
|
|
144
|
+
type: integer
|
|
145
|
+
description: error",
|
|
146
|
+
"mimeType": undefined,
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
"message": "Response object must contain a top-level \\"id\\" property.",
|
|
151
|
+
"ruleId": "response-contains-property",
|
|
152
|
+
"severity": "error",
|
|
153
|
+
"suggest": Array [],
|
|
154
|
+
},
|
|
155
|
+
Object {
|
|
156
|
+
"location": Array [
|
|
157
|
+
Object {
|
|
158
|
+
"pointer": "#/paths/~1store~1subscribe/post/responses/400/content/application~1json/schema/properties",
|
|
159
|
+
"reportOnKey": true,
|
|
160
|
+
"source": Source {
|
|
161
|
+
"absoluteRef": "",
|
|
162
|
+
"body": "openapi: 3.0.3
|
|
163
|
+
info:
|
|
164
|
+
version: 3.0.0
|
|
165
|
+
paths:
|
|
166
|
+
/store/subscribe:
|
|
167
|
+
post:
|
|
168
|
+
responses:
|
|
169
|
+
'201':
|
|
170
|
+
content:
|
|
171
|
+
application/json:
|
|
172
|
+
schema:
|
|
173
|
+
type: object
|
|
174
|
+
properties:
|
|
175
|
+
subscriptionId:
|
|
176
|
+
type: string
|
|
177
|
+
example: AAA-123-BBB-456
|
|
178
|
+
400:
|
|
179
|
+
content:
|
|
180
|
+
application/json:
|
|
181
|
+
schema:
|
|
182
|
+
type: object
|
|
183
|
+
properties:
|
|
184
|
+
status:
|
|
185
|
+
type: integer
|
|
186
|
+
description: error",
|
|
187
|
+
"mimeType": undefined,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
"message": "Response object must contain a top-level \\"error\\" property.",
|
|
192
|
+
"ruleId": "response-contains-property",
|
|
193
|
+
"severity": "error",
|
|
194
|
+
"suggest": Array [],
|
|
195
|
+
},
|
|
196
|
+
]
|
|
197
|
+
`);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('should not report response objects containing specified properties', async () => {
|
|
201
|
+
const document = parseYamlToDocument(outdent`
|
|
202
|
+
openapi: 3.0.3
|
|
203
|
+
info:
|
|
204
|
+
version: 3.0.0
|
|
205
|
+
paths:
|
|
206
|
+
/store/subscribe:
|
|
207
|
+
post:
|
|
208
|
+
responses:
|
|
209
|
+
'201':
|
|
210
|
+
content:
|
|
211
|
+
application/json:
|
|
212
|
+
schema:
|
|
213
|
+
type: object
|
|
214
|
+
properties:
|
|
215
|
+
subscriptionId:
|
|
216
|
+
type: string
|
|
217
|
+
example: AAA-123-BBB-456
|
|
218
|
+
id: some-id
|
|
219
|
+
400:
|
|
220
|
+
content:
|
|
221
|
+
application/json:
|
|
222
|
+
schema:
|
|
223
|
+
type: object
|
|
224
|
+
properties:
|
|
225
|
+
status:
|
|
226
|
+
type: integer
|
|
227
|
+
error:
|
|
228
|
+
type: string
|
|
229
|
+
`);
|
|
230
|
+
const results = await lintDocument({
|
|
231
|
+
externalRefResolver: new BaseResolver(),
|
|
232
|
+
document,
|
|
233
|
+
config: await makeConfig({
|
|
234
|
+
'response-contains-property': {
|
|
235
|
+
severity: 'error',
|
|
236
|
+
names: { '2xx': ['id'], '400': ['error'] },
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
});
|
|
240
|
+
expect(results).toMatchInlineSnapshot(`Array []`);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('should not report a response object when schema type is not object', async () => {
|
|
244
|
+
const document = parseYamlToDocument(outdent`
|
|
245
|
+
openapi: 3.0.3
|
|
246
|
+
info:
|
|
247
|
+
version: 3.0.0
|
|
248
|
+
paths:
|
|
249
|
+
/store/subscribe:
|
|
250
|
+
post:
|
|
251
|
+
responses:
|
|
252
|
+
'201':
|
|
253
|
+
content:
|
|
254
|
+
text/plain:
|
|
255
|
+
schema:
|
|
256
|
+
type: string
|
|
257
|
+
`);
|
|
258
|
+
const results = await lintDocument({
|
|
259
|
+
externalRefResolver: new BaseResolver(),
|
|
260
|
+
document,
|
|
261
|
+
config: await makeConfig({
|
|
262
|
+
'response-contains-property': {
|
|
263
|
+
severity: 'error',
|
|
264
|
+
names: { 201: ['id'] },
|
|
265
|
+
},
|
|
266
|
+
}),
|
|
267
|
+
});
|
|
268
|
+
expect(results).toMatchInlineSnapshot(`Array []`);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('should not report response objects when there is no `names` field specified', async () => {
|
|
272
|
+
const document = parseYamlToDocument(outdent`
|
|
273
|
+
openapi: 3.0.3
|
|
274
|
+
info:
|
|
275
|
+
version: 3.0.0
|
|
276
|
+
paths:
|
|
277
|
+
/store/subscribe:
|
|
278
|
+
post:
|
|
279
|
+
responses:
|
|
280
|
+
'201':
|
|
281
|
+
content:
|
|
282
|
+
application/json:
|
|
283
|
+
schema:
|
|
284
|
+
type: object
|
|
285
|
+
properties:
|
|
286
|
+
subscriptionId:
|
|
287
|
+
type: string
|
|
288
|
+
example: AAA-123-BBB-456
|
|
289
|
+
400:
|
|
290
|
+
content:
|
|
291
|
+
application/json:
|
|
292
|
+
schema:
|
|
293
|
+
type: object
|
|
294
|
+
properties:
|
|
295
|
+
status:
|
|
296
|
+
type: integer
|
|
297
|
+
description: error
|
|
298
|
+
`);
|
|
299
|
+
const results = await lintDocument({
|
|
300
|
+
externalRefResolver: new BaseResolver(),
|
|
301
|
+
document,
|
|
302
|
+
config: await makeConfig({
|
|
303
|
+
'response-contains-property': {
|
|
304
|
+
severity: 'error',
|
|
305
|
+
},
|
|
306
|
+
}),
|
|
307
|
+
});
|
|
308
|
+
expect(results).toMatchInlineSnapshot(`Array []`);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('should not report response objects for 204 status code', async () => {
|
|
312
|
+
const document = parseYamlToDocument(outdent`
|
|
313
|
+
openapi: 3.0.3
|
|
314
|
+
info:
|
|
315
|
+
version: 3.0.0
|
|
316
|
+
paths:
|
|
317
|
+
/store/subscribe:
|
|
318
|
+
post:
|
|
319
|
+
responses:
|
|
320
|
+
'204':
|
|
321
|
+
content:
|
|
322
|
+
application/json:
|
|
323
|
+
schema:
|
|
324
|
+
type: object
|
|
325
|
+
properties:
|
|
326
|
+
subscriptionId:
|
|
327
|
+
type: string
|
|
328
|
+
example: AAA-123-BBB-456
|
|
329
|
+
`);
|
|
330
|
+
const results = await lintDocument({
|
|
331
|
+
externalRefResolver: new BaseResolver(),
|
|
332
|
+
document,
|
|
333
|
+
config: await makeConfig({
|
|
334
|
+
'response-contains-property': {
|
|
335
|
+
severity: 'error',
|
|
336
|
+
names: { '2xx': ['id'] },
|
|
337
|
+
},
|
|
338
|
+
}),
|
|
339
|
+
});
|
|
340
|
+
expect(results).toMatchInlineSnapshot(`Array []`);
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it('should report response objects when there are no properties', async () => {
|
|
344
|
+
const document = parseYamlToDocument(outdent`
|
|
345
|
+
openapi: 3.0.3
|
|
346
|
+
info:
|
|
347
|
+
version: 3.0.0
|
|
348
|
+
paths:
|
|
349
|
+
/store/subscribe:
|
|
350
|
+
post:
|
|
351
|
+
responses:
|
|
352
|
+
200:
|
|
353
|
+
content:
|
|
354
|
+
application/json:
|
|
355
|
+
schema:
|
|
356
|
+
type: object
|
|
357
|
+
|
|
358
|
+
`);
|
|
359
|
+
const results = await lintDocument({
|
|
360
|
+
externalRefResolver: new BaseResolver(),
|
|
361
|
+
document,
|
|
362
|
+
config: await makeConfig({
|
|
363
|
+
'response-contains-property': {
|
|
364
|
+
severity: 'error',
|
|
365
|
+
names: { '2xx': ['id'] },
|
|
366
|
+
},
|
|
367
|
+
}),
|
|
368
|
+
});
|
|
369
|
+
expect(results).toMatchInlineSnapshot(`
|
|
370
|
+
Array [
|
|
371
|
+
Object {
|
|
372
|
+
"location": Array [
|
|
373
|
+
Object {
|
|
374
|
+
"pointer": "#/paths/~1store~1subscribe/post/responses/200/content/application~1json/schema/properties",
|
|
375
|
+
"reportOnKey": true,
|
|
376
|
+
"source": Source {
|
|
377
|
+
"absoluteRef": "",
|
|
378
|
+
"body": "openapi: 3.0.3
|
|
379
|
+
info:
|
|
380
|
+
version: 3.0.0
|
|
381
|
+
paths:
|
|
382
|
+
/store/subscribe:
|
|
383
|
+
post:
|
|
384
|
+
responses:
|
|
385
|
+
200:
|
|
386
|
+
content:
|
|
387
|
+
application/json:
|
|
388
|
+
schema:
|
|
389
|
+
type: object
|
|
390
|
+
",
|
|
391
|
+
"mimeType": undefined,
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
],
|
|
395
|
+
"message": "Response object must contain a top-level \\"id\\" property.",
|
|
396
|
+
"ruleId": "response-contains-property",
|
|
397
|
+
"severity": "error",
|
|
398
|
+
"suggest": Array [],
|
|
399
|
+
},
|
|
400
|
+
]
|
|
401
|
+
`);
|
|
402
|
+
});
|
|
403
|
+
});
|
package/src/rules/oas3/index.ts
CHANGED
|
@@ -45,6 +45,9 @@ import { PathSegmentPlural } from '../common/path-segment-plural';
|
|
|
45
45
|
import { PathExcludesPatterns } from '../common/path-excludes-patterns';
|
|
46
46
|
import { NoInvalidSchemaExamples } from '../common/no-invalid-schema-examples';
|
|
47
47
|
import { NoInvalidParameterExamples } from '../common/no-invalid-parameter-examples';
|
|
48
|
+
import { ResponseContainsHeader } from '../common/response-contains-header';
|
|
49
|
+
import { ResponseContainsProperty } from './response-contains-property';
|
|
50
|
+
import { ScalarPropertyMissingExample } from '../common/scalar-property-missing-example';
|
|
48
51
|
|
|
49
52
|
export const rules = {
|
|
50
53
|
spec: OasSpec,
|
|
@@ -94,6 +97,9 @@ export const rules = {
|
|
|
94
97
|
'path-segment-plural': PathSegmentPlural,
|
|
95
98
|
'no-invalid-schema-examples': NoInvalidSchemaExamples,
|
|
96
99
|
'no-invalid-parameter-examples': NoInvalidParameterExamples,
|
|
100
|
+
'response-contains-header': ResponseContainsHeader,
|
|
101
|
+
'response-contains-property': ResponseContainsProperty,
|
|
102
|
+
'scalar-property-missing-example': ScalarPropertyMissingExample,
|
|
97
103
|
} as Oas3RuleSet;
|
|
98
104
|
|
|
99
105
|
export const preprocessors = {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Oas3Rule } from '../../visitors';
|
|
2
|
+
import { UserContext } from '../../walk';
|
|
3
|
+
import { getMatchingStatusCodeRange } from '../../utils';
|
|
4
|
+
|
|
5
|
+
export const ResponseContainsProperty: Oas3Rule = (options) => {
|
|
6
|
+
const names: Record<string, string[]> = options.names || {};
|
|
7
|
+
let key: string | number;
|
|
8
|
+
return {
|
|
9
|
+
Operation: {
|
|
10
|
+
Response: {
|
|
11
|
+
skip: (_response, key) => {
|
|
12
|
+
return `${key}` === '204';
|
|
13
|
+
},
|
|
14
|
+
enter: (_response, ctx: UserContext) => {
|
|
15
|
+
key = ctx.key;
|
|
16
|
+
},
|
|
17
|
+
MediaType: {
|
|
18
|
+
Schema(schema, { report, location }) {
|
|
19
|
+
if (schema.type !== 'object') return;
|
|
20
|
+
const expectedProperties =
|
|
21
|
+
names[key] ||
|
|
22
|
+
names[getMatchingStatusCodeRange(key)] ||
|
|
23
|
+
names[getMatchingStatusCodeRange(key).toLowerCase()] ||
|
|
24
|
+
[];
|
|
25
|
+
for (const expectedProperty of expectedProperties) {
|
|
26
|
+
if (!schema.properties?.[expectedProperty]) {
|
|
27
|
+
report({
|
|
28
|
+
message: `Response object must contain a top-level "${expectedProperty}" property.`,
|
|
29
|
+
location: location.child('properties').key(),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
};
|
package/src/types/oas3.ts
CHANGED
|
@@ -275,14 +275,14 @@ const Schema: NodeType = {
|
|
|
275
275
|
minimum: { type: 'number' },
|
|
276
276
|
exclusiveMaximum: { type: 'boolean' },
|
|
277
277
|
exclusiveMinimum: { type: 'boolean' },
|
|
278
|
-
maxLength: { type: '
|
|
279
|
-
minLength: { type: '
|
|
278
|
+
maxLength: { type: 'integer', minimum: 0 },
|
|
279
|
+
minLength: { type: 'integer', minimum: 0 },
|
|
280
280
|
pattern: { type: 'string' },
|
|
281
|
-
maxItems: { type: '
|
|
282
|
-
minItems: { type: '
|
|
281
|
+
maxItems: { type: 'integer', minimum: 0 },
|
|
282
|
+
minItems: { type: 'integer', minimum: 0 },
|
|
283
283
|
uniqueItems: { type: 'boolean' },
|
|
284
|
-
maxProperties: { type: '
|
|
285
|
-
minProperties: { type: '
|
|
284
|
+
maxProperties: { type: 'integer', minimum: 0 },
|
|
285
|
+
minProperties: { type: 'integer', minimum: 0 },
|
|
286
286
|
required: { type: 'array', items: { type: 'string' } },
|
|
287
287
|
enum: { type: 'array' },
|
|
288
288
|
type: {
|
|
@@ -300,6 +300,15 @@ const Schema: NodeType = {
|
|
|
300
300
|
return 'Schema';
|
|
301
301
|
}
|
|
302
302
|
},
|
|
303
|
+
additionalItems: (value: any) => {
|
|
304
|
+
if (typeof value === 'boolean') {
|
|
305
|
+
return { type: 'boolean' };
|
|
306
|
+
} else if (Array.isArray(value)) {
|
|
307
|
+
return listOf('Schema');
|
|
308
|
+
} else {
|
|
309
|
+
return 'Schema';
|
|
310
|
+
}
|
|
311
|
+
},
|
|
303
312
|
additionalProperties: (value: any) => {
|
|
304
313
|
if (typeof value === 'boolean') {
|
|
305
314
|
return { type: 'boolean' };
|
package/src/types/oas3_1.ts
CHANGED
|
@@ -90,19 +90,19 @@ const Schema: NodeType = {
|
|
|
90
90
|
discriminator: 'Discriminator',
|
|
91
91
|
myArbitraryKeyword: { type: 'boolean' },
|
|
92
92
|
title: { type: 'string' },
|
|
93
|
-
multipleOf: { type: 'number' },
|
|
93
|
+
multipleOf: { type: 'number', minimum: 0 },
|
|
94
94
|
maximum: { type: 'number' },
|
|
95
95
|
minimum: { type: 'number' },
|
|
96
96
|
exclusiveMaximum: { type: 'number' },
|
|
97
97
|
exclusiveMinimum: { type: 'number' },
|
|
98
|
-
maxLength: { type: '
|
|
99
|
-
minLength: { type: '
|
|
98
|
+
maxLength: { type: 'integer', minimum: 0 },
|
|
99
|
+
minLength: { type: 'integer', minimum: 0 },
|
|
100
100
|
pattern: { type: 'string' },
|
|
101
|
-
maxItems: { type: '
|
|
102
|
-
minItems: { type: '
|
|
101
|
+
maxItems: { type: 'integer', minimum: 0 },
|
|
102
|
+
minItems: { type: 'integer', minimum: 0 },
|
|
103
103
|
uniqueItems: { type: 'boolean' },
|
|
104
|
-
maxProperties: { type: '
|
|
105
|
-
minProperties: { type: '
|
|
104
|
+
maxProperties: { type: 'integer', minimum: 0 },
|
|
105
|
+
minProperties: { type: 'integer', minimum: 0 },
|
|
106
106
|
required: { type: 'array', items: { type: 'string' } },
|
|
107
107
|
enum: { type: 'array' },
|
|
108
108
|
type: (value: any) => {
|
|
@@ -127,6 +127,8 @@ const Schema: NodeType = {
|
|
|
127
127
|
dependentSchemas: listOf('Schema'),
|
|
128
128
|
prefixItems: listOf('Schema'),
|
|
129
129
|
contains: 'Schema',
|
|
130
|
+
minContains: { type: 'integer', minimum: 0 },
|
|
131
|
+
maxContains: { type: 'integer', minimum: 0 },
|
|
130
132
|
patternProperties: { type: 'object' },
|
|
131
133
|
propertyNames: 'Schema',
|
|
132
134
|
unevaluatedItems: 'Schema',
|
|
@@ -392,6 +392,7 @@ const LinksConfig: NodeType = {
|
|
|
392
392
|
color: { type: 'string' },
|
|
393
393
|
hover: { type: 'string' },
|
|
394
394
|
textDecoration: { type: 'string' },
|
|
395
|
+
hoverTextDecoration: { type: 'string' },
|
|
395
396
|
visited: { type: 'string' },
|
|
396
397
|
},
|
|
397
398
|
};
|
|
@@ -513,6 +514,9 @@ const ConfigReferenceDocs: NodeType = {
|
|
|
513
514
|
disableSidebar: { type: 'boolean' },
|
|
514
515
|
downloadDefinitionUrl: { type: 'string' },
|
|
515
516
|
expandDefaultServerVariables: { type: 'boolean' },
|
|
517
|
+
enumSkipQuotes: { type: 'boolean' },
|
|
518
|
+
expandDefaultRequest: { type: 'boolean'},
|
|
519
|
+
expandDefaultResponse: { type: 'boolean'},
|
|
516
520
|
expandResponses: { type: 'string' },
|
|
517
521
|
expandSingleSchemaField: { type: 'boolean' },
|
|
518
522
|
generateCodeSamples: 'GenerateCodeSamples',
|
|
@@ -527,6 +531,8 @@ const ConfigReferenceDocs: NodeType = {
|
|
|
527
531
|
hideSchemaTitles: { type: 'boolean' },
|
|
528
532
|
hideSingleRequestSampleTab: { type: 'boolean' },
|
|
529
533
|
hideTryItPanel: { type: 'boolean' },
|
|
534
|
+
hideFab: { type: 'boolean' },
|
|
535
|
+
hideOneOfDescription: { type: 'boolean'},
|
|
530
536
|
htmlTemplate: { type: 'string' },
|
|
531
537
|
jsonSampleExpandLevel: { type: 'string' },
|
|
532
538
|
labels: 'ConfigLabels',
|
|
@@ -547,6 +553,8 @@ const ConfigReferenceDocs: NodeType = {
|
|
|
547
553
|
samplesTabsMaxCount: { type: 'number' },
|
|
548
554
|
schemaExpansionLevel: { type: 'string' },
|
|
549
555
|
schemaDefinitionsTagName: { type: 'string' },
|
|
556
|
+
minCharacterLengthToInitSearch: { type: 'number' },
|
|
557
|
+
maxResponseHeadersToShowInTryIt: {type: 'number'},
|
|
550
558
|
scrollYOffset: { type: 'string' },
|
|
551
559
|
searchAutoExpand: { type: 'boolean' },
|
|
552
560
|
searchFieldLevelBoost: { type: 'number' },
|
|
@@ -558,6 +566,8 @@ const ConfigReferenceDocs: NodeType = {
|
|
|
558
566
|
showExtensions: { type: 'boolean' },
|
|
559
567
|
showNextButton: { type: 'boolean' },
|
|
560
568
|
showRightPanelToggle: { type: 'boolean' },
|
|
569
|
+
showWebhookVerb: { type: 'boolean' },
|
|
570
|
+
showObjectSchemaExamples: { type: 'boolean' },
|
|
561
571
|
sidebarLinks: 'ConfigSidebarLinks',
|
|
562
572
|
sideNavStyle: { type: 'string' },
|
|
563
573
|
simpleOneOfTypeLabel: { type: 'boolean' },
|
package/src/typings/openapi.ts
CHANGED
package/src/utils.ts
CHANGED