【发布时间】:2020-05-19 04:09:30
【问题描述】:
我有以下控制器代码:
public abstract class BaseController<TClientModel extents BaseClientModel> {
@Operation
@GetMapping
Page<TClientModel> get()
}
@Data
public abstract class BaseClientModel {
int id;
}
@RestController
public class SpecificController extends BaseController<SpecificClientModel> {}
@Data
public class SpecificClientModel extends BaseClientModel {
String name;
}
问题: 在 Swagger 中为 SpecificController 生成 open-api 标记时,响应中的客户端模型是 BaseClientModel,而不是 SpecificClientModel,并且只有 id 字段,而不是 id+name。
实际:
{
"id": 0,
}
预期:
{
"id": 0,
"name": "string",
}
鉴于我有 40 多个特定的控制器,有什么方法可以让 springdoc open-api 基于特定的通用参数生成正确的标记?
【问题讨论】:
-
好像还不支持。在官方仓库中有相关问题github.com/swagger-api/swagger-core/…
-
你能在 github 上提供一个可重现的例子吗?你的例子有些不对劲。什么@Operation 和@GetMapping 注释(来自哪个包)。范围而不是扩展。什么是 Page 对象?我在这里看不到。
Page<TClientModel> get()它没有“;”最后,既不是身体词,也不是抽象词。TClientModel是什么?我在这里看不到它我猜它是SpecificClientModel?举例来说,得到一些答案会更容易
标签: java spring swagger openapi springdoc