Skip to content

Commit bad7e1f

Browse files
authored
(#48) Support for .NET 9 OpenApi (basic support) (#265)
* (#48) Minimal support for .NET 9 OpenApi.
1 parent 4dc3bb8 commit bad7e1f

File tree

24 files changed

+2070
-121
lines changed

24 files changed

+2070
-121
lines changed

Datasync.Toolkit.sln

+14
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Datasync.S
6868
EndProject
6969
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Datasync.Server.MongoDB.Test", "tests\CommunityToolkit.Datasync.Server.MongoDB.Test\CommunityToolkit.Datasync.Server.MongoDB.Test.csproj", "{4FC45D20-0BA9-484B-9040-641687659AF6}"
7070
EndProject
71+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Datasync.Server.OpenApi.Test", "tests\CommunityToolkit.Datasync.Server.OpenApi.Test\CommunityToolkit.Datasync.Server.OpenApi.Test.csproj", "{99E727A3-8EB3-437E-AAC8-3596E8B9B2AE}"
72+
EndProject
73+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Datasync.Server.OpenApi", "src\CommunityToolkit.Datasync.Server.OpenApi\CommunityToolkit.Datasync.Server.OpenApi.csproj", "{505421EC-2598-4114-B2EC-997959B89E74}"
74+
EndProject
7175
Global
7276
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7377
Debug|Any CPU = Debug|Any CPU
@@ -166,6 +170,14 @@ Global
166170
{4FC45D20-0BA9-484B-9040-641687659AF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
167171
{4FC45D20-0BA9-484B-9040-641687659AF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
168172
{4FC45D20-0BA9-484B-9040-641687659AF6}.Release|Any CPU.Build.0 = Release|Any CPU
173+
{99E727A3-8EB3-437E-AAC8-3596E8B9B2AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
174+
{99E727A3-8EB3-437E-AAC8-3596E8B9B2AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
175+
{99E727A3-8EB3-437E-AAC8-3596E8B9B2AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
176+
{99E727A3-8EB3-437E-AAC8-3596E8B9B2AE}.Release|Any CPU.Build.0 = Release|Any CPU
177+
{505421EC-2598-4114-B2EC-997959B89E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
178+
{505421EC-2598-4114-B2EC-997959B89E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
179+
{505421EC-2598-4114-B2EC-997959B89E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
180+
{505421EC-2598-4114-B2EC-997959B89E74}.Release|Any CPU.Build.0 = Release|Any CPU
169181
EndGlobalSection
170182
GlobalSection(SolutionProperties) = preSolution
171183
HideSolutionNode = FALSE
@@ -194,6 +206,8 @@ Global
194206
{A9967817-2A2C-4C6D-A133-967A6062E9B3} = {75F709FD-8CC2-4558-A802-FE57086167C2}
195207
{DC20ACF9-12E9-41D9-B672-CB5FD85548E9} = {84AD662A-4B9E-4E64-834D-72529FB7FCE5}
196208
{4FC45D20-0BA9-484B-9040-641687659AF6} = {D59F1489-5D74-4F52-B78B-88037EAB2838}
209+
{99E727A3-8EB3-437E-AAC8-3596E8B9B2AE} = {D59F1489-5D74-4F52-B78B-88037EAB2838}
210+
{505421EC-2598-4114-B2EC-997959B89E74} = {84AD662A-4B9E-4E64-834D-72529FB7FCE5}
197211
EndGlobalSection
198212
GlobalSection(ExtensibilityGlobals) = postSolution
199213
SolutionGuid = {78A935E9-8F14-448A-BEDF-360FB742F14E}

Directory.Packages.props

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<PackageVersion Include="LiteDB" Version="5.0.21" />
1212
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.1" />
1313
<PackageVersion Include="Microsoft.AspNetCore.OData" Version="9.1.3" />
14+
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
1415
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
1516
<PackageVersion Include="Microsoft.EntityFrameworkCore.Cosmos" Version="9.0.1" />
1617
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="9.0.1" />

samples/datasync-server/src/Sample.Datasync.Server/Program.cs

+14-5
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,26 @@
1616
string? swaggerDriver = builder.Configuration["Swagger:Driver"];
1717
bool nswagEnabled = swaggerDriver?.Equals("NSwag", StringComparison.InvariantCultureIgnoreCase) == true;
1818
bool swashbuckleEnabled = swaggerDriver?.Equals("Swashbuckle", StringComparison.InvariantCultureIgnoreCase) == true;
19+
bool openApiEnabled = swaggerDriver?.Equals("NET9", StringComparison.InvariantCultureIgnoreCase) == true;
1920

2021
builder.Services.AddDbContext<AppDbContext>(options => options.UseSqlServer(connectionString));
2122
builder.Services.AddDatasyncServices();
2223
builder.Services.AddControllers();
2324

2425
if (nswagEnabled)
2526
{
26-
_ = builder.Services
27-
.AddOpenApiDocument(options => options.AddDatasyncProcessor());
27+
_ = builder.Services.AddOpenApiDocument(options => options.AddDatasyncProcessor());
2828
}
2929

3030
if (swashbuckleEnabled)
3131
{
32-
_ = builder.Services
33-
.AddEndpointsApiExplorer()
34-
.AddSwaggerGen(options => options.AddDatasyncControllers());
32+
_ = builder.Services.AddEndpointsApiExplorer();
33+
_ = builder.Services.AddSwaggerGen(options => options.AddDatasyncControllers());
34+
}
35+
36+
if (openApiEnabled)
37+
{
38+
_ = builder.Services.AddOpenApi();
3539
}
3640

3741
WebApplication app = builder.Build();
@@ -58,4 +62,9 @@
5862
app.UseAuthorization();
5963
app.MapControllers();
6064

65+
if (openApiEnabled)
66+
{
67+
_ = app.MapOpenApi(pattern: "swagger/{documentName}/swagger.json");
68+
}
69+
6170
app.Run();

samples/datasync-server/src/Sample.Datasync.Server/Properties/launchSettings.json

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
{
22
"$schema": "http://json.schemastore.org/launchsettings.json",
3-
"iisSettings": {
4-
"windowsAuthentication": false,
5-
"anonymousAuthentication": true,
6-
"iisExpress": {
7-
"applicationUrl": "http://localhost:48768",
8-
"sslPort": 44300
9-
}
10-
},
113
"profiles": {
124
"https": {
135
"commandName": "Project",
146
"dotnetRunMessages": true,
157
"launchBrowser": true,
16-
"launchUrl": "https://localhost:5001/tables/todoitem",
17-
"applicationUrl": "https://localhost:5001;http://localhost:5000",
18-
"environmentVariables": {
19-
"ASPNETCORE_ENVIRONMENT": "Development"
20-
},
21-
"sqlDebugging": true
22-
},
23-
"IIS Express": {
24-
"commandName": "IISExpress",
25-
"launchBrowser": true,
26-
"launchUrl": "https://localhost:44300/tables/todoitem",
8+
"launchUrl": "tables/todoitem",
9+
"applicationUrl": "https://localhost:5001",
2710
"environmentVariables": {
2811
"ASPNETCORE_ENVIRONMENT": "Development"
2912
},
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<Nullable>enable</Nullable>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<UserSecretsId>2fc55b72-4090-46ad-ae44-8b6a415339b8</UserSecretsId>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="CommunityToolkit.Datasync.Server" Version="8.0.4" />
11-
<PackageReference Include="CommunityToolkit.Datasync.Server.EntityFrameworkCore" Version="8.0.4" />
12-
<PackageReference Include="CommunityToolkit.Datasync.Server.NSwag" Version="8.0.4" />
13-
<PackageReference Include="CommunityToolkit.Datasync.Server.Swashbuckle" Version="8.0.4"/>
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.11" />
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.11">
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.1" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.1">
1613
<PrivateAssets>all</PrivateAssets>
1714
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1815
</PackageReference>
1916
</ItemGroup>
2017

18+
<ItemGroup>
19+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.Abstractions\CommunityToolkit.Datasync.Server.Abstractions.csproj" />
20+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.EntityFrameworkCore\CommunityToolkit.Datasync.Server.EntityFrameworkCore.csproj" />
21+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.NSwag\CommunityToolkit.Datasync.Server.NSwag.csproj" />
22+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.Swashbuckle\CommunityToolkit.Datasync.Server.Swashbuckle.csproj" />
23+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server\CommunityToolkit.Datasync.Server.csproj" />
24+
</ItemGroup>
25+
2126
</Project>

samples/datasync-server/src/Sample.Datasync.Server/appsettings.Development.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
}
77
},
88
"Swagger": {
9-
"Driver": "Swashbuckle"
9+
"Driver": "net9"
1010
}
1111
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Description>Provides necessary capabilities for supporting the Datasync server library when using the official OpenApi generator.</Description>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<InternalsVisibleTo Include="CommunityToolkit.Datasync.Server.OpenApi.Test" />
8+
</ItemGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\CommunityToolkit.Datasync.Server\CommunityToolkit.Datasync.Server.csproj" />
16+
</ItemGroup>
17+
</Project>

0 commit comments

Comments
 (0)