Response body without a documented schema

Document the media type and structure of responses that actually return a body.

Description

For a response that returns data, describe the body the client will receive. A bodyless response needs no body schema.

Potential impact

An incorrect SDK model can cause parsing errors and make incompatible changes harder to spot.

Remediation

In OpenAPI 3.0, put the media type under the response’s content and its schema under that media type. In 2.0, use the response’s schema and the applicable produces value.

Examples

The revised 200 response definition describes an application/json body using ApiVersion. Supply the referenced schema separately.

Before

json
{
  "openapi": "3.0.0",
  "paths": {
    "/": {
      "get": {
        "responses": {
          "200": {
            "description": "200 response"
          }
        }
      }
    }
  }
}

After

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

References