Redocly / redocly-cli

⚒️ Redocly CLI makes OpenAPI easy. Lint/validate to any standard, generate beautiful docs, and more.
https://redocly.com/docs/cli/
MIT License
910 stars 139 forks source link

Bundle command does not replace self-referencing files. #1597

Open amine-mf opened 3 months ago

amine-mf commented 3 months ago

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.

tatomyr commented 3 months ago

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

amine-mf commented 3 months ago

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.

tatomyr commented 3 months ago

Yes, I think that makes sense.