scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.41k stars 225 forks source link

Change how swagger ui sends array of values #295

Closed kasir-barati closed 2 years ago

kasir-barati commented 2 years ago

I am using NestJS and class-validator. We can in class-validator do this as we all know:

enum Gender { male = 'male', female = 'female' }

class A {
  @ApiProperty({
    required: false,
    description: `filter result by their gender`,
    example: [Gender.male],
    enum: Gender,
    type: [Gender],
  })
  @IsArray()
  @IsEnum(Gender, { each: true })
  genders: Gender[];
}

This A is used to validate query string Then when we sends a request with swagger it will sends something like this if we specify one age. http://localhost:9000/endpoint?genders=male

But this will make class-validator unsatisfied in my experience. I mean it throw an Error and says genders is not an array.

What will work?

Sending this request http://localhost:9000/endpoint?genders[]=male. class-validator understand how to deal with genders[] but if you sends genders you have to do this: http://localhost:9000/endpoint?genders=male&genders=male

scottie1984 commented 2 years ago

I suggest raising this directly with https://github.com/swagger-api/swagger-ui

josip-volarevic commented 1 year ago

@kasir-barati Any secret knowledge you've obtained in the last few months that you might share with me?

Kinda have the same issue but haven't managed to dig out a solution