Skip to content

Add support for response writing to RequestDelegateGenerator #46291

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

Merged
merged 4 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Microsoft.AspNetCore.Analyzers.Http;

using WellKnownType = WellKnownTypeData.WellKnownType;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class HeaderDictionaryAddAnalyzer : DiagnosticAnalyzer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Microsoft.AspNetCore.Analyzers.Http;

using WellKnownType = WellKnownTypeData.WellKnownType;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public partial class RequestDelegateReturnTypeAnalyzer : DiagnosticAnalyzer
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Microsoft.AspNetCore.Analyzers.Infrastructure;

using WellKnownType = WellKnownTypeData.WellKnownType;

internal static class ParsabilityHelper
{
private static bool IsTypeAlwaysParsableOrBindable(ITypeSymbol typeSymbol, WellKnownTypes wellKnownTypes)
Expand Down Expand Up @@ -160,7 +162,7 @@ internal static Bindability GetBindability(INamedTypeSymbol typeSymbol, WellKnow
{
return Bindability.InvalidReturnType;
}

}

return Bindability.NotBindable;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.AspNetCore.App.Analyzers.Infrastructure;

internal static class WellKnownTypeData
{
public enum WellKnownType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be nested?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily. It was largely a stylistic choice to put the associated data in the same class. To minimize the code delta, I ended up using an alias in the existing analyzers/codefixers but it felt nicer to capture these types in class instead of having them on the top-level namespace.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't leaving this unnested minimize the code delta by removing the using WellKnownType = WellKnownTypeData.WellKnownType;?

{
Microsoft_AspNetCore_Components_Rendering_RenderTreeBuilder,
Microsoft_AspNetCore_Http_IHeaderDictionary,
Microsoft_AspNetCore_Http_Metadata_IFromBodyMetadata,
Microsoft_AspNetCore_Http_Metadata_IFromFormMetadata,
Microsoft_AspNetCore_Http_Metadata_IFromHeaderMetadata,
Microsoft_AspNetCore_Http_Metadata_IFromQueryMetadata,
Microsoft_AspNetCore_Http_Metadata_IFromServiceMetadata,
Microsoft_AspNetCore_Http_Metadata_IFromRouteMetadata,
Microsoft_AspNetCore_Http_HeaderDictionaryExtensions,
Microsoft_AspNetCore_Routing_IEndpointRouteBuilder,
Microsoft_AspNetCore_Mvc_ControllerAttribute,
Microsoft_AspNetCore_Mvc_NonControllerAttribute,
Microsoft_AspNetCore_Mvc_NonActionAttribute,
Microsoft_AspNetCore_Http_AsParametersAttribute,
System_Threading_CancellationToken,
Microsoft_AspNetCore_Http_HttpContext,
Microsoft_AspNetCore_Http_HttpRequest,
Microsoft_AspNetCore_Http_HttpResponse,
System_Security_Claims_ClaimsPrincipal,
Microsoft_AspNetCore_Http_IFormFileCollection,
Microsoft_AspNetCore_Http_IFormFile,
System_IO_Stream,
System_IO_Pipelines_PipeReader,
System_IFormatProvider,
System_Uri,
Microsoft_AspNetCore_Builder_ConfigureHostBuilder,
Microsoft_AspNetCore_Builder_ConfigureWebHostBuilder,
Microsoft_Extensions_Hosting_GenericHostWebHostBuilderExtensions,
Microsoft_AspNetCore_Hosting_WebHostBuilderExtensions,
Microsoft_AspNetCore_Hosting_HostingAbstractionsWebHostBuilderExtensions,
Microsoft_Extensions_Hosting_HostingHostBuilderExtensions,
Microsoft_AspNetCore_Builder_EndpointRoutingApplicationBuilderExtensions,
Microsoft_AspNetCore_Builder_WebApplication,
Microsoft_AspNetCore_Builder_EndpointRouteBuilderExtensions,
System_Delegate,
Microsoft_AspNetCore_Mvc_ModelBinding_IBinderTypeProviderMetadata,
Microsoft_AspNetCore_Mvc_BindAttribute,
Microsoft_AspNetCore_Http_IResult,
Microsoft_AspNetCore_Mvc_IActionResult,
Microsoft_AspNetCore_Mvc_Infrastructure_IConvertToActionResult,
Microsoft_AspNetCore_Http_RequestDelegate,
System_Threading_Tasks_Task_T,
System_Threading_Tasks_ValueTask_T,
System_Reflection_ParameterInfo,
Microsoft_AspNetCore_Http_IBindableFromHttpContext_T,
System_IParsable_T,
Microsoft_AspNetCore_Builder_AuthorizationEndpointConventionBuilderExtensions,
Microsoft_AspNetCore_Http_OpenApiRouteHandlerBuilderExtensions,
Microsoft_AspNetCore_Builder_CorsEndpointConventionBuilderExtensions,
Microsoft_Extensions_DependencyInjection_OutputCacheConventionBuilderExtensions,
Microsoft_AspNetCore_Builder_RateLimiterEndpointConventionBuilderExtensions,
Microsoft_AspNetCore_Builder_RoutingEndpointConventionBuilderExtensions,
Microsoft_AspNetCore_Mvc_RouteAttribute,
Microsoft_AspNetCore_Mvc_HttpDeleteAttribute,
Microsoft_AspNetCore_Mvc_HttpGetAttribute,
Microsoft_AspNetCore_Mvc_HttpHeadAttribute,
Microsoft_AspNetCore_Mvc_HttpOptionsAttribute,
Microsoft_AspNetCore_Mvc_HttpPatchAttribute,
Microsoft_AspNetCore_Mvc_HttpPostAttribute,
Microsoft_AspNetCore_Mvc_HttpPutAttribute,
Microsoft_AspNetCore_Http_EndpointDescriptionAttribute,
Microsoft_AspNetCore_Http_EndpointSummaryAttribute,
Microsoft_AspNetCore_Http_TagsAttribute,
Microsoft_AspNetCore_Routing_EndpointGroupNameAttribute,
Microsoft_AspNetCore_Routing_EndpointNameAttribute,
Microsoft_AspNetCore_Routing_ExcludeFromDescriptionAttribute,
Microsoft_AspNetCore_Cors_DisableCorsAttribute,
Microsoft_AspNetCore_Cors_EnableCorsAttribute,
Microsoft_AspNetCore_OutputCaching_OutputCacheAttribute,
Microsoft_AspNetCore_RateLimiting_DisableRateLimitingAttribute,
Microsoft_AspNetCore_RateLimiting_EnableRateLimitingAttribute,
Microsoft_AspNetCore_Mvc_ActionNameAttribute,
Microsoft_AspNetCore_Mvc_DisableRequestSizeLimitAttribute,
Microsoft_AspNetCore_Mvc_FormatFilterAttribute,
Microsoft_AspNetCore_Mvc_ProducesAttribute,
Microsoft_AspNetCore_Mvc_ProducesDefaultResponseTypeAttribute,
Microsoft_AspNetCore_Mvc_ProducesErrorResponseTypeAttribute,
Microsoft_AspNetCore_Mvc_ProducesResponseTypeAttribute,
Microsoft_AspNetCore_Mvc_RequestFormLimitsAttribute,
Microsoft_AspNetCore_Mvc_RequestSizeLimitAttribute,
Microsoft_AspNetCore_Mvc_RequireHttpsAttribute,
Microsoft_AspNetCore_Mvc_ResponseCacheAttribute,
Microsoft_AspNetCore_Mvc_ServiceFilterAttribute,
Microsoft_AspNetCore_Mvc_TypeFilterAttribute,
Microsoft_AspNetCore_Mvc_ApiExplorer_ApiConventionNameMatchAttribute,
Microsoft_AspNetCore_Mvc_Filters_ResultFilterAttribute,
Microsoft_AspNetCore_Mvc_Infrastructure_DefaultStatusCodeAttribute,
Microsoft_AspNetCore_Mvc_AutoValidateAntiforgeryTokenAttribute,
Microsoft_AspNetCore_Mvc_IgnoreAntiforgeryTokenAttribute,
Microsoft_AspNetCore_Mvc_ViewFeatures_SaveTempDataAttribute,
Microsoft_AspNetCore_Mvc_SkipStatusCodePagesAttribute,
Microsoft_AspNetCore_Mvc_ValidateAntiForgeryTokenAttribute,
Microsoft_AspNetCore_Authorization_AllowAnonymousAttribute,
Microsoft_AspNetCore_Authorization_AuthorizeAttribute
}

public static string[] WellKnownTypeNames = new[]
{
"Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder",
"Microsoft.AspNetCore.Http.IHeaderDictionary",
"Microsoft.AspNetCore.Http.Metadata.IFromBodyMetadata",
"Microsoft.AspNetCore.Http.Metadata.IFromFormMetadata",
"Microsoft.AspNetCore.Http.Metadata.IFromHeaderMetadata",
"Microsoft.AspNetCore.Http.Metadata.IFromQueryMetadata",
"Microsoft.AspNetCore.Http.Metadata.IFromServiceMetadata",
"Microsoft.AspNetCore.Http.Metadata.IFromRouteMetadata",
"Microsoft.AspNetCore.Http.HeaderDictionaryExtensions",
"Microsoft.AspNetCore.Routing.IEndpointRouteBuilder",
"Microsoft.AspNetCore.Mvc.ControllerAttribute",
"Microsoft.AspNetCore.Mvc.NonControllerAttribute",
"Microsoft.AspNetCore.Mvc.NonActionAttribute",
"Microsoft.AspNetCore.Http.AsParametersAttribute",
"System.Threading.CancellationToken",
"Microsoft.AspNetCore.Http.HttpContext",
"Microsoft.AspNetCore.Http.HttpRequest",
"Microsoft.AspNetCore.Http.HttpResponse",
"System.Security.Claims.ClaimsPrincipal",
"Microsoft.AspNetCore.Http.IFormFileCollection",
"Microsoft.AspNetCore.Http.IFormFile",
"System.IO.Stream",
"System.IO.Pipelines.PipeReader",
"System.IFormatProvider",
"System.Uri",
"Microsoft.AspNetCore.Builder.ConfigureHostBuilder",
"Microsoft.AspNetCore.Builder.ConfigureWebHostBuilder",
"Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions",
"Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions",
"Microsoft.AspNetCore.Hosting.HostingAbstractionsWebHostBuilderExtensions",
"Microsoft.Extensions.Hosting.HostingHostBuilderExtensions",
"Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions",
"Microsoft.AspNetCore.Builder.WebApplication",
"Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions",
"System.Delegate",
"Microsoft.AspNetCore.Mvc.ModelBinding.IBinderTypeProviderMetadata",
"Microsoft.AspNetCore.Mvc.BindAttribute",
"Microsoft.AspNetCore.Http.IResult",
"Microsoft.AspNetCore.Mvc.IActionResult",
"Microsoft.AspNetCore.Mvc.Infrastructure.IConvertToActionResult",
"Microsoft.AspNetCore.Http.RequestDelegate",
"System.Threading.Tasks.Task`1",
"System.Threading.Tasks.ValueTask`1",
"System.Reflection.ParameterInfo",
"Microsoft.AspNetCore.Http.IBindableFromHttpContext`1",
"System.IParsable`1",
"Microsoft.AspNetCore.Builder.AuthorizationEndpointConventionBuilderExtensions",
"Microsoft.AspNetCore.Http.OpenApiRouteHandlerBuilderExtensions",
"Microsoft.AspNetCore.Builder.CorsEndpointConventionBuilderExtensions",
"Microsoft.Extensions.DependencyInjection.OutputCacheConventionBuilderExtensions",
"Microsoft.AspNetCore.Builder.RateLimiterEndpointConventionBuilderExtensions",
"Microsoft.AspNetCore.Builder.RoutingEndpointConventionBuilderExtensions",
"Microsoft.AspNetCore.Mvc.RouteAttribute",
"Microsoft.AspNetCore.Mvc.HttpDeleteAttribute",
"Microsoft.AspNetCore.Mvc.HttpGetAttribute",
"Microsoft.AspNetCore.Mvc.HttpHeadAttribute",
"Microsoft.AspNetCore.Mvc.HttpOptionsAttribute",
"Microsoft.AspNetCore.Mvc.HttpPatchAttribute",
"Microsoft.AspNetCore.Mvc.HttpPostAttribute",
"Microsoft.AspNetCore.Mvc.HttpPutAttribute",
"Microsoft.AspNetCore.Http.EndpointDescriptionAttribute",
"Microsoft.AspNetCore.Http.EndpointSummaryAttribute",
"Microsoft.AspNetCore.Http.TagsAttribute",
"Microsoft.AspNetCore.Routing.EndpointGroupNameAttribute",
"Microsoft.AspNetCore.Routing.EndpointNameAttribute",
"Microsoft.AspNetCore.Routing.ExcludeFromDescriptionAttribute",
"Microsoft.AspNetCore.Cors.DisableCorsAttribute",
"Microsoft.AspNetCore.Cors.EnableCorsAttribute",
"Microsoft.AspNetCore.OutputCaching.OutputCacheAttribute",
"Microsoft.AspNetCore.RateLimiting.DisableRateLimitingAttribute",
"Microsoft.AspNetCore.RateLimiting.EnableRateLimitingAttribute",
"Microsoft.AspNetCore.Mvc.ActionNameAttribute",
"Microsoft.AspNetCore.Mvc.DisableRequestSizeLimitAttribute",
"Microsoft.AspNetCore.Mvc.FormatFilterAttribute",
"Microsoft.AspNetCore.Mvc.ProducesAttribute",
"Microsoft.AspNetCore.Mvc.ProducesDefaultResponseTypeAttribute",
"Microsoft.AspNetCore.Mvc.ProducesErrorResponseTypeAttribute",
"Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute",
"Microsoft.AspNetCore.Mvc.RequestFormLimitsAttribute",
"Microsoft.AspNetCore.Mvc.RequestSizeLimitAttribute",
"Microsoft.AspNetCore.Mvc.RequireHttpsAttribute",
"Microsoft.AspNetCore.Mvc.ResponseCacheAttribute",
"Microsoft.AspNetCore.Mvc.ServiceFilterAttribute",
"Microsoft.AspNetCore.Mvc.TypeFilterAttribute",
"Microsoft.AspNetCore.Mvc.ApiExplorer.ApiConventionNameMatchAttribute",
"Microsoft.AspNetCore.Mvc.Filters.ResultFilterAttribute",
"Microsoft.AspNetCore.Mvc.Infrastructure.DefaultStatusCodeAttribute",
"Microsoft.AspNetCore.Mvc.AutoValidateAntiforgeryTokenAttribute",
"Microsoft.AspNetCore.Mvc.IgnoreAntiforgeryTokenAttribute",
"Microsoft.AspNetCore.Mvc.ViewFeatures.SaveTempDataAttribute",
"Microsoft.AspNetCore.Mvc.SkipStatusCodePagesAttribute",
"Microsoft.AspNetCore.Mvc.ValidateAntiForgeryTokenAttribute",
"Microsoft.AspNetCore.Authorization.AllowAnonymousAttribute",
"Microsoft.AspNetCore.Authorization.AuthorizeAttribute"
};
}
Loading