-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Description
Description
The document says:
OpenAPI supports providing a description of the responses returned from an API. ASP.NET Core provides several strategies for setting the response metadata of an endpoint. Response metadata that can be set includes the status code, the type of the response body, and content type(s) of a response. Responses in OpenAPI may have additional metadata, such as description, headers, links, and examples. This additional metadata can be set with a document transformer or operation transformer.
This is true for .NET 9, but for .NET 10 I've implemented dotnet/aspnetcore#55656 which allows a developer to set the response description for both controllers and minimal API like so:
Controllers:
[HttpGet("{id:int:min(1)}")]
[ProducesResponseType<Talk>(StatusCodes.Status200OK, Description = "A talk entity when the request is succesful")]
[ProducesResponseType(StatusCodes.Status422UnprocessableEntity, Description = "The entity is unprocessable SOME_REASON_HERE")]
[ProducesDefaultResponseType(Description = "The response for all other errors that might be thrown")]
public ActionResult<Talk> GetTalk(int id)
{
// Code here
}Minimal API:
builder.MapGet("/api/todos",
[ProducesResponseType(typeof(Todo), StatusCodes,Status200Ok, Description = "A list of todo items")]
[ProducesResponseType(StatusCodes.Status400BadRequest, Description = "Some bad request description")]
() =>
{
// Code here
});The page should be updated to reflect these new possibilities.
This is only relevant for .NET 10, but I thought it'd be worth creating this issue already so it can be tracked!
PS: I'm currently working on creating an API proposal for dotnet/aspnetcore#57963 which might then also add other options for minimal API's in .NET 10: dotnet/aspnetcore#58724
Page URL
Content source URL
Document ID
27bad30c-e0b4-10fb-b202-a29d4f8fad24