PouryaKit.Web.OpenApi
API versions a Module declares, and one OpenAPI document for each.
API versions a Module declares, and one OpenAPI document for each. The Module declares its versions in its Composition Root, on Asp.Versioning's own version set, and each endpoint serves them on a versioned path and on the unversioned path, where a header selects the version. A deprecated version announces the sunset the Host configures, and the Scalar reference lists every document.
Install
dotnet add package PouryaKit.Web.OpenApi --prereleaseWhen to use it
- A Module's HTTP contract changes and existing clients must keep working.
- An endpoint exists only in some versions of its Module.
- You deprecate a version and announce the date it is meant to end.
- You serve one OpenAPI document per version and the Scalar reference over them.
It extends PouryaKit.Web. A Module that declares no version keeps the plain unversioned paths, in a Host with or without it; a Module that declares versions needs the Host to register it, or mapping its endpoints throws.
Quick start
Declare the Module's versions in its Composition Root, as the Proving Sample's Catalog does:
module.AddPouryaKitApiVersions(
"/catalog",
versions =>
versions
.HasDeprecatedApiVersion(new ApiVersion(1, 0))
.HasApiVersion(new ApiVersion(2, 0))
);Register the versions and their documents in the Host, and map the documents:
builder.Services.AddPouryaKitOpenApi();
builder.Services.Configure<PouryaKitOpenApiOptions>(
builder.Configuration.GetSection("PouryaKit:OpenApi")
);
app.MapPouryaKitOpenApi().AllowAnonymous();What you get
- Versions by URL segment and by header, on one endpoint.
- A deprecated version that announces its configured sunset.
- ASP.NET Core's own OpenAPI document for each version, and no Swagger generator.
- The Scalar API reference over them.
A version belongs to the Module, but its number is shared: versions of different Modules that share a number share one document and one sunset. A Module that joins a Host declares a version no other Module deprecates.