Update ProducesResponseTypeAttribute
to support setting content types for the defined response
#34542
Labels
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
feature-minimal-actions
Controller-like actions for endpoint routing
old-area-web-frameworks-do-not-use
*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Priority:1
Work that is critical for the release, but we could probably ship without
Milestone
The
Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute
implementsIApiResponseMetadataProvider
today but does not support setting the content types associated with the response type defined by the attribute instance. This limitation means there is no way to specify the content type produced for specific status codes for a given endpoint, despite the OpenAPI specification supporting this.Customers have indicated they have a need for this support in the OpenAPI library for ASP.NET Core, Swashbuckle too, see domaindrivendev/Swashbuckle.AspNetCore#1691
Take the following common example. A single endpoint can return either
400 Bad Request
with a validation problem formatted asapplication/problem+json
, or a201 Created
with the created resource formatted asapplication/json
:This would be represented in an OpenAPI document like this:
We should update
Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute
to support defining the content types associated with the declared response type, e.g.:This change would work in conjunction with #33924 to enable endpoints to describe the content types they return for each status code and response type. Endpoints that don't specify a content type should default to being described as returning
application/json
inline with the default minimal APIs behavior.The text was updated successfully, but these errors were encountered: