我有以下类来表示一个响应:
class SomeResponse {
property1?: string;
[key: string]: string
}
我想使用nest-cli为这个响应生成正确的swagger文档。它适用于我的所有其他simpler
属性,即property1
在swagger中正确显示。我还尝试使用以下命令直接进行注释:
class SomeResponse {
property1?: string;
@ApiProperty()
[key: string]: string
}
但这是不允许的,因为这给出了:error TS1206: Decorators are not valid here.
有没有一种方法可以手动注释或使用诸如[key: string]: string
之类的nest-cli结构进行注释
发布于 2021-07-17 02:06:41
不幸的是,它似乎不能将装饰符附加到索引签名。您也可以使用additionalProperties
(请参阅here),但它将生成嵌套对象。
class SomeResponse {
@ApiProperty({ type: 'object', additionalProperties: { type: 'string' } })
data: Record<string, string>;
}
这将被提取如下所示。
{
"data": {
"additionalProp1": "string",
"additionalProp2": "string",
"additionalProp3": "string"
}
}
https://stackoverflow.com/questions/68408494
复制相似问题