Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swagger error "type" should be a string #1302

Closed
robinsingh-bw opened this issue Apr 26, 2017 · 3 comments
Closed

swagger error "type" should be a string #1302

robinsingh-bw opened this issue Apr 26, 2017 · 3 comments

Comments

@robinsingh-bw
Copy link

Hi,

I have the following schema:

{
  "swagger": "2.0",
  "info": {
    "title": "API V1",
    "version": "v1"
  },
  "paths": {
    "/brands": {
      "get": {
        "summary": "Fetches all brands",
        "tags": [
          "Brands"
        ],
        "parameters": [
          {
            "name": "page",
            "in": "query",
            "type": "integer",
            "required": false
          },
          {
            "name": "per_page",
            "in": "query",
            "type": "integer",
            "required": false
          }
        ],
        "responses": {
          "200": {
            "description": "received brands",
            "schema": {
              "$schema": "http://json-schema.org/draft-04/schema#",
              "type": "object",
              "required": [
                "brands"
              ],
              "properties": {
                "brands": {
                  "type": "array",
                  "minItems": 1,
                  "uniqueItems": true,
                  "items": {
                    "type": "object",
                    "required": [
                      "name"
                    ],
                    "properties": {
                      "name": {
                        "type": [
                          "string",
                          "null"
                        ]
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

Its showing these two errors:

Schema error at paths./brands.get.responses[200]
is not exactly one from <#/definitions/response>,<#/definitions/jsonReference>
Semantic error at paths./brands.get.responses.200.schema.properties.brands.items.properties.name.type
"type" should be a string

The second issue is being caused by the type: ["string", "null"] line but all my draft4 json schema specs are passing so I dont understand why its complaining? Is this not valid schema?

Regards.

@webron
Copy link
Contributor

webron commented Apr 26, 2017

@robinsingh-bw Swagger doesn't use the full JSON Schema. One of the restrictions is that type must be a single value and not an array. null is not supported as a type at all.

@webron webron closed this as completed Apr 26, 2017
@philsturgeon
Copy link

Hey there! Sorry to bring this back up, but it's the sort of thing that's gonna get found on Google. It certainly is not a job for Swagger Editor to worry about htis, as Swagger Editor is just following the Swagger specification, but is there an issue somewhere where this is being worked on?

The whole "Meh we're a sub&super-set of JSON Schema is not an ok status quo, but an anomaly that needs to be eradicated one piece at a time. Right?

@philsturgeon
Copy link

Found it! OAI/OpenAPI-Specification#229 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants