Skip to content

Commit

Permalink
remove undefined properties instead of setting the {not: {}} type; do…
Browse files Browse the repository at this point in the history
… not add $descriptions for empty properties; slightly improve $ref type
  • Loading branch information
tatomyr committed Nov 21, 2024
1 parent 97d19cd commit 22a0abb
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 219 deletions.
19 changes: 10 additions & 9 deletions applications/__tests__/__snapshots__/e2e-bundle.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,6 @@ paths:
schema:
type: object
properties:
id:
not: {}
name:
type: object
properties:
Expand Down Expand Up @@ -979,17 +977,20 @@ paths:
$and:
- array: string
- array: number
examples:
Correct:
value: {}
Incorrect:
value:
unexpected: fails
schema:
type: object
properties:
WrongAndFormat:
not: {}
Empty:
not: {}
ImpossibleArraysCombination:
not: {}
properties: {}
required: []
additionalProperties: false
application/undefined+json:
x-type:
$and: []
components:
x-types:
CorrectAnd:
Expand Down
59 changes: 38 additions & 21 deletions applications/__tests__/__snapshots__/e2e-lint.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ ERROR! Expected an array but got:
{ foo: 'boolean', bar: 'number' }
ERROR! Cannot merge empty lists.
ERROR! Cannot merge 'array' types.
ERROR! Cannot merge empty lists.
[1] applications/resources/openapi-and.yaml:16:17 at #/paths/~1test/get/responses/200/content/application~1json/example
Example value must conform to the schema: must have required property 'bar'.
Expand All @@ -236,8 +237,8 @@ Example value must conform to the schema: must have required property 'bar'.
| ^^^^^^^^^^^
17 | wrong: not-expected!
| ^^^^^^^^^^^^^^^^^^^^
18 |
19 | application/problems+json:
18 | application/problems+json:
19 | x-type:
referenced from applications/resources/openapi-and.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
Expand All @@ -252,8 +253,8 @@ Example value must conform to the schema: must NOT have additional properties \`
16 | foo: wrong!
17 | wrong: not-expected!
| ^^^^^
18 |
19 | application/problems+json:
18 | application/problems+json:
19 | x-type:
referenced from applications/resources/openapi-and.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
Expand All @@ -264,37 +265,53 @@ Error was generated by the no-invalid-media-type-examples rule.
Example value must conform to the schema: \`foo\` property type must be boolean.
14 | $ref: '#/components/x-types/CorrectAnd'
15 | example:
16 | foo: wrong!
| ^^^^^^
17 | wrong: not-expected!
18 |
14 | $ref: '#/components/x-types/CorrectAnd'
15 | example:
16 | foo: wrong!
| ^^^^^^
17 | wrong: not-expected!
18 | application/problems+json:
referenced from applications/resources/openapi-and.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
Error was generated by the no-invalid-media-type-examples rule.
[4] applications/resources/openapi-and.yaml:23:21 at #/paths/~1test/get/responses/200/content/application~1problems+json/x-type/WrongAndFormat/$and
[4] applications/resources/openapi-and.yaml:22:21 at #/paths/~1test/get/responses/200/content/application~1problems+json/x-type/WrongAndFormat/$and
Expected type \`XTypeList\` (array) but got \`object\`
21 | WrongAndFormat:
22 | $and: # Expected an array!
23 | foo: boolean
20 | WrongAndFormat:
21 | $and: # Expected an array!
22 | foo: boolean
| ^^^^^^^^^^^^
24 | bar: number
23 | bar: number
| ^^^^^^^^^^^
25 | Empty: # Cannot merge empty lists!
26 | $and: []
24 | Empty: # Cannot merge empty lists!
25 | $and: []
Error was generated by the spec rule.
[5] applications/resources/openapi-and.yaml:35:21 at #/paths/~1test/get/responses/200/content/application~1problems+json/examples/Incorrect/value/unexpected
Example value must conform to the schema: must NOT have additional properties \`unexpected\`.
33 | Incorrect:
34 | value:
35 | unexpected: fails
| ^^^^^^^^^^
36 | application/undefined+json:
37 | x-type:
referenced from applications/resources/openapi-and.yaml:19:15 at #/paths/~1test/get/responses/200/content/application~1problems+json
Error was generated by the no-invalid-media-type-examples rule.
applications/resources/openapi-and.yaml: validated in <test>ms
❌ Validation failed with 4 errors.
❌ Validation failed with 5 errors.
run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
"
Expand Down Expand Up @@ -679,14 +696,14 @@ You have 1 warning.
exports[`lint > openapi with writeOnly and readOnly fields 1`] = `
"validating applications/resources/openapi-with-writeonly-and-readonly.yaml...
[1] applications/resources/openapi-with-writeonly-and-readonly.yaml:21:23 at #/paths/~1test/get/requestBody/content/application~1json/examples/Incorrect/value/id
[1] applications/resources/openapi-with-writeonly-and-readonly.yaml:21:19 at #/paths/~1test/get/requestBody/content/application~1json/examples/Incorrect/value/id
Example value must conform to the schema: \`id\` property must NOT be valid.
Example value must conform to the schema: must NOT have additional properties \`id\`.
19 | Incorrect:
20 | value:
21 | id: uuid-like-id # not expected in response
| ^^^^^^^^^^^^
| ^^
22 | name: First Last # must be an object
23 | responses:
Expand Down
6 changes: 2 additions & 4 deletions applications/__tests__/adapter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('adapter', () => {
})

test('`undefined` -> `never`', () => {
expect(translateXTypeToSchema('undefined')).toEqual({not: {}})
expect(translateXTypeToSchema('undefined')).toEqual(undefined)
})

test('OR', () => {
Expand All @@ -32,9 +32,7 @@ describe('adapter', () => {
expect(translateXTypeToSchema(['string', 'undefined'])).toEqual({
type: 'string',
})
expect(translateXTypeToSchema(['undefined'])).toEqual({
not: {},
})
expect(translateXTypeToSchema(['undefined'])).toEqual(undefined)
expect(
translateXTypeToSchema({
Required: ['foo', 'number'],
Expand Down
Loading

0 comments on commit 22a0abb

Please sign in to comment.