Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swashbuckle - Add Model and Example values to Swagger UI from a Model from another project

I am using Swagger to document my .NET C# API and when my models are on another project Swagger just crashes and doesn't load anything.

When I load the sample WebAPI Project from Visual Studio it uses the models that are on the same project and it works:

Visual Studio Sample Project Example Image

But when I use Models from other project it just crashes before loading anything.

I have an API project and a Business Project. My models are View Models stored(and shared among other projects, therfore needed there) on my Buisiness Project.

Is there any way I can indicate to Swagger where my model definitions are?

like image 832
Bruno Di Giuseppe Avatar asked Aug 23 '16 22:08

Bruno Di Giuseppe


1 Answers

I faced same issue with Swashbuckle 5.6.0 and managed to fixed as follows. Enable XML documentation file on model objects containing project by changing project properties as follows.

enter image description here

Then go to SwaggerConfig.cs file of the api project and add xml comments file of model object project as follows.

c.IncludeXmlComments(string.Format(@"{0}\bin\WebApplication1.XML", System.AppDomain.CurrentDomain.BaseDirectory));
// New code line                            
c.IncludeXmlComments(string.Format(@"{0}\bin\core.XML", System.AppDomain.CurrentDomain.BaseDirectory));

Now you will have xml comments for model properties on swagger doc.

like image 138
Janith Widarshana Avatar answered Oct 29 '22 03:10

Janith Widarshana