RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.62k stars 1.23k forks source link

DescriptionAttribute on an operation method is parsed as a summary instead of a description #1930

Open Zero3 opened 5 years ago

Zero3 commented 5 years ago

The content of a DescriptionAttribute on a controller method (operation) is parsed into a OpenAPI summary field instead of a description field. This seems to be a bug, and leads to incorrect displaying in frontends like ReDoc.

The issue is located in this piece of code:

            dynamic descriptionAttribute = context.MethodInfo.GetCustomAttributes()
                .SingleOrDefault(a => a.GetType().Name == "DescriptionAttribute");

            if (descriptionAttribute != null)
                context.OperationDescription.Operation.Summary = descriptionAttribute.Description;
            else
            {
                var summary = await context.MethodInfo.GetXmlSummaryAsync().ConfigureAwait(false);
                if (summary != string.Empty)
                    context.OperationDescription.Operation.Summary = summary;
            }

(https://github.com/RSuter/NSwag/blob/master/src/NSwag.SwaggerGeneration/Processors/OperationSummaryAndDescriptionProcessor.cs)

As seen, the Operation.Summary field is set instead of Operation.Description as expected.

The documentation seems correct, as it says:

DescriptionAttribute on the action method (used as Swagger operation 'Description')

(https://github.com/RSuter/NSwag/wiki/WebApiToSwaggerGenerator#supported-aspnet-web-api-attributes)

I noticed that this issue was previously mentioned in a comment on another issue, but likely since forgotten: https://github.com/RSuter/NSwag/issues/292#issuecomment-246939878

RicoSuter commented 5 years ago

Can you create a PR to assign the correct property (Description) and remove the if/else so that the summary is set to the xml docs?

Zero3 commented 5 years ago

@RSuter The change would conflict with this piece of code below, which I don't know what to do about:

            var remarks = await context.MethodInfo.GetXmlRemarksAsync().ConfigureAwait(false);
            if (remarks != string.Empty)
                context.OperationDescription.Operation.Description = remarks;

I think it is better if someone with better knowledge of the various OpenAPI / XML fields fixes this.