enzonotario / vitepress-openapi

Generate VitePress API Docs from OpenAPI specifications
https://vitepress-openapi.vercel.app
MIT License
36 stars 8 forks source link

[BUG] Generator crashes if openapi-spec contains a circular reference #57

Closed JustSamuel closed 1 week ago

JustSamuel commented 1 week ago

Take the following minimal crashable example:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Minimal API with Circular Reference",
    "version": "1.0.0"
  },
  "paths": {
    "/parent": {
      "get": {
        "summary": "Get a parent",
        "operationId": "getParent",
        "responses": {
          "200": {
            "description": "A parent with a child",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Parent"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Parent": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "child": {
            "$ref": "#/components/schemas/Child"
          }
        }
      },
      "Child": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "parent": {
            "$ref": "#/components/schemas/Parent"
          }
        }
      }
    }
  }
}

This is valid openapi spec as can be seen checked using a validator. Of course, dealing with a circular swagger requires a form of normalization.

I am currently using the standard swagger UI, which does nicely deal with circular references. However, as I have moved all my documentation over to vitepress, I would also prefer to maybe include some swagger here and there as it could help make explanations a bit clearer.

enzonotario commented 1 week ago

I fixed it in #60 . Can you please validate it?

JustSamuel commented 1 week ago

Works like a charm!