How to includeControllerXmlComments in Swagger .json files?

62 Views Asked by At

For my .net core 8.0 api project, I'm using Swashbuckle.AspNetCore 6.5.0 to .AddSwaggerGen() which generates and serves the a .json file at http://localhost:5229/swagger/my_api_name/swagger.json that I can browse at http://localhost:5229/swagger/index.html.

I want to inlcude the controller action ///<summary> comment as a summary under the end point.

However, the only way that I can see in the Swashbuckle Github repo is to include controller xmldocs is using

public static void IncludeXmlComments(
            this SwaggerGenOptions swaggerGenOptions,
            string filePath,
            bool includeControllerXmlComments = false)

I don't want to generate an XML file, how can I include the xmldoc comments in the .json file being generated?

1

There are 1 best solutions below

0
Denis Micheal On

I want to include the controller action ///<summary> comment as a summary under the end point.

This isn't possible without use of the Xml Document generated by the c# compiler.

Get started with Swashbuckle and ASP.NET Core

Some Swagger features (for example, schemata of input parameters or HTTP methods and response codes from the respective attributes) work without the use of an XML documentation file. For most features, namely method summaries and the descriptions of parameters and response codes, the use of an XML file is mandatory.

From the above, You will have to use the c# compiler to generate the xml documentation file (In order for Swashbuckle to pick up your endpoint descriptions in the <summary> element from the generated xml document) which is a painless process.

Simply enable GenerateDocumentationFile in your .csproj and configure Swagger to read the generated file.