ApiImplicitQuery: collectionFormat ignored when enum is set and isArray is true
I'm submitting a...
[ ] Regression
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
When you use the ApiImplicitQuery decorator and set enum and isArray to true, the attribute collectionFormat is by default set to multi and cannot be overwritten. When used without enum and isArray only, the attribute collectionFormat is respected.
This
@ApiImplicitQuery({
name: 'role',
isArray: true,
collectionFormat: 'csv',
})
for example results in ?role=Admin,Moderator.
In contrast, this
@ApiImplicitQuery({
name: 'role',
enum: ['Admin', 'Moderator', 'User'],
isArray: true,
collectionFormat: 'csv',
})
results in ?role=Admin&role=Moderator.
Expected behavior
The attribute collectionFormat is respected when set for enum arrays.
Minimal reproduction of the problem with instructions
See above examples
What is the motivation / use case for changing the behavior?
The collection format should also be selectable when enums are used. This has also been asked on stack overflow at https://stackoverflow.com/questions/55767782/nestjs-swagger-how-to-declare-multiselect-enum-field.
Environment
"@nestjs/common": "^6.1.1", "@nestjs/core": "^6.1.1", "@nestjs/platform-express": "^6.1.1", "@nestjs/swagger": "^3.0.2", "swagger-ui-express": "^4.0.2"
Found that the reason is that multi is currently hard-coded in https://github.com/nestjs/swagger/blob/master/lib/decorators/api-implicit-query.decorator.ts at line 43. Is there a reason for this? If not, I can fix this and create a PR if you want.
@dfrechdev I wasn't so sure when I submitted that PR for ApiImplicitQuery. I thought mainly because it had something to do with swagger-ui-express at the time regarding collectionFormat being multi.
I can confirm this issue. @dfrechdev, could you open a PR with your fix?
Fixed in 3.1.0
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.