Skip to content

(#314) Updated sample server to support OpenAPI 9.x #393

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 1 commit into from
Jul 16, 2025
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
5 changes: 3 additions & 2 deletions docs/in-depth/server/openapi/net9.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ Follow [the basic instructions for OpenApi integration](https://learn.microsoft.

using CommunityToolkit.Datasync.Server.OpenApi;

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

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddOpenApi(options => options.AddDatasyncTransformers());

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

## Known issues

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.
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.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Sample.Datasync.Server.Controllers;

[Route("tables/[controller]")]
[ApiExplorerSettings(IgnoreApi = false)]
public class TodoItemController : TableController<TodoItem>
{
public TodoItemController(AppDbContext context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Sample.Datasync.Server.Controllers;

[Route("tables/[controller]")]
[ApiExplorerSettings(IgnoreApi = false)]
public class TodoListController : TableController<TodoList>
{
public TodoListController(AppDbContext context) : base(new EntityTableRepository<TodoList>(context))
Expand Down
9 changes: 6 additions & 3 deletions samples/datasync-server/src/Sample.Datasync.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using CommunityToolkit.Datasync.Server.NSwag;
using CommunityToolkit.Datasync.Server.OpenApi;
using CommunityToolkit.Datasync.Server.Swashbuckle;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Sample.Datasync.Server.Db;

Expand Down Expand Up @@ -36,6 +37,8 @@

if (openApiEnabled)
{
// Explicit API Explorer configuration
_ = builder.Services.AddEndpointsApiExplorer();
_ = builder.Services.AddOpenApi(options => options.AddDatasyncTransformers());
}

Expand All @@ -60,13 +63,13 @@
_ = app.UseSwagger().UseSwaggerUI();
}

app.UseAuthorization();
app.MapControllers();

if (openApiEnabled)
{
_ = app.MapOpenApi(pattern: "swagger/{documentName}/swagger.json");
_ = app.UseSwaggerUI(options => options.SwaggerEndpoint("/swagger/v1/swagger.json", "Sample.Datasync.Server v1"));
}

app.UseAuthorization();
app.MapControllers();

app.Run();
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Datasync.Server" Version="9.0.2" />
<PackageReference Include="CommunityToolkit.Datasync.Server.EntityFrameworkCore" Version="9.0.2" />
<PackageReference Include="CommunityToolkit.Datasync.Server.NSwag" Version="9.0.2" />
<PackageReference Include="CommunityToolkit.Datasync.Server.OpenApi" Version="9.0.2" />
<PackageReference Include="CommunityToolkit.Datasync.Server.Swashbuckle" Version="9.0.2" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.5">
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.EntityFrameworkCore\CommunityToolkit.Datasync.Server.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.NSwag\CommunityToolkit.Datasync.Server.NSwag.csproj" />
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.OpenApi\CommunityToolkit.Datasync.Server.OpenApi.csproj" />
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server.Swashbuckle\CommunityToolkit.Datasync.Server.Swashbuckle.csproj" />
<ProjectReference Include="..\..\..\..\src\CommunityToolkit.Datasync.Server\CommunityToolkit.Datasync.Server.csproj" />
</ItemGroup>
</Project>