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

[Bug]: Operation parameter with [FromForm] should not be used to describe a request body if more than one such parameter

Open martincostello opened this issue 6 months ago • 7 comments

Describe the bug

As part of #3020 to fix #3018, a change was made to fix XML comments not being used to describe the request body for a form.

On reflection, this fix wasn't correct as if there are multiple parameter the first parameter is used to describe the request body in its entirety: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/3018#issuecomment-2306506421

Expected behavior

The request body should only be documented from the XML documentation for a [FromForm]-annotated argument if there is exactly one such parameter.

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/7a7230dd54be847ac82982010e00497d9fe5f2cf/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsRequestBodyFilter.cs#L17-L26

Actual behavior

The request body is documented from the XML documentation from the first of multiple arguments with [FromForm].

Steps to reproduce

Render the OpenAPI document for an application including the following controller:

using Microsoft.AspNetCore.Mvc;

namespace FromFormXmlIssue;

[ApiController]
[Route("[controller]")]
public class ReproController : ControllerBase
{
    [HttpGet]
    public int[] Get([FromForm] string First, [FromForm] string Second)
    {
        return [42];
    }
}

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

6.7.1

.NET Version

8.0.8

Anything else?

No response

martincostello avatar Aug 23 '24 07:08 martincostello