PaloAltoNetworks / docusaurus-openapi-docs

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

Ignore unknown vendor extensions #891

Open tjperry07 opened 1 month ago

tjperry07 commented 1 month ago

Is your feature request related to a problem?

My API contains custom vendor extensions so it does certain actions as part of the build. The plugin should ignore or skip any it doesn't know. (I wasn't sure if this was a bug or enhancemenmt)

For example:

"x-coa-command-group": "nodes",

I have to remove them each time, otherwise I get an error like:

> docusaurus gen-api-docs all

Loading of api failed for "/Users/tatiana/Documents/coalesce-docs/static/api/coalesce-api.json"

[ERROR] TypeError: Cannot create property 'description' on string 'nodes'
    at createItems (/Users/tatiana/Documents/coalesce-docs/node_modules/docusaurus-plugin-openapi-docs/lib/openapi/openapi.js:109:45)
    at processOpenapiFile (/Users/tatiana/Documents/coalesce-docs/node_modules/docusaurus-plugin-openapi-docs/lib/openapi/openapi.js:511:19)
    at async /Users/tatiana/Documents/coalesce-docs/node_modules/docusaurus-plugin-openapi-docs/lib/openapi/openapi.js:464:35
    at async Promise.all (index 0)
    at async processOpenapiFiles (/Users/tatiana/Documents/coalesce-docs/node_modules/docusaurus-plugin-openapi-docs/lib/openapi/openapi.js:475:22)
    at async generateApiDocs (/Users/tatiana/Documents/coalesce-docs/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:95:44)
    at async /Users/tatiana/Documents/coalesce-docs/node_modules/docusaurus-plugin-openapi-docs/lib/index.js:439:15
[INFO] Docusaurus version: 3.4.0

Describe the solution you'd like

Ignore the unknown vendor extensions. Don't try to process or do anything with them.

Describe alternatives you've considered

None, I need them for code generation for the company app. I can't take them out.

Additional context

If left in, I get error messages and the reference won't generate.

sserrata commented 1 month ago

Hi @tjperry07, can you provide a copy or example snippet that can be used to reproduce the error? Thanks!

tjperry07 commented 1 month ago
  "paths": {
    "/api/v1/environments": {
      "summary": "Environments",
      "x-coa-command-group": "environments",
      "parameters": [],
      "get": {
        "summary": "List Environments",
        "description": "Get a collection of Environment information.",
        "operationId": "GetEnvironments",
        "x-eov-operation-handler": "EnvironmentHandlers",
        "x-coa-command": "list",
        "parameters": [
          {
            "name": "detail",
            "description": "Include the full detail of the environments.",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": false
            },
            "required": false
          }
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Environments"
        ],
        "responses": {
          "200": {
            "$ref": "#/components/responses/EnvironmentsResponse"
          },
          "400": {
            "$ref": "#/components/responses/InvalidRequestError"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/ForbiddenError"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          },
          "502": {
            "$ref": "#/components/responses/BadGatewayError"
          },
          "503": {
            "$ref": "#/components/responses/ServiceUnavailableError"
          },
          "504": {
            "$ref": "#/components/responses/GatewayTimeoutError"
          }
        }
      }
    },
sserrata commented 1 month ago

Hi @tjperry07, I wasn't able to reproduce.

Added vendor extension to addPet operation

    post:
      tags:
        - pet
      summary: Add a new pet to the store
      "x-coa-command-group": "environments"
      description: Add new pet to the store inventory.
      operationId: addPet
      responses:
        "200":
          description: All good
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    oneOf:
                      - type: string
                      - type: object
        "405":
          description: Invalid input

On a side note, are you aware of the option showExtensions? Basically, it allows you to display additional vendors extensions when set to true:

Screenshot 2024-07-26 at 2 03 47 PM
tjperry07 commented 1 month ago

@sserrata I don't want to show vendor extensions. They should be hidden because they are used elsewhere in development I would share the whole file, but I can't for work reasons. :(

sserrata commented 1 month ago

Hi @tjperry07, they are in fact hidden by default - I was mainly illustrating that I was unable to reproduce the error you're seeing.

BrunoCampana commented 1 week ago

I can confirm this error is really happening. I'm also having the same issue: I ommited showExtensions on the configuration. I do have many extension fields. Then I try to run (Ubuntu 20) and received the precise same error. I then make the same test after removing all extension fields from the file, and it restarts to work perfectly.