This library is an extension to the ASP.NET API versioning library of Microsoft addressing missing features on URL segment based versioning.
Be aware that this framework performs some initialization steps that might already be present in your startup sequence. Please ensure the following criterion are met:
- No
AddApiVersioning
call is made if you useAddApiVersioningWithUrlSupport
.AddApiVersioningWithUrlSupport
will internally call theAddApiVersioning
- No
MapHttpAttributeRoute
call is made if you useAddApiVersioningWithUrlSupport
.AddApiVersioningWithUrlSupport
will internally call theMapHttpAttributeRoute
with a custom route provider. - No custom controller selector is registered. ASP.net API versioning comes with a special controller selector handling all neccessary versioning rules.
It adds support for the following features.
Currently ASP.net API versioning cannot handle default version numbers for routes that have the API version in the URL segment. If you define a route
like /api/v{version}/Controller/Action
the AssumeDefaultVersionWhenUnspecified
option will not ensure that /api/Controller/Action
will point to the
action implementing the default version.
configuration.AddApiVersioningWithUrlSupport(o =>
{
o.VersioningOptions.DefaultApiVersion = new ApiVersion(3, 0);
o.VersioningOptions.AssumeDefaultVersionWhenUnspecified = true;
});
This extension is related to dotnet/aspnet-api-versioning#73
The default ApiExplorer implementation that comes with ASP.net Web API struggles generating the API descriptions for all versions. By providing a custom ApiExplorer implementation this library ensures that components using the ApiExplorer can access the individual versions. Note that also this extension focuses on URL segments and will not generate individual entries for Query String or Header based versioning.
configuration.AddApiVersioningAwareApiExplorer(o => {
// in combination with the "Default API version in URL segments" extension you might want to prevent the default version routes
// to be excluded from the API schema.
o.IncludeDefaultVersion = false;
// ASP.net API versioning supports /v3/ and /v3.0/ if you set this option to true
// the API schema will try to shorten the versions by omitting the minor version part.
o.PreferShortHandVersion = true;
});
This extension focuses on the compatibility with SwashBuckle and is related to dotnet/aspnet-api-versioning#60