diff --git a/src/GeneratedEndpoints/MinimalApiGenerator.cs b/src/GeneratedEndpoints/MinimalApiGenerator.cs index c869cfc..6cd6336 100644 --- a/src/GeneratedEndpoints/MinimalApiGenerator.cs +++ b/src/GeneratedEndpoints/MinimalApiGenerator.cs @@ -594,8 +594,8 @@ private static bool RequestHandlerFilter(SyntaxNode syntaxNode, CancellationToke var (httpMethod, pattern, name, summary, description) = GetRequestHandlerAttribute(attribute, cancellationToken); - var (tags, requireAuthorization, authorizationPolicies, disableAntiforgery, allowAnonymous, accepts, produces, - producesProblem, producesValidationProblem) + var (tags, requireAuthorization, authorizationPolicies, disableAntiforgery, allowAnonymous, excludeFromDescription, + accepts, produces, producesProblem, producesValidationProblem) = GetAdditionalRequestHandlerAttributes(requestHandlerClassSymbol, requestHandlerMethodSymbol, cancellationToken); name ??= RemoveAsyncSuffix(requestHandlerMethod.Name); @@ -608,7 +608,8 @@ private static bool RequestHandlerFilter(SyntaxNode syntaxNode, CancellationToke accepts, produces, producesProblem, - producesValidationProblem + producesValidationProblem, + excludeFromDescription ); var requestHandler = new RequestHandler(requestHandlerClass, requestHandlerMethod, httpMethod, pattern, metadata, requireAuthorization, @@ -689,6 +690,7 @@ private static ( EquatableImmutableArray? authorizationPolicies, bool disableAntiforgery, bool allowAnonymous, + bool excludeFromDescription, EquatableImmutableArray? accepts, EquatableImmutableArray? produces, EquatableImmutableArray? producesProblem, @@ -702,6 +704,7 @@ private static ( EquatableImmutableArray? authorizationPolicies = null; var disableAntiforgery = false; var allowAnonymous = false; + var excludeFromDescription = false; List? accepts = null; List? produces = null; @@ -716,6 +719,7 @@ private static ( ref authorizationPolicies, ref disableAntiforgery, ref allowAnonymous, + ref excludeFromDescription, ref accepts, ref produces, ref producesProblem, @@ -730,6 +734,7 @@ ref producesValidationProblem ref authorizationPolicies, ref disableAntiforgery, ref allowAnonymous, + ref excludeFromDescription, ref accepts, ref produces, ref producesProblem, @@ -742,6 +747,7 @@ ref producesValidationProblem authorizationPolicies, disableAntiforgery, allowAnonymous, + excludeFromDescription, ToEquatableOrNull(accepts), ToEquatableOrNull(produces), ToEquatableOrNull(producesProblem), @@ -756,6 +762,7 @@ private static void GetAdditionalRequestHandlerAttributeValues( ref EquatableImmutableArray? authorizationPolicies, ref bool disableAntiforgery, ref bool allowAnonymous, + ref bool excludeFromDescription, ref List? accepts, ref List? produces, ref List? producesProblem, @@ -821,6 +828,9 @@ ref List? producesValidationProblem case $"global::{AllowAnonymousAttributeFullyQualifiedName}": allowAnonymous = true; break; + case "global::Microsoft.AspNetCore.Routing.ExcludeFromDescriptionAttribute": + excludeFromDescription = true; + break; case $"global::{ProducesProblemAttributeFullyQualifiedName}": { var statusCode = attribute.ConstructorArguments.Length > 0 && attribute.ConstructorArguments[0].Value is int producesProblemStatusCode @@ -1467,6 +1477,13 @@ private static void GenerateMapRequestHandler(StringBuilder source, RequestHandl source.Append(')'); } + if (requestHandler.Metadata.ExcludeFromDescription) + { + source.AppendLine(); + source.Append(continuationIndent); + source.Append(".ExcludeFromDescription()"); + } + if (requestHandler.Metadata.Tags is { Count: > 0 }) { source.AppendLine(); @@ -1623,6 +1640,8 @@ private static StringBuilder GetUseEndpointHandlersStringBuilder(ImmutableArray< cost += 24 + metadata.Summary.Length; if (metadata.Description is { Length: > 0 }) cost += 28 + metadata.Description.Length; + if (metadata.ExcludeFromDescription) + cost += 32; if (metadata.Tags is { Count: > 0 }) cost += metadata.Tags.Value.Sum(tag => 6 + tag.Length); @@ -1872,7 +1891,8 @@ private readonly record struct RequestHandlerMetadata( EquatableImmutableArray? Accepts, EquatableImmutableArray? Produces, EquatableImmutableArray? ProducesProblem, - EquatableImmutableArray? ProducesValidationProblem + EquatableImmutableArray? ProducesValidationProblem, + bool ExcludeFromDescription ); private readonly record struct AcceptsMetadata(string RequestType, string ContentType, EquatableImmutableArray? AdditionalContentTypes); diff --git a/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.MapAllAttributesAndHttpMethods_MapEndpointHandlers_WithNamespace.verified.txt b/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.MapAllAttributesAndHttpMethods_MapEndpointHandlers_WithNamespace.verified.txt index a70d5e9..42d7e07 100644 --- a/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.MapAllAttributesAndHttpMethods_MapEndpointHandlers_WithNamespace.verified.txt +++ b/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.MapAllAttributesAndHttpMethods_MapEndpointHandlers_WithNamespace.verified.txt @@ -53,6 +53,7 @@ internal static class EndpointRouteBuilderExtensions .WithName("GetComplex") .WithSummary("Gets complex data.") .WithDescription("Uses every supported attribute.") + .ExcludeFromDescription() .WithTags("Shared", "ClassLevel", "MethodLevel") .Accepts("application/xml", "text/xml") .Accepts("application/custom", "text/custom") diff --git a/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.MapAllAttributesAndHttpMethods_MapEndpointHandlers_WithoutNamespace.verified.txt b/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.MapAllAttributesAndHttpMethods_MapEndpointHandlers_WithoutNamespace.verified.txt index bcddd80..44f2ee6 100644 --- a/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.MapAllAttributesAndHttpMethods_MapEndpointHandlers_WithoutNamespace.verified.txt +++ b/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.MapAllAttributesAndHttpMethods_MapEndpointHandlers_WithoutNamespace.verified.txt @@ -53,6 +53,7 @@ internal static class EndpointRouteBuilderExtensions .WithName("GetComplex") .WithSummary("Gets complex data.") .WithDescription("Uses every supported attribute.") + .ExcludeFromDescription() .WithTags("Shared", "ClassLevel", "MethodLevel") .Accepts("application/xml", "text/xml") .Accepts("application/custom", "text/custom") diff --git a/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.cs b/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.cs index 2c3b70e..3dbe6e2 100644 --- a/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.cs +++ b/tests/GeneratedEndpoints.Tests/GeneratedEndpointsTests.cs @@ -119,6 +119,7 @@ public async Task MapAllAttributesAndHttpMethods(bool withNamespace) [Microsoft.AspNetCore.Generated.Attributes.ProducesResponse(typeof(ClassLevelResponse), 201, "application/json", "text/json")] [ProducesProblem(503, "application/problem+json")] [ProducesValidationProblem(409, "application/problem+json", "text/plain")] + [Microsoft.AspNetCore.Routing.ExcludeFromDescription] internal sealed class ComplexEndpoints { private readonly IServiceProvider _serviceProvider; @@ -141,6 +142,7 @@ public static void Configure(TBuilder builder, IServiceProvider servic [Microsoft.AspNetCore.Generated.Attributes.ProducesResponse(200, "application/json", "text/json")] [ProducesProblem(400, "application/problem+json", "text/plain")] [ProducesValidationProblem(422, "application/problem+json", "text/plain")] + [Microsoft.AspNetCore.Routing.ExcludeFromDescription] public async Task, NotFound>> GetComplex( [FromRoute] int id, [FromQuery] string? filter,