RouteVersioning.OpenApi
1.0.0-alpha.4
dotnet add package RouteVersioning.OpenApi --version 1.0.0-alpha.4
NuGet\Install-Package RouteVersioning.OpenApi -Version 1.0.0-alpha.4
<PackageReference Include="RouteVersioning.OpenApi" Version="1.0.0-alpha.4" />
<PackageVersion Include="RouteVersioning.OpenApi" Version="1.0.0-alpha.4" />
<PackageReference Include="RouteVersioning.OpenApi" />
paket add RouteVersioning.OpenApi --version 1.0.0-alpha.4
#r "nuget: RouteVersioning.OpenApi, 1.0.0-alpha.4"
#:package RouteVersioning.OpenApi@1.0.0-alpha.4
#addin nuget:?package=RouteVersioning.OpenApi&version=1.0.0-alpha.4&prerelease
#tool nuget:?package=RouteVersioning.OpenApi&version=1.0.0-alpha.4&prerelease
RouteVersioning.OpenApi
Versioned OpenAPI document generation for RouteVersioning.
Usage
Generating OpenAPI Documents
The default
Microsoft.AspNetCore.OpenApi
document includes all versioned APIs.services.AddOpenApi("current"); app.MapOpenApi(); // openapi/current.json includes: // api/v1/{a,d,e} // api/v2/{a,b,d,e} // api/v3/{a,b,c,e}
To exclude versioned operations from this document, use
ExcludeVersionedOperations()
.services.AddOpenApi("current", (options) => options .ExcludeVersionedOperations() );
Use
AddVersionedOpenApi
to add version-specific OpenAPI documents. To exclude unversioned endpoints from these documents, specifyincludeUnversionedEndpoints: false
.services.AddVersionedOpenApi(versions, includeUnversionedEndpoints: false); // openapi/v1.json includes api/v1/{a,d,e} // openapi/v2.json includes api/v2/{a,b,d,e} // openapi/v3.json includes api/v3/{a,b,c,e}
Use the configuration delegate of
RouteVersionSetBuilder.Version
to configure version-specific OpenAPI options.new RouteVersionSetBuilder<int>().Version(1, (v) => v .ConfigureOpenApiInfo((i) => i.Description = "v1 description") .ConfigureOpenApiOptions(...) );
Operations of retired API versions will be marked deprecated in version-specific OpenAPI documents. To do the same in other OpenAPI documents, use
MarkSunsettedOperations()
.services.AddOpenApi("current", (options) => options .MarkSunsettedOperations() );
Configuring OpenAPI UIs
Scalar.AspNetCore
uses the OpenAPI document specified in the path.// scalar/current // scalar/v1 // scalar/v2 // scalar/v3 app.MapScalarApiReference();
Swagger UI can be configured with URLs of all generated OpenAPI documents.
app.MapGet("swagger", () => { var urls = new[] { "current" } .Concat(versions.Select(versions.GetSlug)) .Select((name) => new { name, url = $"/openapi/{name}.json" }); return Results.Content(contentType: "text/html", content: $$""" <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style>body { margin: 0 }</style> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.18.2/swagger-ui.css" /> </head> <body> <div id="swagger-ui"></div> <script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.18.2/swagger-ui-bundle.js"></script> <script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5.18.2/swagger-ui-standalone-preset.js"></script> <script> SwaggerUIBundle({ urls: {{JsonSerializer.Serialize(urls)}}, dom_id: '#swagger-ui', presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset, ], layout: 'StandaloneLayout', }); </script> </body> </html> """ ); })
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Microsoft.AspNetCore.OpenApi (>= 9.0.1)
- RouteVersioning (>= 1.0.0-alpha.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0-alpha.4 | 70 | 1/27/2025 |
1.0.0-alpha.3 | 71 | 1/27/2025 |
1.0.0-alpha.2 | 81 | 1/25/2025 |
1.0.0-alpha.1 | 72 | 1/25/2025 |