Describing Responses

In an OpenAPI document, each operation must have at least one response defined, usually a successful response. A response is defined by its HTTP status code and the data returned in the response body and/or headers. To learn more about how responses are described by the OpenAPI Specification, checkout out the OpenAPI docs here.

By default, Swashbuckle will generate a “200” response for all operations. Additionally, if the action returns a response DTO (as a specific type or ActionResult<T>) then this will be used to generate a “schema” for the response body.

For example, given the following action method:

Swashbuckle will generate the following responses:

Note

If you need to specify a different status code and/or additional responses, or your actions return IActionResult instead of a response DTO, you can describe responses explicitly by annotating actions or controllers with the [ProducesResponseType] and/or [ProducesDefaultResponseType] attributes that ship with ASP.NET Core. See Listing Response Types for more info.