Default value does not match the type (OpenAPI 3.0)

A default value conflicts with its declared data type

Description

In OpenAPI 3.0, a default must match the type declared in the same schema.

Potential impact

A mismatch can break document validation, SDK generation or a client that uses the default.

Remediation

Choose a default within the allowed range. Omit the value in a test and check how the server and client handle it.

Examples

The GET / response schema changes its default from the string "a" to the integer 1, which also satisfies minimum: 0.

Before

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "integer",
                  "format": "int32",
                  "description": "the size of the pack the dog is from",
                  "default": "a",
                  "minimum": 0
                }
              }
            }
          }
        }
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API Overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "integer",
                  "format": "int32",
                  "description": "the size of the pack the dog is from",
                  "default": 1,
                  "minimum": 0
                }
              }
            }
          }
        }
      }
    }
  }
}

References