Treat dependentSchemas as a map not array. (#1641)

This commit is contained in:
Brad Jones
2024-07-22 04:07:48 -06:00
committed by GitHub
parent c3ed020bbd
commit 373ad9d668
3 changed files with 55 additions and 1 deletions

View 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.

View File

@@ -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": [],
},
]
`);
});
});

View File

@@ -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',