适用于NestJS的OpenAPI Swagger-结合了两个DTO,以便正确显示

问题描述

我有一个通用的DTO:

export class GenericResponse {
    constructor(data) {
        this.data = data
    }
    @Expose()
    @IsNumber()
    @Apiproperty()
    data: any
    public getData(): any {
        return this.data
    }

    @Expose()
    @Isstring()
    @Apiproperty()
    private _sign: string
    public setSignedPayload(signedPayload: string) {
        this._sign = signedPayload
    }
    public getSignedPayload(): string {
        return this._sign
    }
}

我还将有其他的DTO也将使用该DTO。所以最终结果看起来像这样:

{
   "data": [{ ... dto with properties ... }],"_signed": "jwt"
}

问题是,它无法在OpenAPI中正确显示它。我需要显示这些DTO的组合。例如,在我的控制器中,我有

@ApiOkResponse({
        description: 'The found user',type: UserResponse,--> DTO
    })

显示用户属性

如果我使用这个:

@ApiOkResponse({
            description: 'The found user',type: GenericResponse,--> DTO
        })

当然,它显示数据并带有__signed。

但是我的最终响应是GenericResponse + UserResponse(例如)。我怎样才能将这两者结合起来,以便在OpenApi中显示全部内容

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)