How to include class and property descriptions in Swashbuckle generated Swagger docs for WebApi 2 with OWIN?
Hm... so maybe if someone else runs into this.
Basically I found one way this can be done and I realized why it was not done by default. Not sure if it is the best approach but here it goes.
In my solution, the POCOs are located in a project separate to the actual API and thus, the comment description of MyAwesomeModel
was not included because no XML nodes were generated for the classes and properties. So, in my separate project where the POCOs were located I modified properties to generate an XML.
- Generate XML for project where POCOs are located
- Make sure the XML is copied to whatever path you would like
Swashbuckle
to look for it. I usedPost-build event command line
in project properties;
copy "$(SolutionDir)MyAwesomeProjectWithPocos\bin\MyAwesomeProjectWithPocos.xml" "$(ProjectDir)\bin\MyAwesomeProjectWithPocos.xml"
- Modify
SwaggerConfig
to include this XML as well
I.e.
config.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "My Api Name");
c.OperationFilter<AddAuthorizationHeaderParameterOperationFilter>();
c.IncludeXmlComments(GetXmlCommentsPath());
c.IncludeXmlComments(GetXmlCommentsPathForModels());
}).EnableSwaggerUi(c => { });
Now, on the Swagger page, if I switch from Model Schema
to Model
I can now read the entire model and property descriptions.
Naturally, there is no demand to copy the XML file, one may just point to the correct location in step #3 GetXmlCommentsPathForModels());
but this was my option.