fix: return on invalid ref pointer in remove-unused-components#2286
fix: return on invalid ref pointer in remove-unused-components#2286tatomyr merged 4 commits intoRedocly:mainfrom
Conversation
🦋 Changeset detectedLatest commit: e85fb7e The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
|
Thanks for contributing, @jooola! Could you add a unit or an E2E test to cover this case? |
76083e3 to
7cea153
Compare
|
@tatomyr Done, I hope the test are in the correct location. |
7cea153 to
3d5748b
Compare
34b2cbd to
1f3ab58
Compare
|
Or we will do it ourselves 🙂. Anyway, thank you for your contribution! |
When bundling a specification with --remove-unused-components, and
the specification has an invalid reference:
parameters:
- $ref: "../parameters.yml#/QueryProjectCreatedBefore.fail"
The process fails with:
$redocly bundle my-api --dereferenced --remove-unused-components --output dist/my-api.json
bundling src/my-api.yml using configuration for api 'my-api'...
Something went wrong when processing /work/openapi-spec/src/openapi.yml:
- Cannot read properties of undefined (reading 'split')
This change ensures that when the absolute pointer cannot be split into 2
parts, the visitor returns and let redocly report the "Can't resolve $ref" error.
Note that not all invalid references run into this bug, for example the following
reference will correctly be reported as an error:
parameters:
- $ref: "../parameters.yml#/QueryProjectCreatedBefore/fail"
7a29547 to
e85fb7e
Compare
|
Heads up, a recent setup was working on ran afoul of (possibly? probably?) this change. Got an error like: But in VSCode with redocly extension, it shows no errors and is valid: Had several such By commenting I suspect that the remove references somehow dropped the Anyway...submitted for consideration. CC @jooola |


What/Why/How?
When bundling a specification with
--remove-unused-components --dereferenced, and the specification has an invalid reference:The process fails with:
This change ensures that when the absolute pointer cannot be split into 2 parts, the visitor returns and let redocly report the
Can't resolve $referror.Note that not all invalid references run into this bug, for example the following reference will correctly be reported as an error:
Reference
Testing
Couldn't find a way to test this bug with the existing tests functions. To fully test this, 2 files are required, one referencing the other.
Check yourself
Security