3

Is it possible to generate a Swagger documentation for my ASP.Net Web API in a separate project?

I created an empty project where the Swagger documentation should go. In the API project the Swagger project is referenced, but didn't work. Than API project is load like an external assembly. The controllers was reachable, but documentation wasn't generated.

Then tried with the automatically generated XML documenatation, just to see if it will create anything, but there is no result.

After this try like to have multiple API in one Swagger documentation, Multiple API documentation in one Swagger file, wasn't work.

I also tried this:

On the Swagger official documentation I didn't find something that could help me with this. Neither did I find any information elsewhere if this is possible and how it needs to be done.

I use Swashbuckle 5.6.0 and ASP.Net Web API.

Remy
  • 12,555
  • 14
  • 64
  • 104
Ivan
  • 105
  • 2
  • 8
  • All things are possible - it just depends on how much work you're willing to put in. What have you tried, and what prevented it from working? – mason Aug 23 '18 at 14:51
  • I try to create new project with Swagger, then load my API project in it, first like reference, it didn't work, then I use Assembly.LoadFrom,to be sure that everything is load properly. From debugger I can see all my controllers, but can not generate documentation. I try this too: https://stackoverflow.com/questions/51080805/multiple-api-documentation-in-one-swagger-file, to create new empty API project, and put swagger in it, and to create multiple swagger documentation, didn't work – Ivan Aug 23 '18 at 15:05
  • You may need to generate XML documentation and include it by calling IncludeXmlComments as described here: https://stackoverflow.com/questions/33914842/swagger-ui-returns-500-after-deployment – Joe Aug 27 '18 at 06:32
  • @Remy or Ivan, Can you provide a sample project reproducing this issue? – Helder Sepulveda Aug 27 '18 at 13:11

1 Answers1

3

Yes, it is possible to generate Swagger documentation for a Web API in a separate project.

Here I have the code showing how I did it:
https://github.com/heldersepu/csharp-proj/tree/master/Swashbuckle.Sample

And here is how the swagger-ui looks like: http://swashbucklesample.azurewebsites.net/swagger/ui/index

To be honest Nothing special about that code, it worked on the first try for me ...
But I do have some experience with Swashbuckle


If you can provide a minimal project reproducing your issue, we can help you get to the bottom of it together.

Helder Sepulveda
  • 15,500
  • 4
  • 29
  • 56
  • This is part of the puzzle I missed. private static void MapRoutes(this HttpConfiguration config) { APIISample.WebApiConfig.Register(config); } Thank you – Ivan Aug 28 '18 at 08:21
  • @Ivan I'm glad I was able to help! ... in the future please include a minimal project reproducing your issues, read more about that here: https://stackoverflow.com/help/mcve – Helder Sepulveda Aug 28 '18 at 12:44