【问题标题】:Document QueryDSL endpoint with Swagger使用 Swagger 记录 QueryDSL 端点
【发布时间】:2019-04-04 11:52:37
【问题描述】:

我正在使用 Spring Boot Data、QueryDSL 和 Swagger。 我已经定义了这样的端点:

@GetMapping
public ResponseEntity<?> listOfThings(
        @PageableDefault(size = 20, sort = "uID", direction = Sort.Direction.DESC) final Pageable pageable,
        @QuerydslPredicate(root = Thing.class) final Predicate predicate)

然而 Swagger 只定义变量:页面、大小、排序 - 它似乎没有解析实体以将所有字段显示为可过滤。

我有这样的存储库:

@Repository
public interface ThingRepository
        extends JpaSpecificationExecutor<Thing>, CrudRepository<Thing, String>, PagingAndSortingRepository<Thing, String>,
        QuerydslPredicateExecutor<Thing>, QuerydslBinderCustomizer<QThing>
{
    @Override
    default void customize(final QuerydslBindings bindings, final QThing thing)
    {
        bindings.bind(thing.status).first((status, value) -> status.eq(value));
        bindings.bind(thing.recipient).first(StringExpression::containsIgnoreCase);
        bindings.bind(String.class).first((StringPath path, String value) -> path.containsIgnoreCase(value));
    }

}

我希望 Swagger 将所有字符串字段显示为过滤器,尤其是严格定义的状态和收件人。

【问题讨论】:

  • 我也有类似的要求。你找到解决办法了吗?
  • 很遗憾没有
  • 我有类似的需求,他们的文档中没有提到:s
  • 我来这里寻找解决方案,但不幸的是,我们还没有!

标签: spring-data-jpa swagger spring-data-rest querydsl springfox


【解决方案1】:

定义一些虚拟参数并将所有查询参数添加为RequestParams,但不要使用它们...只需使用谓词。我们使用它作为一种解决方法来支持代码生成的 swagger 文件。不完美但有效!

public Iterable<SCGameInfo> findSCGameInfo(
  @QuerydslPredicate(root = GameInfo.class) Predicate predicate,
  @RequestParam(name= "gameName",required = false) String gameName,
  @RequestParam(name= "vendor",required = false) String vendor
){
 return  scService.findAllGameInfosForPredicate(predicate);
}

【讨论】:

  • 我找到了更好的解决方案。您可以在@QuerydslPredicate 上使用@Parameter(description = "filter",hidden = true)。和@Parameter 端点方法上的注释。 example
猜你喜欢
  • 2019-05-18
  • 1970-01-01
  • 2022-08-08
  • 2015-02-26
  • 2021-07-19
  • 1970-01-01
  • 2020-12-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多