Skip to content

Commit b398283

Browse files
committed
remove undefined properties instead of setting the {not: {}} type; do not add $descriptions for empty properties; slightly improve $ref type
1 parent 97d19cd commit b398283

File tree

10 files changed

+80
-218
lines changed

10 files changed

+80
-218
lines changed

applications/__tests__/__snapshots__/e2e-bundle.test.js.snap

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,6 @@ paths:
842842
schema:
843843
type: object
844844
properties:
845-
id:
846-
not: {}
847845
name:
848846
type: object
849847
properties:
@@ -979,17 +977,20 @@ paths:
979977
$and:
980978
- array: string
981979
- array: number
980+
examples:
981+
Correct:
982+
value: {}
983+
Incorrect:
984+
value:
985+
unexpected: fails
982986
schema:
983987
type: object
984-
properties:
985-
WrongAndFormat:
986-
not: {}
987-
Empty:
988-
not: {}
989-
ImpossibleArraysCombination:
990-
not: {}
988+
properties: {}
991989
required: []
992990
additionalProperties: false
991+
application/undefined+json:
992+
x-type:
993+
$and: []
993994
components:
994995
x-types:
995996
CorrectAnd:

applications/__tests__/__snapshots__/e2e-lint.test.js.snap

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ ERROR! Expected an array but got:
226226
{ foo: 'boolean', bar: 'number' }
227227
ERROR! Cannot merge empty lists.
228228
ERROR! Cannot merge 'array' types.
229+
ERROR! Cannot merge empty lists.
229230
[1] applications/resources/openapi-and.yaml:16:17 at #/paths/~1test/get/responses/200/content/application~1json/example
230231
231232
Example value must conform to the schema: must have required property 'bar'.
@@ -236,8 +237,8 @@ Example value must conform to the schema: must have required property 'bar'.
236237
| ^^^^^^^^^^^
237238
17 | wrong: not-expected!
238239
| ^^^^^^^^^^^^^^^^^^^^
239-
18 |
240-
19 | application/problems+json:
240+
18 | application/problems+json:
241+
19 | x-type:
241242
242243
referenced from applications/resources/openapi-and.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
243244
@@ -252,8 +253,8 @@ Example value must conform to the schema: must NOT have additional properties \`
252253
16 | foo: wrong!
253254
17 | wrong: not-expected!
254255
| ^^^^^
255-
18 |
256-
19 | application/problems+json:
256+
18 | application/problems+json:
257+
19 | x-type:
257258
258259
referenced from applications/resources/openapi-and.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
259260
@@ -264,37 +265,53 @@ Error was generated by the no-invalid-media-type-examples rule.
264265
265266
Example value must conform to the schema: \`foo\` property type must be boolean.
266267
267-
14 | $ref: '#/components/x-types/CorrectAnd'
268-
15 | example:
269-
16 | foo: wrong!
270-
| ^^^^^^
271-
17 | wrong: not-expected!
272-
18 |
268+
14 | $ref: '#/components/x-types/CorrectAnd'
269+
15 | example:
270+
16 | foo: wrong!
271+
| ^^^^^^
272+
17 | wrong: not-expected!
273+
18 | application/problems+json:
273274
274275
referenced from applications/resources/openapi-and.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
275276
276277
Error was generated by the no-invalid-media-type-examples rule.
277278
278279
279-
[4] applications/resources/openapi-and.yaml:23:21 at #/paths/~1test/get/responses/200/content/application~1problems+json/x-type/WrongAndFormat/$and
280+
[4] applications/resources/openapi-and.yaml:22:21 at #/paths/~1test/get/responses/200/content/application~1problems+json/x-type/WrongAndFormat/$and
280281
281282
Expected type \`XTypeList\` (array) but got \`object\`
282283
283-
21 | WrongAndFormat:
284-
22 | $and: # Expected an array!
285-
23 | foo: boolean
284+
20 | WrongAndFormat:
285+
21 | $and: # Expected an array!
286+
22 | foo: boolean
286287
| ^^^^^^^^^^^^
287-
24 | bar: number
288+
23 | bar: number
288289
| ^^^^^^^^^^^
289-
25 | Empty: # Cannot merge empty lists!
290-
26 | $and: []
290+
24 | Empty: # Cannot merge empty lists!
291+
25 | $and: []
291292
292293
Error was generated by the spec rule.
293294
294295
296+
[5] applications/resources/openapi-and.yaml:35:21 at #/paths/~1test/get/responses/200/content/application~1problems+json/examples/Incorrect/value/unexpected
297+
298+
Example value must conform to the schema: must NOT have additional properties \`unexpected\`.
299+
300+
33 | Incorrect:
301+
34 | value:
302+
35 | unexpected: fails
303+
| ^^^^^^^^^^
304+
36 | application/undefined+json:
305+
37 | x-type:
306+
307+
referenced from applications/resources/openapi-and.yaml:19:15 at #/paths/~1test/get/responses/200/content/application~1problems+json
308+
309+
Error was generated by the no-invalid-media-type-examples rule.
310+
311+
295312
applications/resources/openapi-and.yaml: validated in <test>ms
296313
297-
❌ Validation failed with 4 errors.
314+
❌ Validation failed with 5 errors.
298315
run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
299316
300317
"
@@ -679,14 +696,14 @@ You have 1 warning.
679696
680697
exports[`lint > openapi with writeOnly and readOnly fields 1`] = `
681698
"validating applications/resources/openapi-with-writeonly-and-readonly.yaml...
682-
[1] applications/resources/openapi-with-writeonly-and-readonly.yaml:21:23 at #/paths/~1test/get/requestBody/content/application~1json/examples/Incorrect/value/id
699+
[1] applications/resources/openapi-with-writeonly-and-readonly.yaml:21:19 at #/paths/~1test/get/requestBody/content/application~1json/examples/Incorrect/value/id
683700
684-
Example value must conform to the schema: \`id\` property must NOT be valid.
701+
Example value must conform to the schema: must NOT have additional properties \`id\`.
685702
686703
19 | Incorrect:
687704
20 | value:
688705
21 | id: uuid-like-id # not expected in response
689-
| ^^^^^^^^^^^^
706+
| ^^
690707
22 | name: First Last # must be an object
691708
23 | responses:
692709

applications/__tests__/adapter.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('adapter', () => {
1818
})
1919

2020
test('`undefined` -> `never`', () => {
21-
expect(translateXTypeToSchema('undefined')).toEqual({not: {}})
21+
expect(translateXTypeToSchema('undefined')).toEqual(undefined)
2222
})
2323

2424
test('OR', () => {
@@ -32,9 +32,7 @@ describe('adapter', () => {
3232
expect(translateXTypeToSchema(['string', 'undefined'])).toEqual({
3333
type: 'string',
3434
})
35-
expect(translateXTypeToSchema(['undefined'])).toEqual({
36-
not: {},
37-
})
35+
expect(translateXTypeToSchema(['undefined'])).toEqual(undefined)
3836
expect(
3937
translateXTypeToSchema({
4038
Required: ['foo', 'number'],

0 commit comments

Comments
 (0)