#Swagger with multipart/form-data array

5 messages · Page 1 of 1 (latest)

sly gyro
#

I need to send pictures and data about them to the server. So I use multipart/form-data for this. But in SwaggerUI my array is built wrong.
I have this code in my CreateDTO

@IsArray()
@ApiProperty({ example: ['3D', 'Armor'] })
@Transform((params) => {
   return JSON.parse(params.value)
})
readonly tags: Array<string>

When i trying to make request, i get this in CURL output

#

so in params.value i get string: "3D, Armor" and this isn`t a valid json array. I want get from SwaggerUI tags=["3D", "Armor"]. How to achieve this?

fathom gazelle
#

Arrays in a query string are always tricky, because there is no standard dictating how they should be parsed.

I've always used typeof value == 'string' ? value.split(',') : value in the tranform function to parse string arrays

#

Oh, sorry, it is not a query strint but a multipart body param. But I think those are still "urlencoded"

#

You might need to consult the OpenAPI specification if you need any extra configuration