Skip to content

Commit ab949d5

Browse files
committed
Add initial validations generator for minimal APIs
1 parent f7ff82f commit ab949d5

File tree

81 files changed

+4847
-31
lines changed

Some content is hidden

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

81 files changed

+4847
-31
lines changed

AspNetCore.sln

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server
17321732
EndProject
17331733
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Tests", "src\Servers\Kestrel\Transport.NamedPipes\test\Microsoft.AspNetCore.Server.Kestrel.Transport.NamedPipes.Tests.csproj", "{97C7D2A4-87E5-4A4A-A170-D736427D5C21}"
17341734
EndProject
1735-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Http.RequestDelegateGenerator", "src\Http\Http.Extensions\gen\Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj", "{4730F56D-24EF-4BB2-AA75-862E31205F3A}"
1735+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Http.RequestDelegateGenerator", "src\Http\Http.Extensions\gen\RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj", "{4730F56D-24EF-4BB2-AA75-862E31205F3A}"
17361736
EndProject
17371737
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "QuickGrid", "QuickGrid", "{C406D9E0-1585-43F9-AA8F-D468AF84A996}"
17381738
EndProject
@@ -1812,6 +1812,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{2B858B
18121812
EndProject
18131813
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.App.Internal.Assets", "src\Assets\Microsoft.AspNetCore.App.Internal.Assets.csproj", "{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}"
18141814
EndProject
1815+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.Http.ValidationsGenerator", "src\Http\Http.Extensions\gen\ValidationsGenerator\Microsoft.AspNetCore.Http.ValidationsGenerator.csproj", "{185D74AB-76CE-44C1-86EB-16E93C84033F}"
1816+
EndProject
18151817
Global
18161818
GlobalSection(SolutionConfigurationPlatforms) = preSolution
18171819
Debug|Any CPU = Debug|Any CPU
@@ -10943,22 +10945,38 @@ Global
1094310945
{C3928C15-1836-46DB-A09D-9EFBCCA33E08}.Release|x64.Build.0 = Release|Any CPU
1094410946
{C3928C15-1836-46DB-A09D-9EFBCCA33E08}.Release|x86.ActiveCfg = Release|Any CPU
1094510947
{C3928C15-1836-46DB-A09D-9EFBCCA33E08}.Release|x86.Build.0 = Release|Any CPU
10946-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10947-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|Any CPU.Build.0 = Debug|Any CPU
10948-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|arm64.ActiveCfg = Debug|Any CPU
10949-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|arm64.Build.0 = Debug|Any CPU
10950-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x64.ActiveCfg = Debug|Any CPU
10951-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x64.Build.0 = Debug|Any CPU
10952-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x86.ActiveCfg = Debug|Any CPU
10953-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Debug|x86.Build.0 = Debug|Any CPU
10954-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|Any CPU.ActiveCfg = Release|Any CPU
10955-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|Any CPU.Build.0 = Release|Any CPU
10956-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|arm64.ActiveCfg = Release|Any CPU
10957-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|arm64.Build.0 = Release|Any CPU
10958-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x64.ActiveCfg = Release|Any CPU
10959-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x64.Build.0 = Release|Any CPU
10960-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x86.ActiveCfg = Release|Any CPU
10961-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62}.Release|x86.Build.0 = Release|Any CPU
10948+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10949+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Debug|Any CPU.Build.0 = Debug|Any CPU
10950+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Debug|arm64.ActiveCfg = Debug|Any CPU
10951+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Debug|arm64.Build.0 = Debug|Any CPU
10952+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Debug|x64.ActiveCfg = Debug|Any CPU
10953+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Debug|x64.Build.0 = Debug|Any CPU
10954+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Debug|x86.ActiveCfg = Debug|Any CPU
10955+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Debug|x86.Build.0 = Debug|Any CPU
10956+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Release|Any CPU.ActiveCfg = Release|Any CPU
10957+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Release|Any CPU.Build.0 = Release|Any CPU
10958+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Release|arm64.ActiveCfg = Release|Any CPU
10959+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Release|arm64.Build.0 = Release|Any CPU
10960+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Release|x64.ActiveCfg = Release|Any CPU
10961+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Release|x64.Build.0 = Release|Any CPU
10962+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Release|x86.ActiveCfg = Release|Any CPU
10963+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11}.Release|x86.Build.0 = Release|Any CPU
10964+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10965+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Debug|Any CPU.Build.0 = Debug|Any CPU
10966+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Debug|arm64.ActiveCfg = Debug|Any CPU
10967+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Debug|arm64.Build.0 = Debug|Any CPU
10968+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Debug|x64.ActiveCfg = Debug|Any CPU
10969+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Debug|x64.Build.0 = Debug|Any CPU
10970+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Debug|x86.ActiveCfg = Debug|Any CPU
10971+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Debug|x86.Build.0 = Debug|Any CPU
10972+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Release|Any CPU.ActiveCfg = Release|Any CPU
10973+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Release|Any CPU.Build.0 = Release|Any CPU
10974+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Release|arm64.ActiveCfg = Release|Any CPU
10975+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Release|arm64.Build.0 = Release|Any CPU
10976+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Release|x64.ActiveCfg = Release|Any CPU
10977+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Release|x64.Build.0 = Release|Any CPU
10978+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Release|x86.ActiveCfg = Release|Any CPU
10979+
{185D74AB-76CE-44C1-86EB-16E93C84033F}.Release|x86.Build.0 = Release|Any CPU
1096210980
EndGlobalSection
1096310981
GlobalSection(SolutionProperties) = preSolution
1096410982
HideSolutionNode = FALSE
@@ -11853,8 +11871,9 @@ Global
1185311871
{B32FF7A7-9CB3-4DCD-AE97-3B2594DB9DAC} = {2299CCD8-8F9C-4F2B-A633-9BF4DA81022B}
1185411872
{B9BBC1A8-7F58-4F43-94C3-5F3CB125CEF7} = {B32FF7A7-9CB3-4DCD-AE97-3B2594DB9DAC}
1185511873
{C3928C15-1836-46DB-A09D-9EFBCCA33E08} = {B5D98AEB-9409-4280-8225-9C1EC6A791B2}
11856-
{2B858B82-5F0B-4A24-B3C0-5E99149F70D6} = {017429CC-C5FB-48B4-9C46-034E29EE2F06}
11857-
{2AAE7819-BC3E-48F4-9CFA-5DD4CD5FFD62} = {2B858B82-5F0B-4A24-B3C0-5E99149F70D6}
11874+
{18A3AF88-D633-44E6-9407-3B2C708F7F64} = {225AEDCF-7162-4A86-AC74-06B84660B379}
11875+
{FB45AD76-D348-4F96-A8EE-71F61DC6DA11} = {18A3AF88-D633-44E6-9407-3B2C708F7F64}
11876+
{185D74AB-76CE-44C1-86EB-16E93C84033F} = {18A3AF88-D633-44E6-9407-3B2C708F7F64}
1185811877
EndGlobalSection
1185911878
GlobalSection(ExtensibilityGlobals) = postSolution
1186011879
SolutionGuid = {3E8720B3-DBDD-498C-B383-2CC32A054E8F}

eng/Dependencies.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ and are generated based on the last package release.
224224
<LatestPackageReference Include="Swashbuckle.AspNetCore" />
225225
<LatestPackageReference Include="System.Reactive.Linq" />
226226
<LatestPackageReference Include="Verify.Xunit" />
227+
<LatestPackageReference Include="Verify.SourceGenerators" />
227228
<LatestPackageReference Include="xunit.abstractions" />
228229
<LatestPackageReference Include="xunit.analyzers" />
229230
<LatestPackageReference Include="xunit.assert" />

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@
327327
<SystemReactiveLinqVersion>5.0.0</SystemReactiveLinqVersion>
328328
<SwashbuckleAspNetCoreVersion>6.6.2</SwashbuckleAspNetCoreVersion>
329329
<VerifyXunitVersion>19.14.0</VerifyXunitVersion>
330+
<VerifySourceGeneratorsVersion>2.2.0</VerifySourceGeneratorsVersion>
330331
<XunitAbstractionsVersion>2.0.3</XunitAbstractionsVersion>
331332
<XunitAnalyzersVersion>1.15.0</XunitAnalyzersVersion>
332333
<XunitVersion>2.9.2</XunitVersion>

eng/testing/linker/SupportFiles/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<ProjectReference Include="$(RepoRoot)src\SignalR\clients\csharp\Client\src\Microsoft.AspNetCore.SignalR.Client.csproj" />
7777
<ProjectReference Include="$(RepoRoot)src\SignalR\server\SignalR\src\Microsoft.AspNetCore.SignalR.csproj" />
7878
<ProjectReference Include="$(RepoRoot)src\OpenApi\src\Microsoft.AspNetCore.OpenApi.csproj" />
79-
<ProjectReference Include="$(RepoRoot)src\Http\Http.Extensions\gen\Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
79+
<ProjectReference Include="$(RepoRoot)src\Http\Http.Extensions\gen\RequestDelegateGenerator\Microsoft.AspNetCore.Http.RequestDelegateGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
8080
</ItemGroup>
8181

8282
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Builder.WebApplication.Conventions.get -> Microsoft.AspNetCore.Builder.IEndpointConventionBuilder!

src/DefaultBuilder/src/WebApplication.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ public sealed class WebApplication : IHost, IApplicationBuilder, IEndpointRouteB
2727
internal const string GlobalEndpointRouteBuilderKey = "__GlobalEndpointRouteBuilder";
2828

2929
private readonly IHost _host;
30-
private readonly List<EndpointDataSource> _dataSources = new();
30+
private readonly GlobalEndpointRouteBuilder _innerBuilder;
31+
private readonly RouteGroupBuilder _globalRouteGroup;
3132

3233
internal WebApplication(IHost host)
3334
{
3435
_host = host;
36+
_innerBuilder = new(this);
37+
_globalRouteGroup = _innerBuilder.MapGroup("");
3538
ApplicationBuilder = new ApplicationBuilder(host.Services, ServerFeatures);
3639
Logger = host.Services.GetRequiredService<ILoggerFactory>().CreateLogger(Environment.ApplicationName ?? nameof(WebApplication));
3740

38-
Properties[GlobalEndpointRouteBuilderKey] = this;
41+
Properties[GlobalEndpointRouteBuilderKey] = _innerBuilder;
3942
}
4043

4144
/// <summary>
@@ -80,9 +83,14 @@ IServiceProvider IApplicationBuilder.ApplicationServices
8083
internal IDictionary<string, object?> Properties => ApplicationBuilder.Properties;
8184
IDictionary<string, object?> IApplicationBuilder.Properties => Properties;
8285

83-
internal ICollection<EndpointDataSource> DataSources => _dataSources;
86+
internal ICollection<EndpointDataSource> DataSources => ((IEndpointRouteBuilder)_globalRouteGroup).DataSources;
8487
ICollection<EndpointDataSource> IEndpointRouteBuilder.DataSources => DataSources;
8588

89+
/// <summary>
90+
/// Gets the <see cref="IEndpointConventionBuilder"/> for the application.
91+
/// </summary>
92+
public IEndpointConventionBuilder Conventions => _globalRouteGroup;
93+
8694
internal ApplicationBuilder ApplicationBuilder { get; }
8795

8896
IServiceProvider IEndpointRouteBuilder.ServiceProvider => Services;
@@ -307,4 +315,13 @@ public IList<string>? Middleware
307315
}
308316
}
309317
}
318+
319+
private class GlobalEndpointRouteBuilder(WebApplication application) : IEndpointRouteBuilder
320+
{
321+
public IServiceProvider ServiceProvider => application.Services;
322+
323+
public ICollection<EndpointDataSource> DataSources { get; } = [];
324+
325+
public IApplicationBuilder CreateApplicationBuilder() => application;
326+
}
310327
}

src/DefaultBuilder/src/WebApplicationBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private void ConfigureApplication(WebHostBuilderContext context, IApplicationBui
408408
// destination.UseEndpoints()
409409

410410
// Set the route builder so that UseRouting will use the WebApplication as the IEndpointRouteBuilder for route matching
411-
app.Properties.Add(WebApplication.GlobalEndpointRouteBuilderKey, _builtApplication);
411+
app.Properties.Add(WebApplication.GlobalEndpointRouteBuilderKey, _builtApplication.Properties[WebApplication.GlobalEndpointRouteBuilderKey]);
412412

413413
// Only call UseRouting() if there are endpoints configured and UseRouting() wasn't called on the global route builder already
414414
if (_builtApplication.DataSources.Count > 0)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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.Http.Metadata;
5+
6+
/// <summary>
7+
/// A marker interface which can be used to identify metadata that disables validation
8+
/// for a specific endpoint.
9+
/// </summary>
10+
public interface IDisableValidationMetadata
11+
{
12+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#nullable enable
2+
Microsoft.AspNetCore.Http.Metadata.IDisableValidationMetadata
23
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.Description.get -> string?
34
Microsoft.AspNetCore.Http.ProducesResponseTypeMetadata.Description.set -> void
45
Microsoft.AspNetCore.Http.Metadata.IProducesResponseTypeMetadata.Description.get -> string?

0 commit comments

Comments
 (0)