3

I have a .net core 2.1 class library for my models that I use in multiple asp.net core web api projects. I am using Swagger(version 3.0.0) for my API documentation. The Xml Comments are NOT displayed for the models in the class library. Yes, I have IncludeXmlComments in my Startup.cs. How do I get the Xml Comments working in my models class library?

NOTE: My models in my Projects directory are documented correctly by Swagger.

Here is where I include the Xml comments:

services.AddSwaggerGen(c => { 
    c.SwaggerDoc("v1", new Info { Title = "Web API", Version = "v1" }); 
    c.IncludeXmlComments($@"{System.AppDomain.CurrentDomain.BaseDirectory}\ABC.Application.WebApi.xml"); 
}); 
3
  • Can you share some of your code, specifically the part where you use the IncludeXmlComments Commented Aug 15, 2018 at 15:29
  • Here is where I include the Xml comments: services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "Web API", Version = "v1" }); c.IncludeXmlComments($@"{System.AppDomain.CurrentDomain.BaseDirectory}\ABC.Application.WebApi.xml"); }); Commented Aug 16, 2018 at 13:13
  • 1
    Looks like you have only one IncludeXmlComments but you should have at least two one for your WebApi and the other for the class library that has your models. Commented Aug 16, 2018 at 18:17

1 Answer 1

3

Any referenced assemblies will have to be added individually. ABC.Application.WebApi.xml will not contain xml comments from your shared models class.

services.AddSwaggerGen(c => { 
    c.SwaggerDoc("v1", new Info { Title = "Web API", Version = "v1" }); 
    c.IncludeXmlComments($@"{System.AppDomain.CurrentDomain.BaseDirectory}\ABC.Application.WebApi.xml"); 
    c.IncludeXmlComments($@"{System.AppDomain.CurrentDomain.BaseDirectory}\YourSharedClass.Models.xml"); 
}); 

You may need to copy the model xml to your project. Reference: Add NuGet package XML documentation to Swagger

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.