Skip to content

Commit

Permalink
Treat dependentSchemas as a map not array. (#1641)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjones1 authored Jul 22, 2024
1 parent c3ed020 commit 373ad9d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/five-cougars-arrive.md
Original file line number Diff line number Diff line change
@@ -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.
47 changes: 47 additions & 0 deletions packages/core/src/rules/common/__tests__/spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
},
]
`);
});
});
2 changes: 1 addition & 1 deletion packages/core/src/types/oas3_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

1 comment on commit 373ad9d

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 77.31% 4577/5920
🟡 Branches 67.16% 2526/3761
🟡 Functions 70.72% 751/1062
🟡 Lines 77.57% 4310/5556

Test suite run success

751 tests passing in 105 suites.

Report generated by 🧪jest coverage report action from 373ad9d

Please sign in to comment.