Operation output is the data an API returns as part of an operation’s result. Design it alongside the HTTP response: the status code tells consumers what happened, while response headers and bodies carry the information they need next. For a product search, that may be product information—or an empty list when nothing matches. section 4.1.2 section 4.6.2
Choose output according to what the consumer must do next:
- After creating a product with POST, return its representation or a reference that lets the consumer retrieve it. A 201 Created response includes the new resource’s URL in a Location header, even if it has no body. section 4.6.2
- After modifying a product, a 200 OK response can include the updated product; 204 No Content instead has no response data. Error statuses often need error information as well as the status code. section 4.6.2
Once the location is chosen, describe the output in OpenAPI. Response bodies and response headers have different places in the operation description, but their data can be specified with JSON Schema. This also makes an intentionally bodyless response distinct from one whose body was simply left undocumented. section 6.8 section 7.5
Listing 5.1 Sample response for the “Read movie information” operation
{
"id": "ZFqoFq",
"title": "Ghost In The Shell",
"releaseYear": "1995",
"duration": "83",
"director": "Mamoru Oshii",
"music": "Kenji Kawai",
"language": "ja"
}
Use this movie-information response as a concrete output-design check: inspect each property and its JSON value before deciding whether the response data is modeled as intended. section 5.8
Keep output useful within its operation. Search filters should match the names and types of returned properties: a transaction category filter is easier to discover and use when transactions include category. A query parameter can also adjust returned values—for example, requesting a bank balance in EUR instead of the default USD—but should not drastically change the response structure or switch resources. In a car-rental flow, returned cars should include the information needed to choose one. section 9.6.1 section 9.7.3 section 10.1.4
Treat output as a consumer-facing contract when changing an API. Removing an expected property, changing its type, or adding an unexpected enum value can break consumers; the same caution applies to error bodies and response headers. Add or adjust data only within the limits of the existing response contract. section 15.2.1
Before publishing an operation, check:
- Does each result have an appropriate status, and are the body and headers sufficient for the consumer’s next step? section 4.1.2 section 4.6.2
- Are the returned fields described in OpenAPI, consistent with relevant filters, and safe for existing consumers? section 7.5 section 9.6.1 section 15.2.1
