具有通用 return 类型的 Springdoc
Springdoc with a generic return type
当用户使用 Pageable 进行查询时,我有一个自定义页面 return。此页面有一个通用参数,我想在我的 Swagger 文档中指定它。
这是当前结果:
其中 elements
是我的泛型类型实例的列表。
我实际拥有的签名功能:
@CustomPageableAsQueryParam
@Operation(summary = "", operationId = "get_all_version")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Versions found an returned",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = CustomPage.class)))
})
@GetMapping(path = "/versions", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CustomPage<ReducedVersion>> getVersions(
@ParameterObject
@PageableDefault(sort = {"releaseTime"}, direction = Sort.Direction.DESC) Pageable pageable,
@Parameter(description = "Version type to filter the list") @RequestParam(required = false) VersionType type) {
理想情况下,我可以做到 @Schema(implementation = CustomPage<ReducedVersion>.class)
,但在 Java 中是不可能的。
Spring是否提供克服此限制的方法?
感谢您以后的回答!
解决此问题的一个技巧是创建一个新的 class 来包装该类型:
public class ReducedCustomPage extends CustomPage<ReducedVersion> {
}
那么您的控制器将如下所示:
@CustomPageableAsQueryParam
@Operation(summary = "", operationId = "get_all_version")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Versions found an returned",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ReducedCustomPage.class)))
})
@GetMapping(path = "/versions", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ReducedCustomPage> getVersions(
@ParameterObject
@PageableDefault(sort = {"releaseTime"}, direction = Sort.Direction.DESC) Pageable pageable,
@Parameter(description = "Version type to filter the list") @RequestParam(required = false) VersionType type) {
当用户使用 Pageable 进行查询时,我有一个自定义页面 return。此页面有一个通用参数,我想在我的 Swagger 文档中指定它。 这是当前结果:
其中 elements
是我的泛型类型实例的列表。
我实际拥有的签名功能:
@CustomPageableAsQueryParam
@Operation(summary = "", operationId = "get_all_version")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Versions found an returned",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = CustomPage.class)))
})
@GetMapping(path = "/versions", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<CustomPage<ReducedVersion>> getVersions(
@ParameterObject
@PageableDefault(sort = {"releaseTime"}, direction = Sort.Direction.DESC) Pageable pageable,
@Parameter(description = "Version type to filter the list") @RequestParam(required = false) VersionType type) {
理想情况下,我可以做到 @Schema(implementation = CustomPage<ReducedVersion>.class)
,但在 Java 中是不可能的。
Spring是否提供克服此限制的方法?
感谢您以后的回答!
解决此问题的一个技巧是创建一个新的 class 来包装该类型:
public class ReducedCustomPage extends CustomPage<ReducedVersion> {
}
那么您的控制器将如下所示:
@CustomPageableAsQueryParam
@Operation(summary = "", operationId = "get_all_version")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "Versions found an returned",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ReducedCustomPage.class)))
})
@GetMapping(path = "/versions", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<ReducedCustomPage> getVersions(
@ParameterObject
@PageableDefault(sort = {"releaseTime"}, direction = Sort.Direction.DESC) Pageable pageable,
@Parameter(description = "Version type to filter the list") @RequestParam(required = false) VersionType type) {