Skip to content

Clarify spec about schemas with multiple types #458

@ePaul

Description

@ePaul

In #1401 of swagger-core, @webron mentioned that specifying multiple types for a schema is not valid.

The 2.0 Spec says for a schema object:

The following properties are taken directly from the JSON Schema definition and follow the same specifications:
[...]

  • type

JSON Schema validation says in section 5.5.2:

5.5.2. type

5.5.2.1. Valid values

The value of this keyword MUST be either a string or an array. If it is an array, elements of the array MUST be strings and MUST be unique.

String values MUST be one of the seven primitive types defined by the core specification.

5.5.2.2. Conditions for successful validation

An instance matches successfully if its primitive type is one of the types defined by keyword. Recall: "number" includes "integer".

I would interpret this as my type: ["integer", "string"] property being valid JSON Schema, and thus also valid Swagger.

While the "null" type name is not available in swagger due to it missing in the list of available types, the same consideration applies to something like "type": ["integer", "string"]. If this is not supposed to be valid, the sentence quoted above needs to be changed.

(Also, instead of referring to the "latest" version of JSON schema, I would explicitly name the version used, so the validity of Swagger documents doesn't suddenly change whenever there is a new version of JSON schema.)

Related issues I found here: #297, #229, #403.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions