I'm implementing a POST endpoint which takes such a DTO as an input:
export class GenericEventDto<D, A> {
@ApiProperty({ type: D }) // <- does not work
@Expose()
data: D
@ApiProperty({ type: A })
@Expose()
attributes: A // <- same
@ApiProperty()
@Expose()
messageId: string
}
In swagger docs data
and attributes
props appear to be empty object. Controller code looks like this:
export class Controller {
@ApiBody({ type: GenericEventDto<ConcreteData, ConcreteAttributes> })
async handleIncomingMessage(
@Body() event: GenericEventDto<ConcreteData, ConcreteAttributes>
): Promise<void> {
// do smth
}
}
Is it possible to have generic type in swagger spec? This GenericEventDto
will be reused later for other endpoints and I would like to avoid code duplication