PaloAltoNetworks / docusaurus-openapi-docs

🦝 OpenAPI plugin for generating API reference docs in Docusaurus v3.
https://docusaurus-openapi.tryingpan.dev
MIT License
686 stars 233 forks source link

generate mdx of circular $ref failed #720

Open mchades opened 8 months ago

mchades commented 8 months ago

Describe the bug

OAS including circular $ref, use yarn docusaurus gen-api-docs all encounter error

Expected behavior

successfully

Current behavior

fail

Possible solution

I tried my best to work around by modifying the lib file:

image

function replaceOneOfWithValue(obj, parent, keyInParent) {
    if (obj && typeof obj === 'object') {
        // If the current property is an object, recursively traverse its properties
        Object.keys(obj).forEach(key => {
        if (key === 'oneOf' && !Array.isArray(obj[key])) {
          // If the 'oneOf' property is found and its value is not an array
          // Then replace the corresponding property value of the parent object with the string 'circular(DataType)'
          parent[keyInParent] = 'circular(DataType)';
        } else {
          // Recursively traverse the current property
          replaceOneOfWithValue(obj[key], obj, key);
        }
      });
    } else if (Array.isArray(obj)) {
      // If the current property is an array, recursively traverse each element of the array
      obj.forEach((item, index) => {
        replaceOneOfWithValue(item, obj, index);
      });
    }
}

Steps to reproduce

use the OAS of the project Gravitino

Screenshots

Context

Your Environment

sserrata commented 3 months ago

Hi @mchades, thanks for reporting this issue. If your proposed changes address the issue would you mind opening a PR so we can work toward merging it into the code base?

mchades commented 2 months ago

Hi @mchades, thanks for reporting this issue. If your proposed changes address the issue would you mind opening a PR so we can work toward merging it into the code base?

Hi @sserrata , Thank you for your response, and sorry for the late reply.

I only proposed a hard-coded work around, I am not good at TS and JS, and I do not know how to fix this problem from the source. My description just provides a way to reproduce it.