swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.33k stars 8.92k forks source link

Swashbuckle UI problem when one of the input parameter is a file #6219

Closed EmWaw closed 3 years ago

EmWaw commented 4 years ago

I'm trying to upload a file with some metadata:

Upload(IFormFile file, [FromForm]IEnumerable<MetadataValue> list)

public class MetadataValue
{
    public Metadata Metadata { get; set; }
    public string Value { get; set; }
}

public enum Metadata
{
    Cat1,
    Cat2
}

A list of MetadataValue is displayed like an array of string inputs. I was not able to determine how should I pass the data to the controller - I'm always receiving an empty collection.

image

Everything is working when I'm sending a request from Postman. This is handled by dot pattern/notation.

image

In Postman each parameter and each property of a complex object is being sent as a separate field:

curl --location --request POST 'https://localhost:44395/api/document/upload' \
--form 'file=@/C:/FilterDraft.txt' \
--form 'list[0].metadata=Cat1' \
--form 'list[0].value=ABC' \
--form 'list[1].metadata=Cat2' \
--form 'list[1].value=DEF'

How can I achieve this in Swagger UI? How can I configure Swagger for better UI generation?

I'm using:

.NET Core 3.1 Swashbuckle.AspNetCore 5.5.1

tim-lai commented 3 years ago

@EmWaw Please file this ticket to Swashbuckle. This is not a SwaggerUI issue. Thanks.