readmeio/api

Parsing fails, requiring "TYPE must be string"

Closed this issue · 1 comments

api 6.1.0 is failing when validating my schema, tripping up on fields that can be null. When I instead tried with the openapi-generator tool, it didn't complain about building the SDK - so I don't really think the schema is invalid, although I'm open to all input!

Here's a snippet of the output:

node:internal/process/promises:288
            triggerUncaughtException(err, true /* fromPromise */);
            ^

SyntaxError: OpenAPI schema validation failed.

TYPE must be string

  113 |           {
  114 |             "schema": {
> 115 |               "type": [
      |                       ^ 👈🏽type must be string
  116 |                 "number",
  117 |                 "null"
  118 |               ],

TYPE must be string

  760 |                           },
  761 |                           "caption": {
> 762 |                             "type": [
      |                                     ^ 👈🏽type must be string
  763 |                               "null",
  764 |                               "string"
  765 |                             ]

Here's a snippet of the OpenAPI 3.0.3 schema:

            "get": {
                "summary": "List all attributes",
                "tags": [
                    "attribute"
                ],
                "parameters": [
                    {
                        "schema": {
                            "type": "number",
                            "default": 0
                        },
                        "in": "query",
                        "name": "offset",
                        "required": false
                    },
                    {
                        "schema": {
                            "type": [
                                "number",
                                "null"
                            ],
                            "default": null
                        },
                        "in": "query",
                        "name": "count",
                        "required": false
                    },

Thanks for any advice.

Hi! This is failing because OpenAPI 3.0.x does not support type arrays like that. That was introduced in OpenAPI 3.1. If you change the openapi property in your file to openapi: 3.1 it should work.

Interesting that it didn't complain about that when generating the SDK though.