nestjs / swagger

OpenAPI (Swagger) module for Nest framework (node.js) :earth_americas:
https://nestjs.com
MIT License
1.7k stars 476 forks source link

ApiModelProperty with enum and isArray does not create multi-select #237

Closed dfrechdev closed 4 years ago

dfrechdev commented 5 years ago

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 create a query parameter with @ApiImplicitQuery that uses enum and has the property "isArray" set as true, a multi-select is created in the Swagger API, as described and shown in https://docs.nestjs.com/recipes/swagger#working-with-enums:


@ApiImplicitQuery({
    name: 'role',
    enum: ['Admin', 'Moderator', 'User'],
    isArray: true,
})

When you move this to a Dto, the same settings with ApiModelProperty or ApiModelPropertyOptional however do not create a multi-select, but a string array instead:


@ApiModelProperty({
    enum: ['Admin', 'Moderator', 'User'],
    isArray: true,
})
readonly role: string[];

Expected behavior

That the same settings in ApiImplicitQuery and ApiModelProperty result in the same multi-select in the Swagger API.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

I would like to use the Dto for mulit-selecting values, rather than having to define the parameters implicitly. I also found the same question asked on https://stackoverflow.com/questions/55767782/nestjs-swagger-how-to-declare-multiselect-enum-field by another user, but could not find a corresponding issue.

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"

tomsquest commented 5 years ago

Same issue here: no multi-select.

It seems related to the generation of the enum field which should be under items in the Swagger json. See: https://github.com/swagger-api/swagger-ui/issues/4400#issuecomment-378237406

Nest-swagger 3.1.0 Nest: 6.6.3

kamilmysliwiec commented 5 years ago

Fixed in the next version (to install run npm i @nestjs/swagger@next). Note: remember to update @nestjs/common, @nestjs/core and typescript as well to ensure that you're using the latest versions.

Steps to migrate: https://github.com/nestjs/swagger/pull/355#issuecomment-547925879

kamilmysliwiec commented 4 years ago

4.0.0 has been published

lock[bot] commented 4 years ago

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.