developer9969
developer9969

Reputation: 5236

Swagger-Swashbuckle include xmlcomments from dependent dlls

I need to document an asp.net core web api and I m using swagger and swashbuckle.

I have looked around and I have found this link but it's old and does not work https://github.com/domaindrivendev/Swashbuckle/issues/93

Can somebody show/point me how i can include xml comments from another dll?

thanks

Upvotes: 6

Views: 3331

Answers (1)

Helder Sepulveda
Helder Sepulveda

Reputation: 17594

There are two versions of swashbuckle:

If the tags on this question are correct, your link is not to the version you are using, but still the solution offered should give you a good idea what you need to do.

You can include as many xml comments as you want with IncludeXmlComments that is still available on Swashbuckle.AspNetCore, see here:
Swashbuckle.AspNetCore.SwaggerGen/Application/SwaggerGenOptions.cs#L259

First you need to make sure that the xml comments you need are making it to the server as part of your deployment, otherwise Swashbuckle will not show what it is not there...



A solution could be to recursively loop looking for XML files and add them using the IncludeXmlComments, something like this:

public void IncludeAllXmlComments(string folder)
{
  if (!string.IsNullOrEmpty(folder))
  {
    foreach (var name in Directory.GetFiles(folder, "*.XML", SearchOption.AllDirectories))
    {
      IncludeXmlComments(filePath: name);
    }
  }
}

This sample code is just to give you an idea, not for copy/pasta

Upvotes: 6

Related Questions