所以我有一条可以接受两个不同的DTO的路线,我很难让这两个DTO连接/显示在swagger上。我正在使用NestJS的swagger插件。我知道在原始的狂妄自大中你可以做一些类似的事情。有什么想法吗?
Request:
oneOf:
- $ref: "#/components/schemas/RequestOneType"
- $ref: "#/components/schemas/RequestTwoType"
我现在的任何一个例子都是
异步initApp(@Body() req: RequestOneDto Body,@Res({ passthrough: true }) res: Response) {
}
导出类RequestOneDto { @Length(1,10);名称: string
@Max(10)值: number }
导出类RequestTwoDto { @Length(1,15);名称: string
@最大值(15)值:编号
州:‘纽约’}
发布于 2022-05-13 20:05:44
你试过这样做吗?
@ApiExtraModels(RequestOneDto, RequestTwoDto)
@ApiBody({
schema: {
oneOf: [
{
$ref: getSchemaPath(RequestOneDto),
},
{
$ref: getSchemaPath(RequestTwoDto),
},
],
},
})
async initApp(@Body() body: RequestOneDto | RequestTwoDto) {}
您可以从ApiBody, ApiExtraModels
中导入@nestjs/swagger
如果您不想显式地包含这些模型,您可以在一个地方注册它们
const document = SwaggerModule.createDocument(app, options, {
extraModels: [RequestOneDto, RequestTwoDto],
});
下面是更多的信息
https://stackoverflow.com/questions/72232818
复制相似问题