如何使用Swagger Codegen而不是其中的每个属性生成整个Pageable对象?

时间:2019-05-12 09:53:18

标签: swagger swagger-codegen

我有一个API可以检索具有分页和排序功能的所有产品,如下所示:

@ApiImplicitParams({
        @ApiImplicitParam(name = "page", dataType = "integer", paramType = "query", value = "The page number that should be returned. Default is 0."),
        @ApiImplicitParam(name = "size", dataType = "integer", paramType = "query", value = "How many items the page should have. Default is 20."),
        @ApiImplicitParam(name = "sort", allowMultiple = true, dataType = "string", paramType = "query", value = "Sorting order, e.g. asc or desc. Default is asc")})
public ResponseEntity<Product[]> getAllProducts(Pageable pageable) {}

然后我使用Codegen生成客户端API,但是这里的问题是它生成的方法签名不是我所期望的:

public List<Product> getAllProductsUsingGET(Object page, Object size, List<String> sort){}

我想在这里有getAllProductsUsingGET(Pageable pageable)

我在配置上犯了一些错误吗?谁能给我一些提示,如何仅实现pageable作为参数,而不是像这样的每个属性?非常感谢你!

1 个答案:

答案 0 :(得分:0)

您正在定义API隐式参数以恰好包括这3个参数。尽管如此,我不认为最终的API应该包含包含Pageable参数的签名,因为它们是Spring的依赖项,并且您不希望您的“连接器” API附加Spring依赖项。