我有一个控制器的login()
方法,如果用户尝试使用带有200 OK
有效负载的JWT令牌返回Session
或带有带有AcceptTerms有效负载的JWT令牌的451 Unavailable due to legal reasons
返回登录需要同意条款和条件的新版本。
@Nest.Post("login")
@ApiOperation({ title: 'Log in the user given email and password', operationId: 'userLogin'})
@Nest.UseFilters(UnavailableLegalReasonsExceptionFilter)
@ApiResponse({ status: HttpStatus.OK, description: "User was properly logged in", type: JwtToken})
@ApiResponse({ status: 451, description: "User haven't confirmed the latest version of Terms & Conditions", type: JwtToken})
async login(@Nest.Body() body: DTOs.LoginDto): Promise<JwtToken> {
...
}
现在,我想用Swagger记录下来。 JwtToken
定义为:
export class JwtToken {
@ApiModelProperty({enum: TOKEN})
type: TOKEN;
@ApiModelProperty({description: "Number of seconds"})
expiresIn: number;
@ApiModelProperty({ description: "Token", example: "eyJhb ... wWFQ"})
accessToken: string;
}
和TOKEN
:
export enum TOKEN {
AcceptTerms = "AcceptTerms",
Session = "Session"
}
但是写login()
仅返回JwtToken
是令人困惑的,例如在200
的情况下type
是Session
而在{{1}情况下}是451
。有效载荷也大不相同:
AcceptTerms
export class JwtPayload {
@ApiModelProperty({enum: TOKEN, description: "Token type"})
type: TOKEN;
@ApiModelProperty()
issuedAt: number;
}
export class LoginJwtPayload extends JwtPayload {
@ApiModelProperty()
name: string;
@ApiModelProperty({description: "T&C version accepted"})
tncAccepted: number;
}
export class AcceptTermsJwtPayload extends JwtPayload {
@ApiModelProperty({format: "email"})
email: string;
}
的令牌使用200
有效负载,而LoginJwtPayload
的令牌使用451
。
如何使用Nest的SwaggerModule对其进行记录?