Review additional properties on reference objects

Check whether properties beside a reference apply under the specification version in use.

Description

Swagger 2.0 and OpenAPI 3.0 Reference Objects ignore fields such as type or description beside $ref. Check the rules for the specific object and version when using a Path Item’s $ref or a different OpenAPI version.

Potential impact

Validators and generated clients can miss a constraint or description written beside the reference.

Remediation

Keep only $ref in the Reference Object. Put shared details in the target definition. To add a constraint at one schema location, use allOf and check that the target exists and the constraints can be satisfied together.

Examples

Before

json
{
  "openapi": "3.0.0",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "integer",
                  "$ref": "#/components/schemas/MyObject"
                }
              }
            }
          }
        }
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MyObject"
                }
              }
            }
          }
        }
      }
    }
  }
}

The 3.0 excerpt removes the ignored type. The MyObject definition determines the type. The full specification also needs the omitted info and components.schemas.MyObject definitions.

References