Using the following configuration, I do not see Model class/property documentation.
private static void ConfigureSwagger(IServiceCollection services)
{
services.AddSwaggerGen(
c =>
{
c.SwaggerDoc(
"theName", new Info
{
Title = "theTitle",
Contact = new Contact { Name = "me", Email = "[email protected]" }
});
var basePath = AppContext.BaseDirectory;
var xmlPath = Path.Combine(basePath, "TheDocFile.xml");
c.IncludeXmlComments(xmlPath);
});
}
it's still broke. Models have no comments.
In my case, it was because my models are in a different project.
I added another call and it works:
c.IncludeXmlComments(xmlPath2); // add Other proj xml comments, this is needed because it's in a different project.
In my case, it was because my models are in a different project.
I added another call and it works:
c.IncludeXmlComments(xmlPath2); // add Other proj xml comments, this is needed because it's in a different project.
I am having same issue.. models in different project. can you please let me know how you able to see xml comments of model in swagger documentation.
Thanks in advance.
If you split your model class in seperate project, you have to add these to that project and follow what @eschneider999 say
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
How can you get other xml from other projects without explicitly stating the path?
I have a foreach for that (.NET Core version)
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My stinky API", Version = "v1" });
AddSwaggerXml(c);
}
private static void AddSwaggerXml(Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenOptions c)
{
var xmlFiles = Directory.GetFiles(AppContext.BaseDirectory, "*.xml");
foreach (var xmlFile in xmlFiles)
{
c.IncludeXmlComments(xmlFile);
}
}
Beware of large XML files in the example from @mattfrear, nice to automate put make sure you put on some filter to only load your own XML documentation. "System.Reactive.xml" is an example output you might get, and that is 2.3MB in size.
@sondreb FWIW I've never seen xml files from other dlls or NuGet packages in my output folder. The only xml files I have in my wwwroot folder are my own XML files.
Most helpful comment
In my case, it was because my models are in a different project.
I added another call and it works:
c.IncludeXmlComments(xmlPath2); // add Other proj xml comments, this is needed because it's in a different project.