-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Allow setting a group name for endpoints and have it be used to populate ApiDescription.GroupName in ApiExplorer for minimal APIs #34541
Copy link
Copy link
Closed
Labels
Priority:1Work that is critical for the release, but we could probably ship withoutWork that is critical for the release, but we could probably ship withoutarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Metadata
Metadata
Assignees
Labels
Priority:1Work that is critical for the release, but we could probably ship withoutWork that is critical for the release, but we could probably ship withoutarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Type
Fields
Give feedbackNo fields configured for issues without a type.
APIs described by
Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptioncan optionally have a group name defined by theGroupNameproperty. Today in the framework there isn't a way provided to set the group name for an endpoint via its metadata and theEndpointMetadataApiDescriptionProviderdoes not setApiDescription.GroupNamewhen it populatesApiExplorerwith details of the registered endpoints.ApiDescription.GroupNameis used by frameworks like Swashbuckle to associate APIs with different OpenAPI documents, i.e. if the document name and API group name match the API is included in the document (see default logic here).We should allow for setting the group name for endpoints via their metadata and have that used to populate the
ApiDescription.GroupNameproperty when the endpoints are added toApiExplorer.Proposed types for addition:
Proposed extension methods for addition:
namespace Microsoft.AspNetCore.Builder; public static class RoutingEndpointConventionBuilderExtensions { + /// <summary> + /// Adds an EndpointGroupNameMetadata item to the Metadata for all endpoints produced by the builder. + /// </summary> + /// <param name="builder"></param> + /// <param name="groupName"></param> + /// <returns>The Microsoft.AspNetCore.Builder.IEndpointConventionBuilder.</returns> + public static TBuilder WithGroupName<TBuilder>(this TBuilder builder, string groupName) where TBuilder : IEndpointConventionBuilder + { + builder.WithMetadata(new EndpointGroupNameMetadata(groupName)); + + return builder; + } }Example of these new types and methods being used with minimal APIs: