Skip to content

Commit 9686f0e

Browse files
authored
(#314) Updated sample server to support OpenAPI 9.x (#393)
1 parent bdbcd23 commit 9686f0e

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

docs/in-depth/server/openapi/net9.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ Follow [the basic instructions for OpenApi integration](https://learn.microsoft.
1111

1212
using CommunityToolkit.Datasync.Server.OpenApi;
1313

14-
3. Add a service to generate an OpenAPI definition to your `Program.cs` file:
14+
3. Add services to generate an OpenAPI definition to your `Program.cs` file:
1515

16+
builder.Services.AddEndpointsApiExplorer();
1617
builder.Services.AddOpenApi(options => options.AddDatasyncTransformers());
1718

1819
4. Enable the middleware for serving the generated JSON document and the Swagger UI, also in `Program.cs`:
@@ -27,4 +28,4 @@ Browsing to the `/openapi/v1.json` endpoint of the web service allows you to dow
2728

2829
## Known issues
2930

30-
The .NET 9.x OpenApi support currently does not support dynamic schema generation. This means that the schema generated within the OpenApi document will be incomplete.
31+
The .NET 9.x OpenApi support currently does not support dynamic schema generation. This means that the schema generated within the OpenApi document will be incomplete.

samples/datasync-server/src/Sample.Datasync.Server/Controllers/TodoItemController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Sample.Datasync.Server.Controllers;
1111

1212
[Route("tables/[controller]")]
13+
[ApiExplorerSettings(IgnoreApi = false)]
1314
public class TodoItemController : TableController<TodoItem>
1415
{
1516
public TodoItemController(AppDbContext context)

samples/datasync-server/src/Sample.Datasync.Server/Controllers/TodoListController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace Sample.Datasync.Server.Controllers;
1111

1212
[Route("tables/[controller]")]
13+
[ApiExplorerSettings(IgnoreApi = false)]
1314
public class TodoListController : TableController<TodoList>
1415
{
1516
public TodoListController(AppDbContext context) : base(new EntityTableRepository<TodoList>(context))

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using CommunityToolkit.Datasync.Server.NSwag;
77
using CommunityToolkit.Datasync.Server.OpenApi;
88
using CommunityToolkit.Datasync.Server.Swashbuckle;
9+
using Microsoft.AspNetCore.Mvc;
910
using Microsoft.EntityFrameworkCore;
1011
using Sample.Datasync.Server.Db;
1112

@@ -36,6 +37,8 @@
3637

3738
if (openApiEnabled)
3839
{
40+
// Explicit API Explorer configuration
41+
_ = builder.Services.AddEndpointsApiExplorer();
3942
_ = builder.Services.AddOpenApi(options => options.AddDatasyncTransformers());
4043
}
4144

@@ -60,13 +63,13 @@
6063
_ = app.UseSwagger().UseSwaggerUI();
6164
}
6265

66+
app.UseAuthorization();
67+
app.MapControllers();
68+
6369
if (openApiEnabled)
6470
{
6571
_ = app.MapOpenApi(pattern: "swagger/{documentName}/swagger.json");
6672
_ = app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "Sample.Datasync.Server v1"));
6773
}
6874

69-
app.UseAuthorization();
70-
app.MapControllers();
71-
7275
app.Run();

samples/datasync-server/src/Sample.Datasync.Server/Sample.Datasync.Server.csproj

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,19 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="CommunityToolkit.Datasync.Server" Version="9.0.2" />
11-
<PackageReference Include="CommunityToolkit.Datasync.Server.EntityFrameworkCore" Version="9.0.2" />
12-
<PackageReference Include="CommunityToolkit.Datasync.Server.NSwag" Version="9.0.2" />
13-
<PackageReference Include="CommunityToolkit.Datasync.Server.OpenApi" Version="9.0.2" />
14-
<PackageReference Include="CommunityToolkit.Datasync.Server.Swashbuckle" Version="9.0.2" />
15-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5" />
16-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.5" />
17-
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.5">
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.7" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.7" />
12+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.7">
1813
<PrivateAssets>all</PrivateAssets>
1914
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2015
</PackageReference>
2116
</ItemGroup>
17+
18+
<ItemGroup>
19+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.EntityFrameworkCore\CommunityToolkit.Datasync.Server.EntityFrameworkCore.csproj" />
20+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.NSwag\CommunityToolkit.Datasync.Server.NSwag.csproj" />
21+
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.OpenApi\CommunityToolkit.Datasync.Server.OpenApi.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>
2225
</Project>

0 commit comments

Comments
 (0)