-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-openapi
Milestone
Description
Background and Motivation
The ProducesProblem extension method can be specified on a RouteHandlerBuilder to specify that the route handler may return a ProblemDetails response. But unlike similar extension methods to add endpoint metadata, e.g. WithDescription or WithTags, the ProducesProblem extension method is not supported on RouteGroupBuilder. Since nearly every operation can fail in some way or other, it seems desirable to be able to easily mark all route handlers in a group as potentially returning ProblemDetails, and doing this with the ProducesProblem method on the RouteGroupBuilder is the most natural way to do this.
Proposed API
// Assembly: Microsoft.AspNetCore.Routing
namespace Microsoft.AspNetCore.Http;
public static class OpenApiRouteHandlerBuilderExtensions
{
+ public static TBuilder ProducesProblem<TBuilder>(this TBuilder builder, int statusCode, string? contentType = null) where TBuilder : IEndpointConventionBuilder { }
+ public static ProducesValidationProblem<TBuilder>(this TBuilder builder, int statusCode = StatusCodes.Status400BadRequest, string? contentType = null) where TBuilder : IEndpointConventionBuilder { }
}Usage Examples
var app = WebApplication.Create();
var todos = app.MapGroup("/todos")
.ProducesProblem(statusCode: 500, "application/json+problem");Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesfeature-openapi