Can't resolve remote $ref with query parameter
vernondegoede opened this issue · 3 comments
Describe the bug
It seems that any remote $ref
that includes a query parameter cannot be resolved correctly.
To Reproduce
Steps to reproduce the behavior:
- Clone this repo: https://github.com/vernondegoede/repo2-with-specs
- Run the command below to see that without query params it works perfectly fine.
make reproduce-working
- Run the command below to see it failing whenever there's a query parameter in the URL.
make reproduce-broken
You will now see the following error:
╰─$ make reproduce-broken
npx --yes @redocly/cli@latest bundle routes-not-working.yaml --output routes-not-working.json --ext=json
(node:36505) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
bundling routes-not-working.yaml...
[1] routes-not-working.yaml:10:5 at #/paths/~1api~1invoices
Can't resolve $ref
8 | paths:
9 | /api/invoices:
10 | $ref: 'https://raw.githubusercontent.com/vernondegoede/repo1/4deae7ddf2dad69ab31c2770c9dab51239d445a2/test.yaml?test=bl...<9 chars>
Error was generated by the bundler rule.
❌ Errors encountered while bundling routes-not-working.yaml: bundle not created (use --force to ignore errors).
make: *** [reproduce-broken] Error 1
Our use case is the following: we want to link to URLs in other Gitlab repos and link to specific refs:
$ref: 'https://example.com/api/v4/projects/apps%2Fblah/repository/files/apps%2Fblah%2Fdocs%2Finternal-api%2Eyaml/raw?ref=2f83009de0316335f9b32c02b8c22a1eaaa50f9fb#/paths/~1api~1invoices'
What's interesting is that the URL itself actually does seem to resolve. It's not possible to show this in this repo, but if I use a query parameter that will return in a 404 it will actually tell me that the file was not found. However, it now fails to find the actual ref somehow. I'm not sure why :-)
Expected behavior
I would expect the full URL to resolve and find the correct ref.
Logs
See above
OpenAPI description
See https://github.com/vernondegoede/repo2-with-specs/blob/main/routes-not-working.yaml
And the downstream $ref
: https://github.com/vernondegoede/repo1/blob/4deae7ddf2dad69ab31c2770c9dab51239d445a2/test.yaml
Redocly Version(s)
Latest
Node.js
Version(s)
v21.4.0
Additional context
N/A
I confirm this is a bug. Thanks for creating the issue!
Do you have any pointers where to look to fix this myself? :-) Happy to contribute if time allows.
That would be amazing!
You can start with the ref-utils
file, specifically here, where the ref gets split into the url and the pointer. Then, the link itself gets loaded inside the BaseResolver class.
I hope you'll also find our contributing guide helpful.
Feel free to reach out in case you have any further questions.
Cheers!