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

Bundle command does not replace self-referencing files.

Open amine-mf opened this issue 1 year ago • 3 comments

Describe the bug When a file references itself, the references are not substituted with local refs.

To Reproduce Steps to reproduce the behavior:

  1. Given an empty config
  2. And this OpenAPI file(s) test-api.json
  3. Run this command with these arguments... redocly bundle test-api.json -o test-api-bundled.json
  4. Notice that the bundled OpenAPI still has an "external" format reference: "$ref": "test-api.json#/parameters/myParam"

Expected behavior

"$ref": "test-api.json#/parameters/myParam" should be replaced by "$ref": "#/parameters/myParam".

Logs

OpenAPI description Faced with Microsoft-Azure swagger specifications but for simplicity, linked a minimal example to showcase the issue. Haven't tested yet with OpenAPI V3, but expected the same behavior.

Redocly Version(s) 1.16.0

Node.js Version(s) 18.18.2

Additional context Clearly, the Swagger could be written differently and also, we could patch it, but still, after a bundle, if successful, you would expected no more external reference format in any reference. By the way, issue was noticed first when using @redocly/openapi-core but reproduced with the CLI.

amine-mf avatar Jun 21 '24 14:06 amine-mf

Thanks for reporting! BTW, does dereferenced bundling work around your issue?

tatomyr avatar Jun 21 '24 15:06 tatomyr

Thanks for the quick reply. --dereferenced does workaround the issue, but still not the best option as some of the APIs we handle may contain "cycles", we usually dereference "lazily" to avoid infinite loops. Also the size of the API might get too bigger.

amine-mf avatar Jun 21 '24 16:06 amine-mf

Yes, I think that makes sense.

tatomyr avatar Jun 21 '24 17:06 tatomyr