some-dto.ts
export class CreateCatDto {
@ApiProperty()
name: string;
@ApiProperty()
age: number;
@ApiProperty()
breed: string;
}
I don't want response something like this:
@ApiOkResponse(
description: 'Cat object',
type: CreateCatDto
)
but my response must be array of like dto objects. I want smth like soo
ApiOkResponse(
description: 'The record has been successfully removed.',
schema: {
type: 'array',
properties: {
obj: {
type: CreateCatDto
}
}
}
)
have you tried something like this:
@ApiOkResponse(
description: 'Cat object',
type: CreateCatDto,
isArray: true // <= diff is here
)
Let me know if it helps
I found another solution we can wrap in array like this
@ApiOkResponse(
description: 'Cat object',
type: [CreateCatDto]
)
And if you need to deal with multiple types :
@ApiOkResponse({
description: 'More or less dangerous animals',
schema: {
type: 'array',
items: {
oneOf: [
{ $ref: getSchemaPath(CreateCatDto) },
{ $ref: getSchemaPath(CreateAlligatorDto) }
],
},
},
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With