Skip to content

Support API Version Using Namespace Convention #278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
commonsensesoftware opened this issue Apr 16, 2018 · 3 comments
Closed

Support API Version Using Namespace Convention #278

commonsensesoftware opened this issue Apr 16, 2018 · 3 comments
Assignees
Labels
Milestone

Comments

@commonsensesoftware
Copy link
Collaborator

commonsensesoftware commented Apr 16, 2018

Overview

It's a common scenario to use a namespace in the implementation of services as versioning boundary. By configuring API versioning to use this convention, any controller placed in a convention-based API version namespace will automatically have that API version applied.

Design

In order for the feature to work, the namespace name must still conform to the API version format so that it can be parsed. The language-neutral format in BNF will be:

'v' | 'V' : [<year> '-' <month> '-' <day>] : [<major[.minor]>] : [<status>]

Examples

  • Contoso.Api.v1.Controllers → 1.0
  • Contoso.Api.v1_1.Controllers → 1.1
  • Contoso.Api.v0_9_Beta.Controllers → 0.9-Beta
  • Contoso.Api.v20180401.Controllers → 2018-04-01
  • Contoso.Api.v2018_04_01.Controllers → 2018-04-01
  • Contoso.Api.v2018_04_01_Beta.Controllers → 2018-04-01-Beta
  • Contoso.Api.v2018_04_01_1_0_Beta.Controllers → 2018-04-01.1.0-Beta

By default, API versions will be considered supported. If the controller is decorated with the ObsoleteAttribute, then the API version inferred from the containing namespace will be considered deprecated.

Tooling Integration

Compilers such as Visual C# and Visual Basic use folders to automatically define namespace hierarchies. Tools such Visual Studio will attempt to convert invalid namespace names to their safe equivalents. Unfortunately, the . character is considered a namespace delimiter. This character should be changed to _ so that newly added files have the correct format. In addition, Visual Studio will add a leading _ if the folder name starts with a number. Since a leading character will be required, the format will require that the first character must be v or V.

Additional Considerations

The design should consider other types of conventions. This might be an extension of the existing convention features.

@commonsensesoftware commonsensesoftware self-assigned this Apr 16, 2018
@commonsensesoftware commonsensesoftware added this to the 3.0 milestone Apr 16, 2018
@commonsensesoftware commonsensesoftware changed the title [Feature] Support API Version Using Namespace Convention Support API Version Using Namespace Convention Apr 16, 2018
@dave-sampson13
Copy link

Hi @commonsensesoftware, is there an ETA for version 3.0 (pre-release or release)? Keen to use this enhancement in our projects.

@commonsensesoftware
Copy link
Collaborator Author

Things have progressed nicely. I might be able to squeeze out a beta by end of week for folks to start trying out. I'm testing out the routing changes to see how it affects other middleware. It's a rather slow and manual process. =/

To give those following this a sense of how this enhancement will work, you'll now be able to create and define your own conventions (a la the new IControllerConvention interface) in addition to the standard conventions. In this release, the only new convention will be the version by namespace convention. The setup will look like:

options => options.Conventions.Add( new VersionByNamespaceConvention() );

@surenderssm
Copy link

This was awesome, Thank you @commonsensesoftware !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants