0
votes

Starting a new project using web api 2, we want to separate the API it self from the MVC page that among other things holds the auto generated API documentation.

My approach was to create a empty web api project and create my controllers. Then I created another project (same solution) of type web api, but this time I included the MVC part. Then I deleted the web api controllers from the MVC project (because I only want it for documentation) and included a reference to the API project.

This works (almost) perfect, the api project exposes the resources and the MVC project shows the auto generated documentation for the endpoints.

Now here comes the problem: Because we include the api project in the MVCproject the MVC project automatically exposes the endpoints as well, this is absolutely not desired and needs to be removed, I tried removing GlobalConfiguration.Configure(WebApiConfig.Register); from application_start in global.asax, now the endpoints are not exposed (as desired) but the documentation is not generated as well.

Anybody have an idea on how to get past this problem? For sure others people has been wanting the same separation...

2
So... to sum up.... what I need is to disable all endpoints on the MVC project... - iCediCe

2 Answers

1
votes

You can create a global filter and in that you can redirect to api documentation endpoint if request is for mvc endpoint.

0
votes

To keep everything simple we went for a different solution, where a post script in our build triggers a external exe that generates static html pages for the api. The used program can be found here: https://code.msdn.microsoft.com/Design-time-help-page-3048fb43

This way we got a nice clean solution with no need to spin up a full MVC but still with auto generated documentation for the api.

The program did not quite match our needs but fortunately source code was available so I just customized it to our needs.