2

I have a solution in VS2013 with several class libraries and a Web API project. I am running into a few problems when setting up Swagger UI. First, when I setup swashbuckle for my Web API project, I can only point to one documentation XML file. Is there a way to point to include multiple XML files so that Swagger not only picks up documentation for my routes in controller but also the domain objects from my other projects as well? Here is my code from SwaggerConfig.cs

SwaggerSpecConfig.Customize
    (
        c =>
        {
            c.IncludeXmlComments(Path.Combine(dirPath, projName + ".xml"));
        }
    );

If I add multiple XML files, it only picks up the last file from IncludeXmlComments.

Second, I am using camel case for my DTOs when returning in JSON

formats.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

However when I look at the response model and model schema in Response Class in Swagger UI, I see the exact class property names instead of the JSON schema which is returned when an endpoint is hit. Is there a way to show the exact JSON schema in the Swagger UI documentation page?

3 Answers 3

1

I am using version 5.6.0 and multiple XML docs works for me:

var dir = new DirectoryInfo(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"));
foreach (var fi in dir.EnumerateFiles("*.xml"))
{
    c.IncludeXmlComments(fi.FullName);
}
Sign up to request clarification or add additional context in comments.

Comments

0

to add multiple XML File configure swagger like that.

       SwaggerSpecConfig.Customize(c =>
        {
            // single XML Comment Files
            //c.IncludeXmlComments(GetXmlCommentsPath());

            // Multiple XML Comment Files
            string[] paths = GetXmlCommentsPaths();
            foreach (string xmlCommentsPath in paths)
            {
                c.OperationFilter(new ApplyActionXmlComments(xmlCommentsPath))
                    .ModelFilter(new ApplyTypeXmlComments(xmlCommentsPath));
            }
        });

2 Comments

I had been tinkering with the code and I do not know how I got it to work. When I use my code above, it works but when I use yours, I only get partial documentation. I will try to revert my code back and use your solution. FYI, in ApplyActionXmlComments and ApplyTypeXmlComments, the constructors require a XPathDocument.
It is working for me. I dont know what version you are using but i am using 4.1.0-rc2 prerelease .. and it takes path of file as string.
0

After version 4.1 you can write this:

c.IncludeXmlComments("File1_Path");
c.IncludeXmlComments("File2_Path"));

See also here.

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.