请求正文中的显式类型未在Swagger(NestJS)中显示

请求正文中的显式类型未在Swagger(NestJS)中显示,swagger,nestjs,Swagger,Nestjs,我和斯威格和内斯特一起工作。我的控制器中有以下API端点 @ApiTags('test') @Controller('test') export class TestController { @Put() async create( @Body('test') test: { name: string, age: number }): Promise<Foo> { return

我和斯威格和内斯特一起工作。我的控制器中有以下API端点

@ApiTags('test')
@Controller('test')
export class TestController {
   @Put()
   async create(
       @Body('test') test: {
           name: string,
           age: number
       }): Promise<Foo> {
           return await this.testService.creat(test);
       }
   }
}
@ApiTags('test'))
@控制器(“测试”)
导出类TestController{
@Put()
异步创建(
@主体(“测试”)测试:{
名称:string,
年龄:数目
}):承诺{
返回wait this.testService.create(test);
}
}
}
不幸的是,swagger没有选择内联类型定义(或者首先选择body参数)。如果我用一个带有
@ApiProperty()
注释的类替换内联定义,它就会工作。但是,我想找到一种不使用类的方法

有没有办法或者我必须在这里使用类

我还尝试使用
ApiBody()
注释,但是它只添加了一个“Request Body required”字段,而没有swagger中的类型定义(见下文)


提前谢谢

您必须在@ApiBody()标记中指定完整的模式。但是,这只会增加您管理该标记以及实际的@Body()标记的工作量

@ApiTags('test'))
@蜂体({
模式:{
特性:{
'name':{type:'string'},
'age':{type:'number'}
}
}
})
@控制器(“测试”)
导出类TestController{
@Put()
异步创建(
@主体(“测试”)测试:{
名称:string,
年龄:数目
}):承诺{
返回wait this.testService.create(test);
}
}
}

我建议按照Jay的建议使用类。

如果使用类来表示主体,该怎么办?@JayMcDoniel这会起作用,但我不想在这里使用类,而是想看看是否有一种只使用内联类型定义的方法
@ApiTags('test')
@ApiBody({
            schema: {
                properties: {
                    'name': { type: 'string' },
                    'age': { type: 'number' }
                }
            }
         })
@Controller('test')
export class TestController {
   @Put()
   async create(
       @Body('test') test: {
           name: string,
           age: number
       }): Promise<Foo> {
           return await this.testService.creat(test);
       }
   }
}