gpt4 book ai didi

java - 如何在 swagger ApiOperation 注释响应变量中传递类型的 Class

转载 作者:行者123 更新时间:2023-12-02 08:44:41 25 4
gpt4 key购买 nike

我想大肆地显示响应,这是一个通用类。但它不会将类的类型作为响应。

@ApiOperation(value = "Get user name", response = ResponseWrapper.class)
// but I want to pass

@ApiOperation(value = "Get user name", response = ResponseWrapper<UserModel>.class)
// here I am getting error
// how can I pass ResponseWrapper<UserModel>.class in the response variable

// In swagger response example body will be shown like :
/*
{
"errors": [
{
"errorCode": "string",
"message": "string"
}
],
"id": "string",
"metadata": {},
"response": {},
"responsetime": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"version": "string"
}

But I want my response example body like this :

{
"errors": [
{
"errorCode": "string",
"message": "string"
}
],
"id": "string",
"metadata": {},
"response": {
"userName" : "string"
},
"responsetime": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"version": "string"
}
*/

示例代码没有通用类型的 ResponseWrapper,但我想传递通用类型的响应包装器。

最佳答案

到目前为止,我发现的唯一方法是创建一个显式类型化的类来实现/扩展您的泛型:

public class UserResponse extends ResponseWrapper<UserModel>{
}

这允许你做

@ApiOperation(value = "Get user name", response = UserResponse .class)

关于java - 如何在 swagger ApiOperation 注释响应变量中传递类型的 Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55393565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com