Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controllerless WebApi documentation with multiple xml doc files #14

Open
timohayes opened this issue Sep 14, 2017 · 6 comments
Open

Controllerless WebApi documentation with multiple xml doc files #14

timohayes opened this issue Sep 14, 2017 · 6 comments
Labels

Comments

@timohayes
Copy link

timohayes commented Sep 14, 2017

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);
@dotnetjunkie
Copy link
Owner

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

@timohayes
Copy link
Author

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

@dotnetjunkie
Copy link
Owner

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.

@timohayes
Copy link
Author

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?

@dotnetjunkie
Copy link
Owner

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

@timohayes
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants