Skip to content

Commit

Permalink
Use OpenAPI package
Browse files Browse the repository at this point in the history
Migrate from NSwag to the new Microsoft.AspNetCore.OpenApi NuGet package.
  • Loading branch information
martincostello committed Jul 2, 2024
1 parent e2e3314 commit aa64487
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
13 changes: 8 additions & 5 deletions src/TodoApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
builder.Services.AddRazorPages();

// Configure OpenAPI documentation for the Todo API
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddOpenApiDocument(options =>
builder.Services.AddOpenApi(options =>
{
options.Title = "Todo API";
options.Version = "v1";
options.UseTransformer((document, _, _) =>
{
document.Info.Title = "Todo API";
document.Info.Version = "v1";
return Task.CompletedTask;
});

Check warning on line 27 in src/TodoApp/Program.cs

View check run for this annotation

Codecov / codecov/patch

src/TodoApp/Program.cs#L22-L27

Added lines #L22 - L27 were not covered by tests
});

if (string.Equals(builder.Configuration["CODESPACES"], "true", StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -57,7 +60,7 @@
app.UseAuthorization();

// Add endpoint for OpenAPI
app.UseOpenApi();
app.MapOpenApi();

// Add the HTTP endpoints
app.MapAuthenticationRoutes();
Expand Down
2 changes: 1 addition & 1 deletion src/TodoApp/TodoApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNet.Security.OAuth.GitHub" Version="8.1.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0-preview.5.24306.11" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0-preview.5.24306.3" />
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="5.5.3" PrivateAssets="all" />
<PackageReference Include="NSwag.AspNetCore" Version="14.0.8" />
</ItemGroup>
<ItemGroup>
<Content Update="package.json;package-lock.json;tsconfig.json" CopyToPublishDirectory="Never" />
Expand Down
2 changes: 1 addition & 1 deletion src/TodoApp/wwwroot/swagger-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<script>
window.onload = function () {
window.ui = SwaggerUIBundle({
url: "/swagger/v1/swagger.json",
url: "/openapi/v1.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [
Expand Down

0 comments on commit aa64487

Please sign in to comment.