Skip to content
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

Can't resolve remote $ref with query parameter #1545

Open
vernondegoede opened this issue May 3, 2024 · 3 comments
Open

Can't resolve remote $ref with query parameter #1545

vernondegoede opened this issue May 3, 2024 · 3 comments
Labels
p3 Type: Bug Something isn't working

Comments

@vernondegoede
Copy link

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:

  1. Clone this repo: https://github.com/vernondegoede/repo2-with-specs
  2. Run the command below to see that without query params it works perfectly fine.
make reproduce-working
  1. 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

@vernondegoede vernondegoede added the Type: Bug Something isn't working label May 3, 2024
@tatomyr
Copy link
Contributor

tatomyr commented May 3, 2024

I confirm this is a bug. Thanks for creating the issue!

@tatomyr tatomyr added the p3 label May 3, 2024
@vernondegoede
Copy link
Author

Do you have any pointers where to look to fix this myself? :-) Happy to contribute if time allows.

@tatomyr
Copy link
Contributor

tatomyr commented May 3, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3 Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants