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
898 stars 137 forks source link

Self-referencing circular pointer #1622

Open amine-mf opened 1 month ago

amine-mf commented 1 month ago

Describe the bug

Let's consider you have an OpenAPI that contains a Self-referencing circular pointer. As of today, there is no way to "clean/preprocess" it before it is being resolved in the bundler.

I tried providing a custom implementation of externalRefResolver and using preProcessors. The first obviously can't fix the problem, from its name, it is meant for externalRefs. The latter, is called too late in the chain, it is not being applied by the resolver visitor.

In my case, I have many APIs to process and I'm looking for a clean way to do it instead of hardcoding replaces all over the place to fix the input APIs (Which are vendors provided). Is there a way to get around this using Redocly that I don't know of? What options can you offer?

To Reproduce Steps to reproduce the behavior:

The following component throws Self-referencing circular pointer which I makes sense, but it would be good to be able to fix APIs "on the fly".

components:
  schemas:
    SomeComponent:
      $ref: "#/components/schemas/SomeComponent"

Expected behavior

A way to avoid the error, using a "middleware" to apply common fixes to APIs.

Logs

OpenAPI description

Redocly Version(s) 1.17.0

Node.js Version(s)

v18.18.2

Additional context

RomanHotsiy commented 1 month ago

What is your idea to "fix" this on the fly?

amine-mf commented 1 month ago

In this case, I took an "arbitrary" decision to replace it with "any object". This only an example.

components:
  schemas:
    SomeComponent:
      type: object

The real idea behind is to be able to apply "fixes/patches" in the bundle visitor. (Same as a lint --fix but in this case, it would be different types of fixes that you can "inject"). So I understand currently there is no way to do it using redocly? (BTW, my current "fix" is to preprocess the files before feeding them to bundle)