Version : "@nestjs/swagger": "^2.5.1"
I'm trying to print out an API response with a list of various object types. I'm also trying to use class-transformer with discriminators but swagger prints out [{}]
export class GetPageDto extends WeakCreatePageDto {
@ApiModelPropertyOptional({
isArray: true,
})
@IsOptional()
@IsArray()
@Type(() => BaseBlockDto, {
discriminator: {
property: 'type',
subTypes: [
{ value: GetBannerDto, name: 'banner' },
{ value: GetCampaignDto, name: 'campaign' },
],
},
})
readonly blockList: GetBannerDto | GetCampaignDto;
}
Is there a way to define an array of multiple types ?
Same observation today.
@ApiModelProperty({ isArray: true, type: [FooDto] }) readonly items: FooDto[]
leads to type being empty in .json.
EDIT:
Got this working...
Apparently out of 5 known (to me) possibilities:
@ApiModelProperty({ type: [FooDto] }) readonly items: FooDto[]@ApiModelProperty({ isArray: true, type: FooDto }) readonly items: FooDto[]@ApiModelProperty({ isArray: true }) readonly items: FooDto[]@ApiModelProperty({ isArray: true, type: [FooDto] }) readonly items: FooDto[]@ApiModelProperty() readonly items: FooDto[]It is closest to what is described in the 'quickstart' as well. So I would not dare to say 'docs' are wrong... but still... it could be a little confusing. ;)
@arekbal only first 2 are valid
@elSuperRiton we can't resolve union types, this is related to this issue https://github.com/nestjs/swagger/issues/191
@kamilmysliwiec what specifically from https://github.com/nestjs/swagger/issues/191 does not resolving union types have to do with so that I can follow along?
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.
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.
Most helpful comment
Same observation today.
@ApiModelProperty({ isArray: true, type: [FooDto] }) readonly items: FooDto[]leads to type being empty in .json.
EDIT:
Got this working...
Apparently out of 5 known (to me) possibilities:
@ApiModelProperty({ type: [FooDto] }) readonly items: FooDto[]@ApiModelProperty({ isArray: true, type: FooDto }) readonly items: FooDto[]@ApiModelProperty({ isArray: true }) readonly items: FooDto[]@ApiModelProperty({ isArray: true, type: [FooDto] }) readonly items: FooDto[]@ApiModelProperty() readonly items: FooDto[]only first 2 work.
It is closest to what is described in the 'quickstart' as well. So I would not dare to say 'docs' are wrong... but still... it could be a little confusing. ;)