Array of multiple types in response not working
See original GitHub issueVersion : “@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 ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Returning decoded data of multiple types not working
I am downloading data from Firebase and storing into UserDefaults. I am encoding and decoding it properly, and I can retrieve the data...
Read more >Solved: Can You Define a Response Consisting of an Array W...
Solved: Hi! It is easy to define a response that consists of an array made up of several objects. Is it possible to...
Read more >Arrays | Elasticsearch Guide [8.5] | Elastic
Field data types ... Arrays of objects do not work as you would expect: you cannot query each object independently of the other...
Read more >Returning values - Manual - PHP
A function can not return multiple values, but similar results can be obtained by returning an array. Example #2 Returning an array to...
Read more >How to extract data from array within Response Body
The answers above will work fine if you are sure that you will always get only one object in that array. So be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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. 😉
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.