How to show XML comments for external library assembly provided endpoints in SwashBuckle.ASP.NET Core library

Viewed 403

I have a ASP.NET Core application that serves it's own endpoints. I also have endpoints to manage basic application functionality (i.e. a health endpoint to check what the machine name is and if it's running locally or on a remote machine) which are provided by internal nuget packages. I currently am using Swashbuckle.AspNetCore to serve API documentation. Within my StartUp file I currently am able to include XML comments within the assembly of my web project like so:

services.AddSwaggerGen(gen =>
            {
                gen.IncludeXmlComments(
                    filePath: Path.Combine(AppContext.BaseDirectory, Assembly.GetEntryAssembly()!.GetName().Name + ".xml"),
                    includeControllerXmlComments: true
                    );
            });    

However this does not provide XML comments on routes provided by other libraries that my web project consume. These endpoints still are in my api doc (which I want), but ideally I'd also have xml comments as well. Any thoughts on how to achieve this?

2 Answers

I got the below comment from Swagger's official readme docs. It wroks.

NOTE: You can also provide Swagger Schema descriptions by annotating your API models and their properties with summary tags. If you have multiple XML comments files (e.g. separate libraries for controllers and models), you can invoke the IncludeXmlComments method multiple times and they will all be merged into the outputted Swagger JSON.

I created an extension method for my project that will pull the XML file and load it into Swagger here. You also need to make sure that your .NET Core project is generating an XML file. To check; right-click on your project, then Properties -> Build, then under Output make sure that XML documentation file location is set.

Related