15

I am using the WebAPI Versioning package to version my API by the X-Api-Header by using the "VersionHeaderVersionedControllerSelector". I am also using the Microsoft.AspNet.WebApi.HelpPage to autogenerate documentation for the APIs. In order for controller versionign to work, they need to be namespaced with the VersionXYZ as the suffix in the namespace so that the "VersionHeaderVersionedControllerSelector" is able to route the request to the appropriate version of the controller like so:

namespace WEBAPI.Api.Controllers.Version1
{ public class ProductsController : ApiController {} }

namespace WEBAPI.Api.Controllers.Version2
{ public class ProductsController : ApiController {} }

This works as intended but when I look at the generated help pages the ApiDescription is including the "VersionXYZ" suffix from the namespace in the ID (GETapi/Version1.Products) and RelativePath(api/Version1.Products) properties. Ideally what I'd like to do is to have a top level help page which just the API Version numbers and drilling in would show the API the normal way i.e. The ApiDescription.ID = GETapi/Products and the ApiDescription.RelativePath = api/Products

Is there a way to achieve this using the Out of the Box APIs or am I going to need to rollout my own implementation of ApiExplorer

2
  • Did you ever find a solution to this problem? Commented Feb 19, 2014 at 15:42
  • Is it asp.net web api 2.0? Commented Jul 15, 2014 at 13:34

2 Answers 2

1

Check out this answer Get Help page works with Api Versioning

Make sure you have configure the versioning right, and you need to get a documentation XML file from your project XXXX.Api.v1 project and place it in the bin folder of the XXXX.Api project.

Sign up to request clarification or add additional context in comments.

Comments

0

Unfortunately ApiExplorer does not support duplicate controller names. So by implementing controller versioning this way, your (or the package code) doesn't play nicely with the system.

Consider another alternative where you actually change the controller name (and yes you will have to implement your own solution, but honestly its not that complex). For example make the version be part of the controller name itself (rather than its name space).

e.g. Ver1_ProcuctsController

Now these will start showing up on your help page, and since help page is just content package you can change the logic to make the names that start with verxxx_ to mutate.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.