Skip to content

refactor(api): migrate Swashbuckle to Scalar + chore(deps): upgrade NuGet packages#35

Merged
xavierjohn merged 2 commits into
mainfrom
xavierjohn/migrate-swagger-to-scalar
Jun 7, 2026
Merged

refactor(api): migrate Swashbuckle to Scalar + chore(deps): upgrade NuGet packages#35
xavierjohn merged 2 commits into
mainfrom
xavierjohn/migrate-swagger-to-scalar

Conversation

@xavierjohn

@xavierjohn xavierjohn commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

Migrate the API service from Swashbuckle (Swagger UI) to Microsoft.AspNetCore.OpenApi + Scalar, and refresh all NuGet packages to their latest stable versions.

Commits

  1. 6ee3353 refactor(api): migrate from Swashbuckle/Swagger UI to Microsoft.AspNetCore.OpenApi + Scalar
  2. aae3c2c chore(deps): upgrade NuGet packages to latest

Scalar migration

Packages

  • Swashbuckle.AspNetCore
  • Microsoft.AspNetCore.OpenApi (already centralised)
  • Scalar.AspNetCore 2.14.14

Files

  • 🗑️ Api/src/ConfigureSwaggerOptions.cs, Api/src/SwaggerDefaultValues.cs
  • Api/src/OpenApiDocumentTransformers.cs (VersionedInfoDocumentTransformer + BearerSecurityDocumentTransformer)
  • ✏️ Api/src/DependencyInjection.cs — new AddVersionedOpenApi() enumerates IApiVersionDescriptionProvider.ApiVersionDescriptions and registers one OpenAPI document per version with both transformers
  • ✏️ Api/src/Program.csUseSwagger() + UseSwaggerUI(...)MapOpenApi() + MapScalarApiReference(...); each version registered as a Scalar document, Bearer set as preferred security scheme
  • ✏️ Api/src/Properties/launchSettings.jsonlaunchUrl: ""scalar/"" on InMemory and CosmosDb profiles
  • ✏️ README.md — references Scalar instead of Swashbuckle/UseSwaggerUI()

XML doc comments still surface in the spec (GenerateDocumentationFile is on; Microsoft.AspNetCore.OpenApi discovers the XML file automatically).

Package upgrades

All packages bumped to latest stable, with three documented pins (inline comments in Directory.Packages.props):

  • Asp.Versioning.Mvc.ApiExplorer 8.1.0 — 8.1.1 has a confirmed Rfc7231ProblemDetailsWriter regression that hijacks problem-details writer ordering and silently drops bodies (dotnet/aspnet-api-versioning#1191, closed as fixed in 10.0.0). 10.x removes the wrapper but exposes a latent ASP.NET Core MVC issue (DefaultApiProblemDetailsWriter silently no-ops when IApiBehaviorMetadata is missing from endpoint metadata, which happens with this repo's <AssemblyAttribute Include=""...ApiController""/> setup). Tracked for a follow-up.
  • FluentAssertions 7.2.2 — v8.0+ switched to a paid commercial license (XCEED Software). 7.2.2 is the last MIT-licensed release.
  • Xunit.DependencyInjection 9.3.0 — v10+ switched to xunit.v3, which collides with xunit 2.x.

Bumped:
Azure.Identity 1.13.2 → 1.21.0, FluentValidation 11.3.0 → 12.1.1, Mapster / Mapster.DependencyInjection 7.4 / 1.0 → 10.0.7, Microsoft.AspNetCore.* 10.0.0 → 10.0.8, Microsoft.AspNetCore.OpenApi 10.0.7 → 10.0.8, Microsoft.Azure.Cosmos 3.46.1 → 3.61.0, Microsoft.Extensions.* 10.0.0 → 10.0.8, Nerdbank.GitVersioning 3.7 → 3.9.50, Newtonsoft.Json 13.0.3 → 13.0.4, System.IdentityModel.Tokens.Jwt 8.3.1 → 8.19.1, coverlet.collector 6.0.4 → 10.0.1, Microsoft.NET.Test.Sdk 17.10.0 → 18.6.0, xunit 2.8.0 → 2.9.3, xunit.runner.visualstudio 2.8.0 → 3.1.5, xunit.categories 2.0.8 → 3.0.1.

Verification

  • dotnet build: 0 warnings, 0 errors.
  • dotnet test: 122/122 pass (Domain 45 · Application 1 · Infrastructure 2 · Api 74), three consecutive runs.
  • Runtime smoke test:
    • GET /openapi/2022-10-01.json200 with info.title=Buber Dinner, components.securitySchemes.Bearer populated, global security: [{ Bearer: [] }].
    • GET /scalar/200 and references openapi/2022-10-01.json.
    • POST /authentication/login (bad creds) → 401 with proper application/problem+json body + WWW-Authenticate: Bearer.
    • POST /authentication/register (happy path) → JWT issued.

…tCore.OpenApi + Scalar

- Drop Swashbuckle.AspNetCore; add Microsoft.AspNetCore.OpenApi (10.0.7) and Scalar.AspNetCore (2.14.14).
- Delete ConfigureSwaggerOptions.cs and SwaggerDefaultValues.cs.
- New OpenApiDocumentTransformers.cs:
  - VersionedInfoDocumentTransformer: per-version OpenApiInfo (title, version, contact, license, deprecation/sunset text).
  - BearerSecurityDocumentTransformer: JWT Bearer scheme + document-wide security requirement.
- DependencyInjection.AddVersionedOpenApi enumerates IApiVersionDescriptionProvider.ApiVersionDescriptions and registers one OpenAPI document per version with both transformers.
- Program.cs: replace UseSwagger()/UseSwaggerUI(...) with MapOpenApi() + MapScalarApiReference(...); each version registered as a Scalar document, Bearer set as preferred security scheme.
- launchSettings.json: launchUrl set to scalar/ on InMemory and CosmosDb profiles.
- README: reference Scalar instead of Swashbuckle/UseSwaggerUI.

Verified: build clean (0/0), all 122 tests pass, GET /openapi/2022-10-01.json returns 200 with Bearer scheme + global requirement, GET /scalar/ renders against the right document.
Bumps all packages to their latest stable versions, with three documented pins:

- Asp.Versioning.Mvc.ApiExplorer 8.1.0 (was already pinned). 8.1.1 has a confirmed regression
  in the Rfc7231ProblemDetailsWriter wrapper that hijacks problem-details writer ordering and
  silently drops bodies (dotnet/aspnet-api-versioning#1191, fixed in 10.0.0). 10.x removes
  the wrapper but exposes a latent ASP.NET Core MVC issue with this repo's
  <AssemblyAttribute Include="...ApiController"/> setup — tracked for a follow-up PR.
- FluentAssertions 7.2.2: v8.0+ switched to a paid commercial license (XCEED Software).
  7.2.2 is the last MIT-licensed release.
- Xunit.DependencyInjection 9.3.0: v10+ switched to xunit.v3, which collides with xunit 2.x.

Bumped:
  Azure.Identity 1.13.2 -> 1.21.0
  FluentValidation 11.3.0 -> 12.1.1
  Mapster / Mapster.DependencyInjection 7.4 / 1.0 -> 10.0.7
  Microsoft.AspNetCore.Authentication.JwtBearer 10.0.0 -> 10.0.8
  Microsoft.AspNetCore.Mvc.Testing 10.0.0 -> 10.0.8
  Microsoft.AspNetCore.OpenApi 10.0.7 -> 10.0.8
  Microsoft.Azure.Cosmos 3.46.1 -> 3.61.0
  Microsoft.Extensions.Configuration 10.0.0 -> 10.0.8
  Microsoft.Extensions.Options.ConfigurationExtensions 10.0.0 -> 10.0.8
  Nerdbank.GitVersioning 3.7.115 -> 3.9.50
  Newtonsoft.Json 13.0.3 -> 13.0.4
  System.IdentityModel.Tokens.Jwt 8.3.1 -> 8.19.1
  coverlet.collector 6.0.4 -> 10.0.1
  Microsoft.NET.Test.Sdk 17.10.0 -> 18.6.0
  xunit 2.8.0 -> 2.9.3
  xunit.runner.visualstudio 2.8.0 -> 3.1.5
  xunit.categories 2.0.8 -> 3.0.1

Verified: 0 warnings, 0 errors, 122/122 tests pass.
@xavierjohn xavierjohn changed the title refactor(api): migrate from Swashbuckle/Swagger UI to Microsoft.AspNetCore.OpenApi + Scalar refactor(api): migrate Swashbuckle to Scalar + chore(deps): upgrade NuGet packages Jun 7, 2026
@xavierjohn xavierjohn merged commit dfd3182 into main Jun 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant