-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Route Groups] WithTags et al. should target IEndpointConventionBuilder #41428
Comments
The |
Indeed. Route filters are one of the main things we want to be able to apply to an entire group. Unlike I am hoping that #41427 which tracks supporting custom |
Thanks for contacting us. We're moving this issue to the |
Background and Motivation
Proposed APInamespace Microsoft.AspNetCore.Http;
public static class OpenApiRouteHandlerBuilderExtensions
{
public static RouteHandlerBuilder ExcludeFromDescription(this RouteHandlerBuilder builder);
+ public static TBuilder ExcludeFromDescription<TBuilder>(this TBuilder builder) where TBuilder : IEndpointConventionBuilder;
public static RouteHandlerBuilder Produces<TResponse>(
this RouteHandlerBuilder builder,
int statusCode = StatusCodes.Status200OK,
string? contentType = null,
params string[] additionalContentTypes);
public static RouteHandlerBuilder Produces(
this RouteHandlerBuilder builder,
int statusCode,
Type? responseType = null,
string? contentType = null,
params string[] additionalContentTypes);
+ public static TBuilder Produces<TBuilder>(
+ this TBuilder builder,
+ Type? responseType = null,
+ int statusCode = StatusCodes.Status200OK,
+ string? contentType = null,
+ params string[] additionalContentTypes) where TBuilder : IEndpointConventionBuilder;
public static RouteHandlerBuilder ProducesProblem(
this RouteHandlerBuilder builder,
int statusCode,
string? contentType = null);
+ public static TBuilder ProducesProblem<TBuilder>(
+ this TBuilder builder,
+ int statusCode,
+ string? contentType = null) where TBuilder : IEndpointConventionBuilder;
public static RouteHandlerBuilder ProducesValidationProblem(
this RouteHandlerBuilder builder,
int statusCode = StatusCodes.Status400BadRequest,
string? contentType = null);
+ public static TBuilder ProducesValidationProblem<TBuilder>(
+ this TBuilder builder,
+ int statusCode = StatusCodes.Status400BadRequest,
+ string? contentType = null) where TBuilder : IEndpointConventionBuilder;
public static RouteHandlerBuilder Accepts<TRequest>(
this RouteHandlerBuilder builder,
bool isOptional,
string contentType,
params string[] additionalContentTypes) where TRequest : notnull;
public static RouteHandlerBuilder Accepts(
this RouteHandlerBuilder builder,
Type requestType,
bool isOptional,
string contentType,
params string[] additionalContentTypes);
public static RouteHandlerBuilder Accepts(
this RouteHandlerBuilder builder,
Type requestType,
string contentType,
params string[] additionalContentTypes);
+ public static TBuilder Accepts<TBuilder>(
+ this TBuilder builder,
+ Type requestType,
+ bool isOptional,
+ string contentType,
+ params string[] additionalContentTypes) where TBuilder : IEndpointConventionBuilder;
+ public static TBuilder Accepts<TBuilder>(
+ this TBuilder builder,
+ Type requestType,
+ string contentType,
+ params string[] additionalContentTypes) where TBuilder : IEndpointConventionBuilder;
public static RouteHandlerBuilder WithTags(this RouteHandlerBuilder builder, params string[] tags);
+ public static TBuilder WithTags<TBuilder>(this TBuilder builder, params string[] tags) where TBuilder : IEndpointConventionBuilder;
- public static RouteHandlerBuilder WithDescription(this RouteHandlerBuilder builder, string description);
+ public static TBuilder WithDescription<TBuilder>(this TBuilder builder, string description) where TBuilder : IEndpointConventionBuilder;
- public static RouteHandlerBuilder WithSummary(this RouteHandlerBuilder builder, string summary);
+ public static TBuilder WithSummary<TBuilder>(this TBuilder builder, string summary) where TBuilder : IEndpointConventionBuilder Usage Examplesvar todoGroup = app.MapGroup("/todos");
todoGroup.WithTags("todos");
todoGroup.WithSummary("An endpoint for managing todos.");
todoGroup.MapGet("/", (TodoDb db) => TypedResults.Ok(await db.Todos.ToArrayAsync()));
todoGroup.MapPost("/todos", (Todo todo, TodoDb db) =>
{
// .... Alternative Designs
RisksLow. No overloads that exist in .NET 6 are removed. I also added tests calling all the new and old overloads to verify they do not cause ambiguity. This does cause these extension methods to show up in a bunch of new places however like on the builders returned by |
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
API Review Notes:
Approved API: namespace Microsoft.AspNetCore.Http;
public static class OpenApiRouteHandlerBuilderExtensions
{
public static RouteHandlerBuilder ExcludeFromDescription(this RouteHandlerBuilder builder);
+ public static TBuilder ExcludeFromDescription<TBuilder>(this TBuilder builder) where TBuilder : IEndpointConventionBuilder;
public static RouteHandlerBuilder WithTags(this RouteHandlerBuilder builder, params string[] tags);
+ public static TBuilder WithTags<TBuilder>(this TBuilder builder, params string[] tags) where TBuilder : IEndpointConventionBuilder;
- public static RouteHandlerBuilder WithDescription(this RouteHandlerBuilder builder, string description);
+ public static TBuilder WithDescription<TBuilder>(this TBuilder builder, string description) where TBuilder : IEndpointConventionBuilder;
- public static RouteHandlerBuilder WithSummary(this RouteHandlerBuilder builder, string summary);
+ public static TBuilder WithSummary<TBuilder>(this TBuilder builder, string summary) where TBuilder : IEndpointConventionBuilder |
WithTags
and otherOpenApiRouteHandlerBuilderExtensions
don't work with route groups today because they target a customIEndpointConventionBuilder
type (RouteHandlerBuilder
) rather than anyIEndpointConventionBuilder
. While we do plan to support custom convention builder types on route groups (#41427), it shouldn't be necessary for many of the methods onOpenApiRouteHandlerBuilderExtensions
.Describe the solution you'd like
We should retarget
WithTags
and similar methods toIEndpointConventionBuilder
. If we cannot do that without breaking, maybe it should targetGroupRouteBuilder
(or a futureIRouteGroup
interface).The text was updated successfully, but these errors were encountered: