Review discriminator value types and mappings

Align discriminator values with schema mappings and check any reliance on string conversion.

Description

A string discriminator property can be compared consistently with schema names or mapping keys. OpenAPI 3.0 requires string mapping keys but permits tooling to convert response values to strings for comparison, so a numeric property is not always a specification violation. Relying on unverified conversion can cause compatibility problems.

Potential impact

If servers and clients compare values differently, they may choose different subtypes or fail to identify a type.

Remediation

Review actual discriminator values and schema mappings, using a consistent string contract where practical. Coordinate servers and clients when changing existing numeric values to strings. In OpenAPI 2.0, discriminator values must identify the applicable model names under definitions.

Examples

These OpenAPI 3.0 excerpts compare property types; subtypes, polymorphic composition, info and paths are omitted. The numeric property in the first needs review alongside its mapping and tool conversion support.

Before

json
{
  "openapi": "3.0.0",
  "components": {
    "schemas": {
      "GeneralError": {
        "type": "object",
        "discriminator": {
          "propertyName": "petType"
        },
        "properties": {
          "petType": {
            "type": "integer"
          }
        },
        "required": [
          "petType"
        ]
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "components": {
    "schemas": {
      "GeneralError": {
        "type": "object",
        "discriminator": {
          "propertyName": "petType"
        },
        "properties": {
          "petType": {
            "type": "string"
          }
        },
        "required": [
          "petType"
        ]
      }
    }
  }
}

The second defines petType as a string. Actual transmitted values must match that type and schema mapping; changing the declaration alone does not convert data.

References