Schema discriminator property must be a string

Description

You have defined a discriminator that is not a string. Discriminator values must always be of the type string.

This applies only to OpenAPI Specification (OAS) v2. For more details, see the OAS.

Example

The following is an example of how this issue could look in your API definition. Here, the type of the discriminator age is integer :

{
  "definitions": {
    "Pet": {
      "type": "object",
      "discriminator": "age",
      "properties": {
        "name": {
          "type": "string"
        },
        "age": {
          "type": "integer"
        }
      },
      "required": [
        "name",
        "age"
      ]
    }
  }
}

Remediation

Make sure that all discriminator values are strings.

{
  "definitions": {
    "Pet": {
      "type": "object",
      "discriminator": "age",
      "properties": {
        "name": {
          "type": "string"
        },
        "age": {
          "type": "string"
        }
      },
      "required": [
        "name",
        "age"
      ]
    }
  }
}

Get API Security news directly in your Inbox.

By clicking Subscribe you agree to our Data Policy