diff --git a/.changeset/five-cougars-arrive.md b/.changeset/five-cougars-arrive.md new file mode 100644 index 00000000..b5967e7e --- /dev/null +++ b/.changeset/five-cougars-arrive.md @@ -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. diff --git a/packages/core/src/rules/common/__tests__/spec.test.ts b/packages/core/src/rules/common/__tests__/spec.test.ts index 4c45e7f0..ee35721d 100644 --- a/packages/core/src/rules/common/__tests__/spec.test.ts +++ b/packages/core/src/rules/common/__tests__/spec.test.ts @@ -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": [], + }, + ] + `); + }); }); diff --git a/packages/core/src/types/oas3_1.ts b/packages/core/src/types/oas3_1.ts index 4b10e2e7..3eb5000a 100755 --- a/packages/core/src/types/oas3_1.ts +++ b/packages/core/src/types/oas3_1.ts @@ -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',