-
Notifications
You must be signed in to change notification settings - Fork 197
fix: do not resolve $ref in examples.value #2392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ac5c0cb
fix: do not resolve $ref in examples.value
vadyvas 3ac2881
chore: remove console.log
vadyvas 21a19af
chore: update changeset
vadyvas d50276d
fix: oas example types and tests
vadyvas ef63eaf
fix: update Example type definitions across OAS specs
vadyvas d16bd72
fix: update oas3.2 types
vadyvas abc1cf7
fix: improve docs, changeset and tests
vadyvas 2374fda
chore: update e2e test
vadyvas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@redocly/openapi-core": patch | ||
| "@redocly/cli": patch | ||
| --- | ||
|
|
||
| Fixed an issue where the content of `$ref`s inside example values was erroneously resolved during bundling and linting. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
229 changes: 229 additions & 0 deletions
229
packages/core/src/__tests__/bundle-examples-ref-resolution.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,229 @@ | ||
| import outdent from 'outdent'; | ||
| import * as path from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { bundleDocument } from '../bundle/bundle-document.js'; | ||
| import { parseYamlToDocument, yamlSerializer } from '../../__tests__/utils.js'; | ||
| import { createConfig } from '../config/index.js'; | ||
| import { BaseResolver } from '../resolve.js'; | ||
| import { AsyncApi3Types, Oas3Types } from '../index.js'; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| describe('Bundle Examples $ref Resolution', () => { | ||
| expect.addSnapshotSerializer(yamlSerializer); | ||
|
|
||
| describe('OpenAPI 3.0/3.1 Examples', () => { | ||
| it('should resolve $ref in Example field', async () => { | ||
| const testDocument = parseYamlToDocument( | ||
| outdent` | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Test API | ||
| version: 1.0.0 | ||
| paths: | ||
| /test: | ||
| get: | ||
| responses: | ||
| '200': | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| id: | ||
| type: integer | ||
| name: | ||
| type: string | ||
| example: | ||
| $ref: ${path.join(__dirname, 'fixtures/example-data.json')} | ||
| `, | ||
| '' | ||
| ); | ||
|
|
||
| const { bundle: result, problems } = await bundleDocument({ | ||
| document: testDocument, | ||
| externalRefResolver: new BaseResolver(), | ||
| config: await createConfig({}), | ||
| types: Oas3Types, | ||
| }); | ||
|
|
||
| expect(problems).toHaveLength(0); | ||
| expect(result.parsed).toMatchInlineSnapshot(` | ||
| openapi: 3.0.0 | ||
| info: | ||
| title: Test API | ||
| version: 1.0.0 | ||
| paths: | ||
| /test: | ||
| get: | ||
| responses: | ||
| '200': | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| id: | ||
| type: integer | ||
| name: | ||
| type: string | ||
| example: | ||
| id: 123 | ||
| name: Test User | ||
| components: {} | ||
| `); | ||
| }); | ||
|
|
||
| it('should NOT resolve $ref in Example.value field', async () => { | ||
| const testDocument = parseYamlToDocument( | ||
| outdent` | ||
| openapi: 3.1.0 | ||
| info: | ||
| title: Test API | ||
| version: 1.0.0 | ||
| paths: | ||
| /test: | ||
| get: | ||
| responses: | ||
| '200': | ||
| content: | ||
| application/json: | ||
| examples: | ||
| test-example: | ||
| value: | ||
| $ref: ./example-data.json | ||
| `, | ||
| '' | ||
| ); | ||
|
|
||
| const { bundle: result, problems } = await bundleDocument({ | ||
| document: testDocument, | ||
| externalRefResolver: new BaseResolver(), | ||
| config: await createConfig({}), | ||
| types: Oas3Types, | ||
| }); | ||
|
|
||
| expect(problems).toHaveLength(0); | ||
| expect(result.parsed).toMatchInlineSnapshot(` | ||
| openapi: 3.1.0 | ||
| info: | ||
| title: Test API | ||
| version: 1.0.0 | ||
| paths: | ||
| /test: | ||
| get: | ||
| responses: | ||
| '200': | ||
| content: | ||
| application/json: | ||
| examples: | ||
| test-example: | ||
| value: | ||
| $ref: ./example-data.json | ||
| components: {} | ||
| `); | ||
| }); | ||
| }); | ||
|
|
||
| describe('OpenAPI 3.2 Examples', () => { | ||
| it('should NOT resolve $ref in Example.dataValue field', async () => { | ||
| const testDocument = parseYamlToDocument( | ||
| outdent` | ||
| openapi: 3.2.0 | ||
| info: | ||
| title: Test API | ||
| version: 1.0.0 | ||
| paths: | ||
| /test: | ||
| get: | ||
| responses: | ||
| '200': | ||
| content: | ||
| application/json: | ||
| examples: | ||
| test-example: | ||
| dataValue: | ||
| $ref: ./example-data.json | ||
| `, | ||
| '' | ||
| ); | ||
|
|
||
| const { bundle: result, problems } = await bundleDocument({ | ||
| document: testDocument, | ||
| externalRefResolver: new BaseResolver(), | ||
| config: await createConfig({}), | ||
| types: Oas3Types, | ||
| }); | ||
|
|
||
| expect(problems).toHaveLength(0); | ||
| expect(result.parsed).toMatchInlineSnapshot(` | ||
| openapi: 3.2.0 | ||
| info: | ||
| title: Test API | ||
| version: 1.0.0 | ||
| paths: | ||
| /test: | ||
| get: | ||
| responses: | ||
| '200': | ||
| content: | ||
| application/json: | ||
| examples: | ||
| test-example: | ||
| dataValue: | ||
| $ref: ./example-data.json | ||
| components: {} | ||
| `); | ||
| }); | ||
| }); | ||
|
|
||
| describe('AsyncAPI 3.0 Examples', () => { | ||
| it('should NOT resolve $ref in Example.value field', async () => { | ||
| const testDocument = parseYamlToDocument( | ||
| outdent` | ||
| asyncapi: 3.0.0 | ||
| info: | ||
| title: Test AsyncAPI | ||
| version: 1.0.0 | ||
| operations: | ||
| sendUserSignedup: | ||
| action: send | ||
| messages: | ||
| - payload: | ||
| type: object | ||
| examples: | ||
| test-example: | ||
| value: | ||
| $ref: ./example-data.json | ||
| `, | ||
| '' | ||
| ); | ||
|
|
||
| const { bundle: result, problems } = await bundleDocument({ | ||
| document: testDocument, | ||
| externalRefResolver: new BaseResolver(), | ||
| config: await createConfig({}), | ||
| types: AsyncApi3Types, | ||
| }); | ||
|
|
||
| expect(problems).toHaveLength(0); | ||
| expect(result.parsed).toMatchInlineSnapshot(` | ||
| asyncapi: 3.0.0 | ||
| info: | ||
| title: Test AsyncAPI | ||
| version: 1.0.0 | ||
| operations: | ||
| sendUserSignedup: | ||
| action: send | ||
| messages: | ||
| - payload: | ||
| type: object | ||
| examples: | ||
| test-example: | ||
| value: | ||
| $ref: ./example-data.json | ||
| components: {} | ||
| `); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "id": 123, | ||
| "name": "Test User" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
tests/e2e/bundle/bundle-example-value-with-ref/openapi.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| openapi: 3.2.0 | ||
| info: | ||
| title: Test API | ||
| version: 1.0.0 | ||
| paths: | ||
| /test: | ||
| get: | ||
| responses: | ||
| '200': | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| $ref: | ||
| type: string | ||
| example: | ||
| $ref: example.json # should NOT be resolved | ||
| examples: | ||
| Test: | ||
| summary: Example with $ref in value (should NOT resolve) | ||
| value: | ||
| $ref: example.json # should NOT be resolved | ||
|
|
||
| TestDataValue: | ||
| summary: Example with $ref in dataValue (should NOT resolve) | ||
| dataValue: | ||
| $ref: example.json # should NOT be resolved |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apis: | ||
| main: | ||
| root: openapi.yaml | ||
|
|
||
| resolve: | ||
| doNotResolveExamples: true |
31 changes: 31 additions & 0 deletions
31
tests/e2e/bundle/bundle-example-value-with-ref/snapshot.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| openapi: 3.2.0 | ||
| info: | ||
| title: Test API | ||
| version: 1.0.0 | ||
| paths: | ||
| /test: | ||
| get: | ||
| responses: | ||
| '200': | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: object | ||
| properties: | ||
| $ref: | ||
| type: string | ||
| example: | ||
| $ref: example.json | ||
| examples: | ||
| Test: | ||
| summary: Example with $ref in value (should NOT resolve) | ||
| value: | ||
| $ref: example.json | ||
| TestDataValue: | ||
| summary: Example with $ref in dataValue (should NOT resolve) | ||
| dataValue: | ||
| $ref: example.json | ||
| components: {} | ||
|
|
||
| bundling openapi.yaml using configuration for api 'main'... | ||
| 📦 Created a bundle for openapi.yaml at stdout <test>ms. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It also affects the CLI behaviour, so please mention it here as well.