openapi-backend icon indicating copy to clipboard operation
openapi-backend copied to clipboard

OpenAPI 3.1 Support

Open revnode opened this issue 1 year ago • 3 comments

It looks like OpenAPI 3.1 support was added a few years back? I'm having trouble with it.

When executing:

const definition = `{
  "openapi": "3.1.0",
  "info": {
    "version": "1.0.0",
    "title": "test",
    "description": "test",
    "contact": {
      "email": "[email protected]"
    },
    "license": {
      "name": "UNLICENSED",
      "url": "https://test.com/terms-conditions/"
    }
  },
  "servers": [
    {
      "url": "/api/v1"
    }
  ],
  "paths": {
    "/ping": {
      "get": {
        "operationId": "ping.get",
        "summary": "Checks if the API is operational.",
        "description": "Verifies the API is deployed and functioning properly.",
        "tags": [
          "Utilities"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "description": "The response to a ping should be pong.",
                      "type": "string",
                      "example": "pong"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "key": {
        "type": "apiKey",
        "in": "header",
        "name": "key",
        "description": "test"
      },
      "session": {
        "type": "apiKey",
        "in": "header",
        "name": "session",
        "description": "test"
      }
    },
    "schemas": {
      "test": {
        "type": "object",
        "properties": {
          "test": {
            "description": "This is a test.",
            "type": [
              "string",
              "null"
            ]
          }
        }
      }
    }
  }
}`;
const api = new OpenAPIBackend({
  definition,
  apiRoot: "/api/v1"
});

I get errors like:

{
  "instancePath": "/components/schemas/test/properties/test/type",
  "schemaPath": "#/properties/type/type",
  "keyword": "type",
  "params": {
    "type": "string"
  },
  "message": "must be string"
}

If I set the type to a string, the error goes away. But it should support an array? Any help appreciated. Thanks!

revnode avatar Feb 21 '23 05:02 revnode