solidservices icon indicating copy to clipboard operation
solidservices copied to clipboard

Controllerless WebApi documentation with multiple xml doc files

Open timohayes opened this issue 7 years ago • 6 comments

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);

timohayes avatar Sep 14 '17 23:09 timohayes

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);
}

dotnetjunkie avatar Sep 15 '17 07:09 dotnetjunkie

Thanks, Steven. For some reason, only the last xml file seems to work (in Swagger only comments from the last assembly appear).

timohayes avatar Sep 15 '17 18:09 timohayes

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.

dotnetjunkie avatar Sep 17 '17 10:09 dotnetjunkie

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?

timohayes avatar Sep 18 '17 19:09 timohayes

I tested this locally, and it works. There's no naming convention. Not sure why it doesn't work in your case.

dotnetjunkie avatar Sep 18 '17 20:09 dotnetjunkie

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!

timohayes avatar Sep 19 '17 16:09 timohayes