我有一个带有 POST 操作的控制器来保存 ReasonCode。这是我的控制器中的内容:
import {
CustomAuthGuard,
ReasonCodeService,
ReasonCode,
} from 'cnv-ms-core';
export class ReasonCodeController {
constructor(private readonly reasonCodeService: ReasonCodeService) {}
}
@Post('reason-codes')
@ApiOperation({ summary: 'Save Reason Code' })
@ApiBody({
//type: ReasonCode,
description: 'Reason Code',
required: true,
isArray: false,
})
@ApiResponse({
status: 201,
description: 'Reason Code is Saved Successfully.'
})
async saveReasonCode(
@Body() newReasonCode: ReasonCode,
): Promise<ReasonCode | null> {
return this.reasonCodeService.saveReasonCode(newReasonCode);
}
这是我的接口对象:
export interface ReasonCode {
name: string;
description: string;
type: ReasonCodeTypeEnum;
isVisible: boolean;
createdAt?: Date;
updatedAt?: Date;
}
正如您在上面的控制器片段中看到的那样,我在“@ApiBody”装饰器中注释掉了“类型”。我想添加这个,但是当我取消注释时,我看到错误“ReasonCode 仅指一种类型,但在此处用作值”,并且 vs code 提供了将 ReasonCode 添加到导入的快速修复。但是,我已经在导入中有 ReasonCode。如何在 @ApiBody 中添加它以在 swagger-ui 中查看它。
谢谢您的帮助。