RouteVersioning.OpenApi 1.0.0-alpha.4

This is a prerelease version of RouteVersioning.OpenApi.
dotnet add package RouteVersioning.OpenApi --version 1.0.0-alpha.4
                    
NuGet\Install-Package RouteVersioning.OpenApi -Version 1.0.0-alpha.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RouteVersioning.OpenApi" Version="1.0.0-alpha.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RouteVersioning.OpenApi" Version="1.0.0-alpha.4" />
                    
Directory.Packages.props
<PackageReference Include="RouteVersioning.OpenApi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RouteVersioning.OpenApi --version 1.0.0-alpha.4
                    
#r "nuget: RouteVersioning.OpenApi, 1.0.0-alpha.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RouteVersioning.OpenApi@1.0.0-alpha.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RouteVersioning.OpenApi&version=1.0.0-alpha.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=RouteVersioning.OpenApi&version=1.0.0-alpha.4&prerelease
                    
Install as a Cake Tool

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, specify includeUnversionedEndpoints: 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>
      	"""
      );
    })
    

    alternate text is missing from this package README image

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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