mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 04:21:09 +00:00
Treat dependentSchemas as a map not array. (#1641)
This commit is contained in:
7
.changeset/five-cougars-arrive.md
Normal file
7
.changeset/five-cougars-arrive.md
Normal file
@@ -0,0 +1,7 @@
|
||||
---
|
||||
"@redocly/openapi-core": patch
|
||||
"@redocly/cli": patch
|
||||
---
|
||||
|
||||
Fixed an issue in the OpenAPI `spec` rule where `dependentSchemas` was parsed as an array.
|
||||
It is now correctly parsed as a map.
|
||||
@@ -607,4 +607,51 @@ describe('Oas3.1 spec', () => {
|
||||
]
|
||||
`);
|
||||
});
|
||||
|
||||
it('should flag invalid dependentSchemas', async () => {
|
||||
const document = parseYamlToDocument(
|
||||
outdent`
|
||||
openapi: 3.1.0
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: Example.com
|
||||
description: info,
|
||||
license:
|
||||
name: Apache 2.0
|
||||
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
|
||||
components:
|
||||
schemas:
|
||||
withInvalidDependentSchemas:
|
||||
dependentSchemas:
|
||||
- invalid1
|
||||
- invalid2
|
||||
`,
|
||||
'foobar.yaml'
|
||||
);
|
||||
|
||||
const results = await lintDocument({
|
||||
externalRefResolver: new BaseResolver(),
|
||||
document,
|
||||
config: await makeConfig({ spec: 'error' }),
|
||||
});
|
||||
|
||||
expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
|
||||
[
|
||||
{
|
||||
"from": undefined,
|
||||
"location": [
|
||||
{
|
||||
"pointer": "#/components/schemas/withInvalidDependentSchemas/dependentSchemas",
|
||||
"reportOnKey": false,
|
||||
"source": "foobar.yaml",
|
||||
},
|
||||
],
|
||||
"message": "Expected type \`SchemaMap\` (object) but got \`array\`",
|
||||
"ruleId": "spec",
|
||||
"severity": "error",
|
||||
"suggest": [],
|
||||
},
|
||||
]
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -133,7 +133,7 @@ const Schema: NodeType = {
|
||||
if: 'Schema',
|
||||
then: 'Schema',
|
||||
else: 'Schema',
|
||||
dependentSchemas: listOf('Schema'),
|
||||
dependentSchemas: mapOf('Schema'),
|
||||
dependentRequired: 'DependentRequired',
|
||||
prefixItems: listOf('Schema'),
|
||||
contains: 'Schema',
|
||||
|
||||
Reference in New Issue
Block a user