fix: wrong discriminator mapping when bundling with derefernce
What/Why/How?
Fixed bundling with the --dereferenced option. Previously, references to external files were not substituted with references to components, causing them to become invalid.
For example, bundling this:
openapi: 3.1.0
info: {}
paths:
/test:
get:
responses:
default:
content:
application/json:
schema:
type: object
discriminator:
propertyName: discriminatedProp
mapping:
Foo: ./foo.yaml
Bar: ./bar.yaml
oneOf:
- $ref: ./foo.yaml
- $ref: ./bar.yaml
will lead to this (please notice the comments):
openapi: 3.1.0
info: {}
paths:
/test:
get:
responses:
default:
content:
application/json:
schema:
type: object
discriminator:
propertyName: discriminatedProp
mapping:
Foo: ./foo.yaml # <-- THIS REFERENCE IS NO LONGERE VALID
Bar: ./bar.yaml # <-- THIS REFERENCE IS NO LONGERE VALID
oneOf:
- type: object
properties: &ref_0
discriminatedProp:
type: string
foo:
type: string
- type: object
properties: &ref_1
discriminatedProp:
type: string
bar:
type: boolean
components:
schemas:
foo:
type: object
properties: *ref_0
bar:
type: object
properties: *ref_1
Reference
https://github.com/Redocly/redocly-cli/issues/1602
Testing
Screenshots (optional)
Check yourself
- [x] Code changed? - Tested with redoc/reference-docs/workflows (internal)
- [x] All new/updated code is covered with tests
- [ ] New package installed? - Tested in different environments (browser/node)
Security
- [x] Security impact of change has been considered
- [x] Code follows company security practices and guidelines
🦋 Changeset detected
Latest commit: ea2b4606520a97d407f605741924c83207f25b1b
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 2 packages
| Name | Type |
|---|---|
| @redocly/openapi-core | Patch |
| @redocly/cli | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
| Command | Mean [s] | Min [s] | Max [s] | Relative |
|---|---|---|---|---|
redocly lint packages/core/src/benchmark/benches/rebilly.yaml |
1.011 ± 0.020 | 0.986 | 1.062 | 1.00 |
redocly-next lint packages/core/src/benchmark/benches/rebilly.yaml |
1.018 ± 0.026 | 0.977 | 1.061 | 1.01 ± 0.03 |
Coverage report
St.:grey_question: |
Category | Percentage | Covered / Total |
|---|---|---|---|
| 🟡 | Statements | 78.57% | 4991/6352 |
| 🟡 | Branches | 67.24% | 2061/3065 |
| 🟡 | Functions | 72.98% | 824/1129 |
| 🟡 | Lines | 78.86% | 4709/5971 |
Test suite run success
809 tests passing in 121 suites.
Report generated by 🧪jest coverage report action from ea2b4606520a97d407f605741924c83207f25b1b