domaindrivendev / Swashbuckle.WebApi

Seamlessly adds a swagger to WebApi projects!
BSD 3-Clause "New" or "Revised" License
3.06k stars 679 forks source link

Disabling swagger-ui and generating api docs file? #89

Closed thj-dk closed 9 years ago

thj-dk commented 9 years ago

First of all I would like to say thank you for this great extension to Web API!

I would like to ask if it's possible to disable the swagger-ui but still make the swagger api docs available? And also if it's possible to generate a file containing the swagger api docs?

domaindrivendev commented 9 years ago

Thanks for the support.

Swashbuckle automatically adds both the UI routes - "/swagger/ui/{*uiPath)" and the raw doc routes - "swagger/api-docs/{resourceName}" to your API and there is currently no way to disable the ui routes. I will be releasing a new major version in the coming weeks which will have a lot of fundamental differences, in particular it will generate Swagger 2.0 instead of 1.2, and I'll certainly consider this as an additional feature.

With that said, WebApi has the necessary extension points to do this right now. You can add a HttpMessageHandler to the chain (see http://www.asp.net/web-api/overview/advanced/http-message-handlers). This will be be executed before any of the Swashbuckle handlers so you can inspect the incoming route and if it starts with "swagger/ui", short-circuit the request and return a 404 response.

Wrt to generating a file, Swagger 1.2 is composed of multiple JSON documents - an over all listing (available at /swagger/api-docs/) and then one or more API declarations (available at /swagger/api-docs/{resourceName}). You can point your browser to each of these routes and then just download the displayed JSON as a file.

In Swagger 2.0, the description is consolidated into a single JSON document which will make it a little easier.

thj-dk commented 9 years ago

Sounds great! Looking forward to the new version :-)