Skip to content

Commit b138bde

Browse files
authored
Add support for response writing to RequestDelegateGenerator (dotnet#46291)
* Add support for response writing to RequestDelegateGenerator * React to feedback and add incrementality tests * Route patterns don't factor into incrementality check * Address feedback from review
1 parent 7976429 commit b138bde

File tree

46 files changed

+1805
-618
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1805
-618
lines changed

src/Framework/AspNetCoreAnalyzers/src/Analyzers/Http/HeaderDictionaryAddAnalyzer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace Microsoft.AspNetCore.Analyzers.Http;
1111

12+
using WellKnownType = WellKnownTypeData.WellKnownType;
13+
1214
[DiagnosticAnalyzer(LanguageNames.CSharp)]
1315
public sealed class HeaderDictionaryAddAnalyzer : DiagnosticAnalyzer
1416
{

src/Framework/AspNetCoreAnalyzers/src/Analyzers/Http/RequestDelegateReturnTypeAnalyzer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
namespace Microsoft.AspNetCore.Analyzers.Http;
1111

12+
using WellKnownType = WellKnownTypeData.WellKnownType;
13+
1214
[DiagnosticAnalyzer(LanguageNames.CSharp)]
1315
public partial class RequestDelegateReturnTypeAnalyzer : DiagnosticAnalyzer
1416
{

src/Framework/AspNetCoreAnalyzers/src/Analyzers/Infrastructure/ParsabilityHelper.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
namespace Microsoft.AspNetCore.Analyzers.Infrastructure;
1414

15+
using WellKnownType = WellKnownTypeData.WellKnownType;
16+
1517
internal static class ParsabilityHelper
1618
{
1719
private static bool IsTypeAlwaysParsableOrBindable(ITypeSymbol typeSymbol, WellKnownTypes wellKnownTypes)
@@ -160,7 +162,7 @@ internal static Bindability GetBindability(INamedTypeSymbol typeSymbol, WellKnow
160162
{
161163
return Bindability.InvalidReturnType;
162164
}
163-
165+
164166
}
165167

166168
return Bindability.NotBindable;
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace Microsoft.AspNetCore.App.Analyzers.Infrastructure;
5+
6+
internal static class WellKnownTypeData
7+
{
8+
public enum WellKnownType
9+
{
10+
Microsoft_AspNetCore_Components_Rendering_RenderTreeBuilder,
11+
Microsoft_AspNetCore_Http_IHeaderDictionary,
12+
Microsoft_AspNetCore_Http_Metadata_IFromBodyMetadata,
13+
Microsoft_AspNetCore_Http_Metadata_IFromFormMetadata,
14+
Microsoft_AspNetCore_Http_Metadata_IFromHeaderMetadata,
15+
Microsoft_AspNetCore_Http_Metadata_IFromQueryMetadata,
16+
Microsoft_AspNetCore_Http_Metadata_IFromServiceMetadata,
17+
Microsoft_AspNetCore_Http_Metadata_IFromRouteMetadata,
18+
Microsoft_AspNetCore_Http_HeaderDictionaryExtensions,
19+
Microsoft_AspNetCore_Routing_IEndpointRouteBuilder,
20+
Microsoft_AspNetCore_Mvc_ControllerAttribute,
21+
Microsoft_AspNetCore_Mvc_NonControllerAttribute,
22+
Microsoft_AspNetCore_Mvc_NonActionAttribute,
23+
Microsoft_AspNetCore_Http_AsParametersAttribute,
24+
System_Threading_CancellationToken,
25+
Microsoft_AspNetCore_Http_HttpContext,
26+
Microsoft_AspNetCore_Http_HttpRequest,
27+
Microsoft_AspNetCore_Http_HttpResponse,
28+
System_Security_Claims_ClaimsPrincipal,
29+
Microsoft_AspNetCore_Http_IFormFileCollection,
30+
Microsoft_AspNetCore_Http_IFormFile,
31+
System_IO_Stream,
32+
System_IO_Pipelines_PipeReader,
33+
System_IFormatProvider,
34+
System_Uri,
35+
Microsoft_AspNetCore_Builder_ConfigureHostBuilder,
36+
Microsoft_AspNetCore_Builder_ConfigureWebHostBuilder,
37+
Microsoft_Extensions_Hosting_GenericHostWebHostBuilderExtensions,
38+
Microsoft_AspNetCore_Hosting_WebHostBuilderExtensions,
39+
Microsoft_AspNetCore_Hosting_HostingAbstractionsWebHostBuilderExtensions,
40+
Microsoft_Extensions_Hosting_HostingHostBuilderExtensions,
41+
Microsoft_AspNetCore_Builder_EndpointRoutingApplicationBuilderExtensions,
42+
Microsoft_AspNetCore_Builder_WebApplication,
43+
Microsoft_AspNetCore_Builder_EndpointRouteBuilderExtensions,
44+
System_Delegate,
45+
Microsoft_AspNetCore_Mvc_ModelBinding_IBinderTypeProviderMetadata,
46+
Microsoft_AspNetCore_Mvc_BindAttribute,
47+
Microsoft_AspNetCore_Http_IResult,
48+
Microsoft_AspNetCore_Mvc_IActionResult,
49+
Microsoft_AspNetCore_Mvc_Infrastructure_IConvertToActionResult,
50+
Microsoft_AspNetCore_Http_RequestDelegate,
51+
System_Threading_Tasks_Task_T,
52+
System_Threading_Tasks_ValueTask_T,
53+
System_Reflection_ParameterInfo,
54+
Microsoft_AspNetCore_Http_IBindableFromHttpContext_T,
55+
System_IParsable_T,
56+
Microsoft_AspNetCore_Builder_AuthorizationEndpointConventionBuilderExtensions,
57+
Microsoft_AspNetCore_Http_OpenApiRouteHandlerBuilderExtensions,
58+
Microsoft_AspNetCore_Builder_CorsEndpointConventionBuilderExtensions,
59+
Microsoft_Extensions_DependencyInjection_OutputCacheConventionBuilderExtensions,
60+
Microsoft_AspNetCore_Builder_RateLimiterEndpointConventionBuilderExtensions,
61+
Microsoft_AspNetCore_Builder_RoutingEndpointConventionBuilderExtensions,
62+
Microsoft_AspNetCore_Mvc_RouteAttribute,
63+
Microsoft_AspNetCore_Mvc_HttpDeleteAttribute,
64+
Microsoft_AspNetCore_Mvc_HttpGetAttribute,
65+
Microsoft_AspNetCore_Mvc_HttpHeadAttribute,
66+
Microsoft_AspNetCore_Mvc_HttpOptionsAttribute,
67+
Microsoft_AspNetCore_Mvc_HttpPatchAttribute,
68+
Microsoft_AspNetCore_Mvc_HttpPostAttribute,
69+
Microsoft_AspNetCore_Mvc_HttpPutAttribute,
70+
Microsoft_AspNetCore_Http_EndpointDescriptionAttribute,
71+
Microsoft_AspNetCore_Http_EndpointSummaryAttribute,
72+
Microsoft_AspNetCore_Http_TagsAttribute,
73+
Microsoft_AspNetCore_Routing_EndpointGroupNameAttribute,
74+
Microsoft_AspNetCore_Routing_EndpointNameAttribute,
75+
Microsoft_AspNetCore_Routing_ExcludeFromDescriptionAttribute,
76+
Microsoft_AspNetCore_Cors_DisableCorsAttribute,
77+
Microsoft_AspNetCore_Cors_EnableCorsAttribute,
78+
Microsoft_AspNetCore_OutputCaching_OutputCacheAttribute,
79+
Microsoft_AspNetCore_RateLimiting_DisableRateLimitingAttribute,
80+
Microsoft_AspNetCore_RateLimiting_EnableRateLimitingAttribute,
81+
Microsoft_AspNetCore_Mvc_ActionNameAttribute,
82+
Microsoft_AspNetCore_Mvc_DisableRequestSizeLimitAttribute,
83+
Microsoft_AspNetCore_Mvc_FormatFilterAttribute,
84+
Microsoft_AspNetCore_Mvc_ProducesAttribute,
85+
Microsoft_AspNetCore_Mvc_ProducesDefaultResponseTypeAttribute,
86+
Microsoft_AspNetCore_Mvc_ProducesErrorResponseTypeAttribute,
87+
Microsoft_AspNetCore_Mvc_ProducesResponseTypeAttribute,
88+
Microsoft_AspNetCore_Mvc_RequestFormLimitsAttribute,
89+
Microsoft_AspNetCore_Mvc_RequestSizeLimitAttribute,
90+
Microsoft_AspNetCore_Mvc_RequireHttpsAttribute,
91+
Microsoft_AspNetCore_Mvc_ResponseCacheAttribute,
92+
Microsoft_AspNetCore_Mvc_ServiceFilterAttribute,
93+
Microsoft_AspNetCore_Mvc_TypeFilterAttribute,
94+
Microsoft_AspNetCore_Mvc_ApiExplorer_ApiConventionNameMatchAttribute,
95+
Microsoft_AspNetCore_Mvc_Filters_ResultFilterAttribute,
96+
Microsoft_AspNetCore_Mvc_Infrastructure_DefaultStatusCodeAttribute,
97+
Microsoft_AspNetCore_Mvc_AutoValidateAntiforgeryTokenAttribute,
98+
Microsoft_AspNetCore_Mvc_IgnoreAntiforgeryTokenAttribute,
99+
Microsoft_AspNetCore_Mvc_ViewFeatures_SaveTempDataAttribute,
100+
Microsoft_AspNetCore_Mvc_SkipStatusCodePagesAttribute,
101+
Microsoft_AspNetCore_Mvc_ValidateAntiForgeryTokenAttribute,
102+
Microsoft_AspNetCore_Authorization_AllowAnonymousAttribute,
103+
Microsoft_AspNetCore_Authorization_AuthorizeAttribute
104+
}
105+
106+
public static string[] WellKnownTypeNames = new[]
107+
{
108+
"Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder",
109+
"Microsoft.AspNetCore.Http.IHeaderDictionary",
110+
"Microsoft.AspNetCore.Http.Metadata.IFromBodyMetadata",
111+
"Microsoft.AspNetCore.Http.Metadata.IFromFormMetadata",
112+
"Microsoft.AspNetCore.Http.Metadata.IFromHeaderMetadata",
113+
"Microsoft.AspNetCore.Http.Metadata.IFromQueryMetadata",
114+
"Microsoft.AspNetCore.Http.Metadata.IFromServiceMetadata",
115+
"Microsoft.AspNetCore.Http.Metadata.IFromRouteMetadata",
116+
"Microsoft.AspNetCore.Http.HeaderDictionaryExtensions",
117+
"Microsoft.AspNetCore.Routing.IEndpointRouteBuilder",
118+
"Microsoft.AspNetCore.Mvc.ControllerAttribute",
119+
"Microsoft.AspNetCore.Mvc.NonControllerAttribute",
120+
"Microsoft.AspNetCore.Mvc.NonActionAttribute",
121+
"Microsoft.AspNetCore.Http.AsParametersAttribute",
122+
"System.Threading.CancellationToken",
123+
"Microsoft.AspNetCore.Http.HttpContext",
124+
"Microsoft.AspNetCore.Http.HttpRequest",
125+
"Microsoft.AspNetCore.Http.HttpResponse",
126+
"System.Security.Claims.ClaimsPrincipal",
127+
"Microsoft.AspNetCore.Http.IFormFileCollection",
128+
"Microsoft.AspNetCore.Http.IFormFile",
129+
"System.IO.Stream",
130+
"System.IO.Pipelines.PipeReader",
131+
"System.IFormatProvider",
132+
"System.Uri",
133+
"Microsoft.AspNetCore.Builder.ConfigureHostBuilder",
134+
"Microsoft.AspNetCore.Builder.ConfigureWebHostBuilder",
135+
"Microsoft.Extensions.Hosting.GenericHostWebHostBuilderExtensions",
136+
"Microsoft.AspNetCore.Hosting.WebHostBuilderExtensions",
137+
"Microsoft.AspNetCore.Hosting.HostingAbstractionsWebHostBuilderExtensions",
138+
"Microsoft.Extensions.Hosting.HostingHostBuilderExtensions",
139+
"Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions",
140+
"Microsoft.AspNetCore.Builder.WebApplication",
141+
"Microsoft.AspNetCore.Builder.EndpointRouteBuilderExtensions",
142+
"System.Delegate",
143+
"Microsoft.AspNetCore.Mvc.ModelBinding.IBinderTypeProviderMetadata",
144+
"Microsoft.AspNetCore.Mvc.BindAttribute",
145+
"Microsoft.AspNetCore.Http.IResult",
146+
"Microsoft.AspNetCore.Mvc.IActionResult",
147+
"Microsoft.AspNetCore.Mvc.Infrastructure.IConvertToActionResult",
148+
"Microsoft.AspNetCore.Http.RequestDelegate",
149+
"System.Threading.Tasks.Task`1",
150+
"System.Threading.Tasks.ValueTask`1",
151+
"System.Reflection.ParameterInfo",
152+
"Microsoft.AspNetCore.Http.IBindableFromHttpContext`1",
153+
"System.IParsable`1",
154+
"Microsoft.AspNetCore.Builder.AuthorizationEndpointConventionBuilderExtensions",
155+
"Microsoft.AspNetCore.Http.OpenApiRouteHandlerBuilderExtensions",
156+
"Microsoft.AspNetCore.Builder.CorsEndpointConventionBuilderExtensions",
157+
"Microsoft.Extensions.DependencyInjection.OutputCacheConventionBuilderExtensions",
158+
"Microsoft.AspNetCore.Builder.RateLimiterEndpointConventionBuilderExtensions",
159+
"Microsoft.AspNetCore.Builder.RoutingEndpointConventionBuilderExtensions",
160+
"Microsoft.AspNetCore.Mvc.RouteAttribute",
161+
"Microsoft.AspNetCore.Mvc.HttpDeleteAttribute",
162+
"Microsoft.AspNetCore.Mvc.HttpGetAttribute",
163+
"Microsoft.AspNetCore.Mvc.HttpHeadAttribute",
164+
"Microsoft.AspNetCore.Mvc.HttpOptionsAttribute",
165+
"Microsoft.AspNetCore.Mvc.HttpPatchAttribute",
166+
"Microsoft.AspNetCore.Mvc.HttpPostAttribute",
167+
"Microsoft.AspNetCore.Mvc.HttpPutAttribute",
168+
"Microsoft.AspNetCore.Http.EndpointDescriptionAttribute",
169+
"Microsoft.AspNetCore.Http.EndpointSummaryAttribute",
170+
"Microsoft.AspNetCore.Http.TagsAttribute",
171+
"Microsoft.AspNetCore.Routing.EndpointGroupNameAttribute",
172+
"Microsoft.AspNetCore.Routing.EndpointNameAttribute",
173+
"Microsoft.AspNetCore.Routing.ExcludeFromDescriptionAttribute",
174+
"Microsoft.AspNetCore.Cors.DisableCorsAttribute",
175+
"Microsoft.AspNetCore.Cors.EnableCorsAttribute",
176+
"Microsoft.AspNetCore.OutputCaching.OutputCacheAttribute",
177+
"Microsoft.AspNetCore.RateLimiting.DisableRateLimitingAttribute",
178+
"Microsoft.AspNetCore.RateLimiting.EnableRateLimitingAttribute",
179+
"Microsoft.AspNetCore.Mvc.ActionNameAttribute",
180+
"Microsoft.AspNetCore.Mvc.DisableRequestSizeLimitAttribute",
181+
"Microsoft.AspNetCore.Mvc.FormatFilterAttribute",
182+
"Microsoft.AspNetCore.Mvc.ProducesAttribute",
183+
"Microsoft.AspNetCore.Mvc.ProducesDefaultResponseTypeAttribute",
184+
"Microsoft.AspNetCore.Mvc.ProducesErrorResponseTypeAttribute",
185+
"Microsoft.AspNetCore.Mvc.ProducesResponseTypeAttribute",
186+
"Microsoft.AspNetCore.Mvc.RequestFormLimitsAttribute",
187+
"Microsoft.AspNetCore.Mvc.RequestSizeLimitAttribute",
188+
"Microsoft.AspNetCore.Mvc.RequireHttpsAttribute",
189+
"Microsoft.AspNetCore.Mvc.ResponseCacheAttribute",
190+
"Microsoft.AspNetCore.Mvc.ServiceFilterAttribute",
191+
"Microsoft.AspNetCore.Mvc.TypeFilterAttribute",
192+
"Microsoft.AspNetCore.Mvc.ApiExplorer.ApiConventionNameMatchAttribute",
193+
"Microsoft.AspNetCore.Mvc.Filters.ResultFilterAttribute",
194+
"Microsoft.AspNetCore.Mvc.Infrastructure.DefaultStatusCodeAttribute",
195+
"Microsoft.AspNetCore.Mvc.AutoValidateAntiforgeryTokenAttribute",
196+
"Microsoft.AspNetCore.Mvc.IgnoreAntiforgeryTokenAttribute",
197+
"Microsoft.AspNetCore.Mvc.ViewFeatures.SaveTempDataAttribute",
198+
"Microsoft.AspNetCore.Mvc.SkipStatusCodePagesAttribute",
199+
"Microsoft.AspNetCore.Mvc.ValidateAntiForgeryTokenAttribute",
200+
"Microsoft.AspNetCore.Authorization.AllowAnonymousAttribute",
201+
"Microsoft.AspNetCore.Authorization.AuthorizeAttribute"
202+
};
203+
}

0 commit comments

Comments
 (0)