feat(iwebapi): migrate OpenAPI generation to Microsoft.AspNetCore.OpenApi#627
Merged
Merged
Conversation
…nApi
Replace Swashbuckle's document generation with the built-in
Microsoft.AspNetCore.OpenApi generator and an IOpenApiDocumentTransformer,
keeping Swashbuckle Swagger UI as the frontend only.
- Add Microsoft.AspNetCore.OpenApi; swap the Swashbuckle.AspNetCore
meta-package for Swashbuckle.AspNetCore.SwaggerUI (UI only)
- Add AzureAdSecuritySchemeTransformer (OAuth2 scheme + global security
requirement), replacing the security setup in SwaggerGenConfigurator
- Register the document via a literal AddOpenApi("v1") call so the .NET 10
XML doc-comment source generator stays active; set title/version inline
- Serve the document with MapOpenApi() and point Swagger UI at
/openapi/{group}.json; drop AddEndpointsApiExplorer (minimal-APIs only)
- Delete SwaggerGenConfigurator; XML comments are now automatic
- Regenerate packages.lock.json
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Migrates the iwebapi .NET template’s OpenAPI document generation from Swashbuckle/SwaggerGen to the built-in Microsoft.AspNetCore.OpenApi generator (via AddOpenApi + MapOpenApi), while keeping Swashbuckle’s Swagger UI purely as a frontend renderer.
Changes:
- Switch OpenAPI document generation to
Microsoft.AspNetCore.OpenApiwith anIOpenApiDocumentTransformer. - Replace the Swashbuckle meta-package with
Swashbuckle.AspNetCore.SwaggerUIand repoint UI to/openapi/{group}.json. - Remove
SwaggerGenConfiguratorand introduceAzureAdSecuritySchemeTransformerfor Azure AD OAuth2 + security requirements.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| dotnet/iwebapi/Company.WebApplication1/Swagger/SwaggerUIConfigurator.cs | Updates Swagger UI to load docs from the new /openapi/{group}.json endpoint. |
| dotnet/iwebapi/Company.WebApplication1/Swagger/SwaggerGenConfigurator.cs | Removes SwaggerGen-based document configuration (no longer used). |
| dotnet/iwebapi/Company.WebApplication1/Swagger/AzureAdSecuritySchemeTransformer.cs | Adds a document transformer to inject Azure AD OAuth2 security scheme and requirements. |
| dotnet/iwebapi/Company.WebApplication1/Program.cs | Wires up AddOpenApi/MapOpenApi and removes SwaggerGen registration. |
| dotnet/iwebapi/Company.WebApplication1/packages.lock.json | Updates lockfile for the new OpenAPI/Swashbuckle package set. |
| dotnet/iwebapi/Company.WebApplication1/Company.WebApplication1.csproj | Adds Microsoft.AspNetCore.OpenApi and switches to Swashbuckle.AspNetCore.SwaggerUI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Set the Azure AD requirement once via document.Security instead of iterating every operation. This matches the original Swashbuckle AddSecurityRequirement behavior (global, top-level security), removes duplication, and preserves per-operation override semantics. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Thorstein Løkensgard (loekensgard)
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrates the iwebapi template from Swashbuckle's OpenAPI document generation to the built-in
Microsoft.AspNetCore.OpenApigenerator with anIOpenApiDocumentTransformer. Swashbuckle's Swagger UI is retained as the frontend only — it no longer generates the document, it just renders the one produced by the built-in generator.What changed
Microsoft.AspNetCore.OpenApi(10.0.8); replace the fullSwashbuckle.AspNetCoremeta-package withSwashbuckle.AspNetCore.SwaggerUI(UI only). BothAsp.Versioningpackages are retained (versioning engine + theGroupNamethe generator routes documents by).AzureAdSecuritySchemeTransformer: a DI-activated document transformer that adds the Azure AD OAuth2 scheme and a global per-operation security requirement — a direct port of the security setup fromSwaggerGenConfigurator.Program.cs: registers the document with a literalAddOpenApi("v1")call (literal name required so the .NET 10 XML doc-comment source generator stays active) and sets title/version inline; serves it withMapOpenApi()instead ofUseSwagger(). DroppedAddEndpointsApiExplorer()(minimal-APIs only; the template uses controllers).SwaggerUIConfigurator: repointed from/swagger/{group}/swagger.jsonto/openapi/{group}.json; dynamic version loop kept so the UI auto-discovers versions.SwaggerGenConfigurator: its security setup moved to the transformer; XML comments are now picked up automatically by the .NET 10 source generator; title/version moved inline.packages.lock.jsonregenerated (CI runslocked-mode: true).Test Plan
dotnet buildof the main project succeeds (only the pre-existingWeatherForecastnullability warning)./openapi/v1.json: correctinfotitle/version,Azure ADOAuth2 scheme, global security requirement on the operation, XML-sourced summary ("Retrieve weather forecast."), and the versioned path/api/v1/WeatherForecast.dotnet restore --locked-mode(linux-musl-x64) passes — lockfile consistent for CI.SwaggerGen,swagger.json, orAddEndpointsApiExplorerin the template.__PROJECT_PATH__); the existing tests (controller unit test + 401 integration test) are unaffected by this change and pass on an instantiated copy.🤖 Generated with Claude Code