Skip to content

Commit

Permalink
add tests for $and and $description
Browse files Browse the repository at this point in the history
  • Loading branch information
tatomyr committed Oct 30, 2024
1 parent f67ce6e commit 5b90277
Show file tree
Hide file tree
Showing 6 changed files with 204 additions and 0 deletions.
61 changes: 61 additions & 0 deletions applications/__tests__/__snapshots__/e2e-bundle.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,67 @@ components: {}
"
`;

exports[`bundle > openapi with $and and $description 1`] = `
"openapi: 3.1.0
info:
title: Test
version: 1.0.0
paths:
/test:
get:
responses:
'200':
description: Test $and with $description.
content:
application/json:
x-type:
$and:
- az:
bukh: vidh
$descriptions:
bukh: Description of az.bukh
- az:
glagol: dobro
$descriptions:
glagol: Description of az.glagol
examples:
Correct:
value:
az:
bukh: vidh
glagol: dobro
Incorrect:
value:
az:
glagol: vidh
not-expected: fail
schema:
type: object
properties:
az:
type: object
properties:
bukh:
description: Description of az.bukh
type: string
enum:
- vidh
glagol:
description: Description of az.glagol
type: string
enum:
- dobro
required:
- bukh
- glagol
additionalProperties: false
required:
- az
additionalProperties: false
components: {}
"
`;

exports[`bundle > openapi with writeOnly and readOnly fields 1`] = `
"openapi: 3.1.0
info:
Expand Down
60 changes: 60 additions & 0 deletions applications/__tests__/__snapshots__/e2e-lint.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,66 @@ run \`redocly lint --generate-ignore-file\` to add all problems to the ignore fi
"
`;
exports[`lint > openapi with $and and $description 1`] = `
"validating applications/resources/openapi-and-with-descriptions.yaml...
[1] applications/resources/openapi-and-with-descriptions.yaml:35:23 at #/paths/~1test/get/responses/200/content/application~1json/examples/Incorrect/value/az
Example value must conform to the schema: \`az\` property must have required property 'bukh'.
33 | az:
34 | # missing bukh
35 | glagol: vidh
| ^^^^^^^^^^^^
36 | not-expected: fail
| ^^^^^^^^^^^^^^^^^^
37 |
referenced from applications/resources/openapi-and-with-descriptions.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
Error was generated by the no-invalid-media-type-examples rule.
[2] applications/resources/openapi-and-with-descriptions.yaml:36:23 at #/paths/~1test/get/responses/200/content/application~1json/examples/Incorrect/value/az/not-expected
Example value must conform to the schema: \`az\` property must NOT have additional properties \`not-expected\`.
34 | # missing bukh
35 | glagol: vidh
36 | not-expected: fail
| ^^^^^^^^^^^^
37 |
referenced from applications/resources/openapi-and-with-descriptions.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
Error was generated by the no-invalid-media-type-examples rule.
[3] applications/resources/openapi-and-with-descriptions.yaml:35:31 at #/paths/~1test/get/responses/200/content/application~1json/examples/Incorrect/value/az/glagol
Example value must conform to the schema: \`glagol\` property must be equal to one of the allowed values "dobro".
Did you mean: dobro ?
33 | az:
34 | # missing bukh
35 | glagol: vidh
| ^^^^
36 | not-expected: fail
37 |
referenced from applications/resources/openapi-and-with-descriptions.yaml:13:15 at #/paths/~1test/get/responses/200/content/application~1json
Error was generated by the no-invalid-media-type-examples rule.
applications/resources/openapi-and-with-descriptions.yaml: validated in <test>ms
❌ Validation failed with 3 errors.
run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
"
`;
exports[`lint > openapi with ORs (including nested and referenced) 1`] = `
"validating applications/resources/openapi-or.yaml...
[1] applications/resources/openapi-or.yaml:34:25 at #/paths/~1test/get/responses/200/content/application~1json/examples/Incorrect/value/Or
Expand Down
7 changes: 7 additions & 0 deletions applications/__tests__/e2e-bundle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,11 @@ describe('bundle', () => {
)
expect(stdout).toMatchSnapshot()
})

test('openapi with $and and $description', () => {
const {stdout} = runCommand(
'redocly bundle applications/resources/openapi-and-with-descriptions.yaml --config=applications/x-redocly.yaml'
)
expect(stdout).toMatchSnapshot()
})
})
7 changes: 7 additions & 0 deletions applications/__tests__/e2e-lint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,11 @@ describe('lint', () => {
)
expect(stripCWD(stderr)).toMatchSnapshot()
})

test('openapi with $and and $description', () => {
const {stderr} = runCommand(
'redocly lint applications/resources/openapi-and-with-descriptions.yaml --config=applications/x-redocly.yaml'
)
expect(stripCWD(stderr)).toMatchSnapshot()
})
})
33 changes: 33 additions & 0 deletions applications/__tests__/resolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,37 @@ describe('resolver', () => {
)
).toEqual({az: 'undefined', bukh: 'undefined'})
})

test('$description in combination with $and', () => {
expect(
resolveAndMerge(
{
$and: [
{
az: {
bukh: 'vidh',
$descriptions: {bukh: 'Description of az.bukh'},
},
},
{
az: {
glagol: 'dobro',
$descriptions: {glagol: 'Description of az.glagol'},
},
},
],
},
{}
)
).toEqual({
az: {
bukh: 'vidh',
glagol: 'dobro',
$descriptions: {
bukh: 'Description of az.bukh',
glagol: 'Description of az.glagol',
},
},
})
})
})
36 changes: 36 additions & 0 deletions applications/resources/openapi-and-with-descriptions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
openapi: 3.1.0
info:
title: Test
version: 1.0.0
paths:
/test:
get:
responses:
200:
description: Test $and with $description.
content:
application/json:
x-type:
$and:
- az:
bukh: vidh
$descriptions:
bukh: Description of az.bukh
- az:
glagol: dobro
$descriptions:
glagol: Description of az.glagol

examples:
Correct:
value:
az:
bukh: vidh
glagol: dobro

Incorrect:
value:
az:
# missing bukh
glagol: vidh
not-expected: fail

0 comments on commit 5b90277

Please sign in to comment.