Numeric format does not match the type (OpenAPI 3.0)

A standard numeric format conflicts with the schema type

Description

When using a standard numeric format, pair integer with int32 or int64 and number with float or double. The format field is optional.

Potential impact

An unrecognized format can produce a different numeric type than expected in a generated SDK.

Remediation

Choose a format that fits the values you exchange. For a custom format, check validation and serialization with representative values in your tools.

Examples

The example changes the integer id to int64 and the numeric percentage to float.

Before

json
{
  "openapi": "3.0.0",
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "double"
          },
          "percentage": {
            "type": "number",
            "format": "int32"
          }
        }
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "components": {
    "schemas": {
      "MyObject": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "percentage": {
            "type": "number",
            "format": "float"
          }
        }
      }
    }
  }
}

References