【发布时间】:2020-07-08 09:29:42
【问题描述】:
使用 Nestjs OpenAPI 模块,我可以使用如下装饰器指定响应类型:
@Controller('app')
class MyController {
@Get()
@ApiResponse({ status: 200, description: 'Success', type: MyDto })
getThing() {
// code here
}
}
但是,文档没有指定如何使用多态响应类型(或在 OpenAPI 术语中为 oneOf 响应类型)。例如,在下面的示例中,我希望我的响应类型为 oneOf: [MyDto, MyOtherDto]:
@Controller('app')
class MyController {
@Get()
@ApiResponse({ status: 200, description: 'Success', type: MyDto }) // What do do for type here?
getThing(): MyDto | MyOtherDto {
// code here
}
}
我该怎么做?
【问题讨论】: