Swashbuckle.AspNetCore icon indicating copy to clipboard operation
Swashbuckle.AspNetCore copied to clipboard

Comments from XML Docs: not rendered for [FromForm] params

Open poddubitskya opened this issue 2 years ago • 2 comments

Hi!

I've updated Swashbuckle from 5.6.3 to 6.4.0 in my solution via the Swashbuckle.AspNetCore metapackage There are some API method params with [FromForm] attribute

I can't see comments for those methods after the upgrade. Rollback to 5.6.3 w\o changing anything else brings the comments back The latest manual still suggests this should work (https://github.com/domaindrivendev/Swashbuckle.AspNetCore#include-descriptions-from-xml-comments)


/// <summary>
/// Summary - OK in both
/// </summary>
/// <param name="id" example="123">This is not rendered in 6.4.0 but OK in 5.6.3</param>

Is there a bug?

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2308 I guess this issue is about the same situation. I've decided to create another one and try to express the problem in a more clear way

https://stackoverflow.com/a/66378019/2498155 Here guys discuss the same IMO

poddubitskya avatar Oct 17 '22 11:10 poddubitskya

I am also having this issue, except with the <example></example> tag on models. In 5.6.3, the examples show correctly. In 6.4.0, some of the examples do not show correctly and some do show correctly.

/// <summary>
/// Summary - OK in both
/// </summary>
/// <example>This is sometimes not rendered in 6.4.0 but OK in 5.6.3</example>

I don't see any correlation in the model fields where the example is not rendered. It is seemingly random which fields generate correctly; however, the example is not rendered for the same fields consistently.

I checked the documentation .xml file (not swagger.json) and I see the example tags are correct <example>[email protected]</example>.

But in the swagger.json file generated schemas, these tags are not there for every model field.

CarterCall1 avatar Oct 17 '22 18:10 CarterCall1

Good point to mention, thanks @CarterCall1 In the original case swagger json doesn't contain the description as well

poddubitskya avatar Oct 17 '22 18:10 poddubitskya

I also have the same problem. Do you have a solution to this problem?

MonkSoul avatar Apr 23 '23 07:04 MonkSoul

This error occurs even in version 6.5

dang-gun avatar Jul 18 '23 02:07 dang-gun

I have tried to get to the bottom of this Behaviour, so i wrote this Test Action: public void ActionWithSwaggerParameterAndFromFormAttribute([FromForm, SwaggerParameter(description: "param")] string param) { }

And added the Following Test: [Fact] public void Apply_EnrichesFormParrameters_IfActionDecoratedWithSwaggerParameterAndFromForm() { var parameter = new OpenApiParameter { }; var parameterInfo = typeof(FakeControllerWithSwaggerAnnotations) .GetMethod(nameof(FakeControllerWithSwaggerAnnotations.ActionWithSwaggerParameterAndFromFormAttribute)) .GetParameters()[0]; var swaggerParamAttribute = parameterInfo.GetCustomAttributes<SwaggerParameterAttribute>().FirstOrDefault(); var filterContext = new ParameterFilterContext( apiParameterDescription: null, schemaGenerator: null, schemaRepository: null, parameterInfo: parameterInfo); Subject().Apply(parameter, filterContext); Assert.Equal(parameter.Description, swaggerParamAttribute.Description); }

The Test passes and the OpenApiParameter has the correct Description. It wont be displayed tho using SwaggerUI. Not sure were the Problem lies but maybe someone more Familiar with the Library could take a look?

marcel-smits avatar Sep 09 '23 09:09 marcel-smits

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/2062

alexminza avatar Oct 06 '23 08:10 alexminza

I believe this is fixed in DotSwashbuckle, it has XML comment logic rewritten

Havunen avatar Mar 05 '24 19:03 Havunen

Duplicate of #2062

martincostello avatar May 04 '24 15:05 martincostello