PaloAltoNetworks / PaloAltoNetworks/docusaurus-openapi-docs

generate mdx of circular $ref failed

Open
#720 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug question reviewing :eyes:
Dominant language
TypeScript
Stars
1.1k
Forks
315
Avg merge
7d 5h
Merged PRs (30d)
7

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running yarn docusaurus gen-api-docs all against the linked Gravitino OAS and capture the full error. Inspect the generation path that processes circular $ref and compare it with the reported workaround. Done means the command completes and generates MDX successfully for circular references without breaking non-circular schemas.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
documentation, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.