solidservices
solidservices copied to clipboard
Controllerless WebApi documentation with multiple xml doc files
Great work here! One question, regarding your Controllerless API library and xml doc files...
I see that you are copying the xml documentation file to the App_Data directory of the web api project in a post-build step. I have separated out my commands/queries into separate class libraries to facilitate re-use. In that case, how can I get the api explorer to see my xml comments from multiple assemblies? If the ControllerlessActionFilter took an array of xml doc files, it would be perfect. Perhaps something like below? Have you worked around this already?
var appDataPath = HostingEnvironment.MapPath("~/App_Data");
var xmlDocFiles = Directory.GetFiles(appDataPath, "*.xml").ToList();
foreach(var xmlFile in xmlDocFiles)
{
c.IncludeXmlComments(xmlFile);
}
var filter = new ControllerlessActionOperationFilter(xmlDocFiles);
c.OperationFilter(() => filter);
You can already achieve this by doing the following:
var appDataPath = HostingEnvironment.MapPath("~/App_Data");
var xmlCommentsPaths = Directory.GetFiles(appDataPath, "*.xml");
foreach (string xmlCommentsPath in xmlCommentsPaths)
{
c.IncludeXmlComments(xmlCommentsPath);
var filter = new ControllerlessActionOperationFilter(xmlCommentsPath);
c.OperationFilter(() => filter);
}
Thanks, Steven. For some reason, only the last xml file seems to work (in Swagger only comments from the last assembly appear).
Hi @timohayes,
You are right. After some testing I was able to reproduce this. The SwaggerDocsConfig.OperationFilter
method seems to favor the last applied filter. I pushed a new version of the SwaggerConfig.cs
that fixes this problem.
Thanks! I made the same changes to my project's SwaggerConfig, but for some reason it still doesn't work. I only see comments from the last xml file that is added. Is there any kind of naming convention required for the command/query/DTO assemblies?
I tested this locally, and it works. There's no naming convention. Not sure why it doesn't work in your case.
Strange, I even tried pulling your SolidServices solution and added a new Command/Query project to that solution, and it didn't work for me. I'm guessing this is probably an issue w/ Swashbuckle. When I get time, I'll try to debug it to see where the problem lies. Thanks again!