redocly-cli icon indicating copy to clipboard operation
redocly-cli copied to clipboard

Can't resolve remote $ref with query parameter

Open vernondegoede opened this issue 3 months ago • 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:

  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 avatar May 03 '24 15:05 vernondegoede