Skip to content

Danielku15/aspnet-url-versioning

Repository files navigation

Build status

ASP.net API Versioning - URL segment extensions

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 use AddApiVersioningWithUrlSupport. AddApiVersioningWithUrlSupport will internally call the AddApiVersioning
  • No MapHttpAttributeRoutecall is made if you use AddApiVersioningWithUrlSupport. AddApiVersioningWithUrlSupport will internally call the MapHttpAttributeRoute 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.

Default API version in URL segments

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

ApiExplorer implementation for SwashBuckle compatibility.

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

About

Extends aspnet-api-versioning with URL focused versioning features

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published