-
Notifications
You must be signed in to change notification settings - Fork 12
Modernize OpenAPI generation #713
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
Draft
Copilot
wants to merge
9
commits into
master
Choose a base branch
from
copilot/implement-openapi-spec-generation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
244d0d1
feat(AspNetCore): add Microsoft OpenAPI path
Copilot 88cbeb4
docs(openapi): add Swashbuckle migration guide
Copilot 33c39e5
fix(openapi): support build-time document generation
Copilot 0e57b2a
fix(openapi): serve generated specs asynchronously
Copilot 627cef2
fix(openapi): apply validation review fixes
Copilot 809f6ed
fix(openapi): address review feedback
Copilot c8add99
fix(openapi): harden annotation transformers
Copilot 781f958
fix(openapi): migrate reference sample
Copilot 5c67854
fix(openapi): address validation feedback
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Migration from Swashbuckle to Microsoft OpenAPI | ||
|
|
||
| Ark.Tools now uses `Microsoft.AspNetCore.OpenApi` as the default generator in `ArkStartupWebApiCommon`. | ||
| Existing applications can keep the legacy Swashbuckle generator by overriding: | ||
|
|
||
| ```csharp | ||
| public override bool UseSwashbuckleOpenApi => true; | ||
| ``` | ||
|
|
||
| Swagger UI and Redoc are still hosted by the API and read the same `/swagger/docs/{documentName}` specification route. | ||
| The route first serves build-generated JSON when present and falls back to runtime generation for development and tests. | ||
|
|
||
| ## Build-time generation | ||
|
|
||
| Application projects that use the Microsoft OpenAPI path should reference `Microsoft.Extensions.ApiDescription.Server`. | ||
| This enables OpenAPI JSON generation during normal `dotnet build`. | ||
|
|
||
| Recommended project settings: | ||
|
|
||
| ```xml | ||
| <PropertyGroup> | ||
| <OpenApiDocumentsDirectory>$(OutputPath)</OpenApiDocumentsDirectory> | ||
| <OpenApiGenerateDocumentsOptions>--openapi-version OpenApi3_1</OpenApiGenerateDocumentsOptions> | ||
| </PropertyGroup> | ||
| ``` | ||
|
|
||
| Build-time generation starts the application entry point with a mock server. | ||
| Guard startup code that performs external side effects, migrations, outbound calls, or hosted background work during document generation. | ||
|
|
||
| ## Swashbuckle attributes | ||
|
|
||
| Swashbuckle-specific attributes are not interpreted automatically by Microsoft OpenAPI. | ||
| Prefer ASP.NET Core metadata, XML comments, and Ark.Tools/Microsoft OpenAPI transformers for new code. | ||
|
|
||
| | Swashbuckle attribute | Recommended replacement | Notes | | ||
| | --- | --- | --- | | ||
| | `SwaggerOperationAttribute` | XML comments or endpoint metadata transformed by `IOpenApiOperationTransformer` | Use for summary, description, tags, and operation-specific metadata. | | ||
|
AndreaCuneo marked this conversation as resolved.
Outdated
|
||
| | `SwaggerResponseAttribute` | ASP.NET Core `ProducesResponseTypeAttribute` | Microsoft OpenAPI reads ApiExplorer response metadata. | | ||
|
AndreaCuneo marked this conversation as resolved.
Outdated
|
||
| | `SwaggerParameterAttribute` | XML comments, `FromQuery`/`FromRoute` metadata, or an operation transformer | Use native binding metadata for required and source information. | | ||
| | `SwaggerRequestBodyAttribute` | ASP.NET Core request metadata plus XML comments or an operation transformer | Prefer deterministic transformers for examples and descriptions. | | ||
| | `SwaggerSchemaAttribute` | System.Text.Json metadata, XML comments, or `IOpenApiSchemaTransformer` | Swashbuckle schema filters remain legacy-only. | | ||
| | `SwaggerTagAttribute` | Controller/action grouping metadata or document/operation transformers | Use generator-neutral tag metadata where possible. | | ||
| | `SwaggerSchemaFilterAttribute` | `IOpenApiSchemaTransformer` | Treat this as Swashbuckle-only during the transition. | | ||
|
|
||
| ## Swashbuckle filters | ||
|
|
||
| | Swashbuckle extension point | Microsoft OpenAPI replacement | | ||
| | --- | --- | | ||
| | `IDocumentFilter` | `IOpenApiDocumentTransformer` | | ||
| | `IOperationFilter` | `IOpenApiOperationTransformer` | | ||
| | `ISchemaFilter` | `IOpenApiSchemaTransformer` | | ||
| | `IExamplesProvider<T>` from `Swashbuckle.AspNetCore.Filters` | Prefer a generator-neutral example model or an operation/schema transformer that writes examples deterministically. | | ||
|
|
||
| Current Ark.Tools defaults provide Microsoft OpenAPI equivalents for default problem responses, NodaTime schema formats, flags enum query parameters, OData media type cleanup, versioned document selection, and stable operation IDs. | ||
|
|
||
| ## Compatibility guidance | ||
|
|
||
| - Use the Microsoft OpenAPI default for new applications. | ||
| - Override `UseSwashbuckleOpenApi` only when existing Swashbuckle filters or attributes cannot be migrated immediately. | ||
| - Keep Swagger UI and Redoc pointed at `/swagger/docs/{documentName}` so UI routes do not change while the generator changes. | ||
| - Move custom Swashbuckle filters to generator-neutral Ark.Tools options or Microsoft OpenAPI transformers before the .NET 12 removal window. | ||
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,8 @@ public Startup(IConfiguration configuration, IHostEnvironment env) | |
|
|
||
| public override IEnumerable<ApiVersion> Versions => ApiVersions.All; | ||
|
|
||
| public override bool UseSwashbuckleOpenApi => HostEnvironment.IsEnvironment("IntegrationTests"); | ||
|
|
||
| public override OpenApiInfo MakeInfo(ApiVersion version) | ||
| => new() | ||
| { | ||
|
|
@@ -48,6 +50,11 @@ public override void ConfigureServices(IServiceCollection services) | |
| { | ||
| base.ConfigureServices(services); | ||
|
|
||
| foreach (var version in Versions) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be in base class and guarded based on the OpenApi enablement |
||
| { | ||
| services.AddOpenApi($"v{version.ToString("VVVV", CultureInfo.InvariantCulture)}"); | ||
| } | ||
|
|
||
| var auth0Scheme = "Auth0"; | ||
| var audience = "Audience"; | ||
| var domain = "Domain"; | ||
|
|
@@ -178,4 +185,4 @@ protected override void RegisterContainer(IServiceProvider services) | |
| var apiHost = new ApiHost(cfg) | ||
| .WithContainer(Container); | ||
| } | ||
| } | ||
| } | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.