unchase / Unchase.Swashbuckle.AspNetCore.Extensions

:hammer: A library contains a bunch of extensions (filters) for Swashbuckle.AspNetCore.
https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions
Apache License 2.0
115 stars 16 forks source link

Bug: More than one .xml file may not return description #14

Closed DaleyKD closed 4 years ago

DaleyKD commented 4 years ago

Man, you're going to hate me. :)

SYMPTOM

Using more than one .xml file may result in a string.Empty enum description.

REPRODUCTION

services.AddSwaggerGen(options =>
{
    options.SwaggerDoc("v1", apiInfo);
    options.UseAllOfToExtendReferenceSchemas();

    var xmlFiles = Directory.GetFiles(AppContext.BaseDirectory, "*.xml", SearchOption.TopDirectoryOnly);
    foreach (var xmlFile in xmlFiles)
    {
        options.IncludeXmlComments(xmlFile);
    }

    options.AddEnumsWithValuesFixFilters(services, o =>
    {
        o.IncludeDescriptions = true;
        o.DescriptionSource = DescriptionSources.DescriptionAttributesThenXmlComments;

        foreach (var xmlFile in xmlFiles)
        {
            o.IncludeXmlCommentsFrom(xmlFile);
        }
    });
});

CAUSE

https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/blob/a3d1193ce9546cde4e15e39c6f4af27cb577a996/src/Unchase.Swashbuckle.AspNetCore.Extensions/Extensions/EnumTypeExtensions.cs#L105

This returns out after the first iteration and won't check any of the other XPath Navigators.

SOLUTION

Replace that line with:

if (xpathNavigator2 != null)
{
    return XmlCommentsTextHelper.Humanize(xpathNavigator2.InnerXml);
}
unchase commented 4 years ago

Hi, @DaleyKD

Agree with you. Thanks for your feedback! It helps to improve the library.