Review property constraints in composed schemas

Check that a property can satisfy all constraints applied by the composed schema.

Description

With allOf, a property must satisfy every constraint that applies to it. Multiple definitions of the same name are allowed if they agree.

Potential impact

Conflicting types can rule out every value of a property. If it is optional, an object that omits it may still pass validation.

Remediation

Check every constraint on the property. Keep compatible ones and resolve conflicts using the type the API actually accepts.

Examples

These OpenAPI 3.0 excerpts omit info and paths. The first defines code as an integer and also requires any code value to be a string.

Before

json
{
  "openapi": "3.0.0",
  "components": {
    "schemas": {
      "ErrorModel": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer"
          }
        },
        "allOf": [
          {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              }
            }
          }
        ]
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "components": {
    "schemas": {
      "ErrorModel": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer"
          },
          "rootCause": {
            "type": "string"
          }
        }
      }
    }
  }
}

The revision keeps integer code and adds a separate string rootCause. Use two fields only if the API exposes both.

References