【问题标题】:Springfox tags not working on PagingAndSortingRepositorySpringfox 标签在 PagingAndSortingRepository 上不起作用
【发布时间】:2018-07-08 15:44:13
【问题描述】:

我正在使用 Spring Boot 1.5.8 和 Springfox 2.8.0。我正在向我的 PagingAndSortingRepository 添加一个标签,试图在 Swagger UI 的“主题操作”标题下组织所有的 crud 方法。

但是,最终结果是某些方法显示在 Subject Entity: Simple Jpa Repository 标题下,例如

GET /api/subjects/{id}/images subjectImages

POST /api/subjects/{id}/images subjectImages

...等等

其余方法在主题操作下:

GET /api/subjects findAllSubject

POST /api/subjects saveSubject

..等等。

似乎 Spring 为外键相关数据生成的方法,例如/subjects/images,没有被移动到标签下,但我不确定如何纠正这种情况?

@CrossOrigin(origins = "http://localhost:3000")
@RepositoryRestResource(collectionResourceRel = "subjects", path = "subjects", excerptProjection = SubjectView.class)
@Api(tags = { "Subject Operations" })
public interface SubjectRepository extends PagingAndSortingRepository<Subject, Integer> {

    @Query("select distinct s from Subject s "
        + "join s.images si "
        + "where si.dataset.id = ?1")
    Page<Subject> findByDatasetId(Pageable pagable, @Param("datasetId") int datasetId);

}

【问题讨论】:

    标签: spring-boot swagger spring-rest springfox


    【解决方案1】:

    在存储库中定义标签,然后在 swagger 配置中创建它。标签的名称与标准标签“* Entity”相同。这对我有用:

    @Api(tags = "Channel Entity")
    @RepositoryRestResource
    public interface ChannelRepository extends JpaRepository<Channel, Long> {
    ..
    }
    

    Swagger 配置:

     @Bean
      public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo()).select()
            .apis(RequestHandlerSelectors.any())
            .paths(..))
            .build()
            .tags(new Tag("Channel Entity", "Data-rest endpoints"))
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-18
      • 2018-05-03
      • 2020-02-25
      • 2014-01-01
      • 2013-03-23
      • 2021-07-26
      • 2018-09-24
      相关资源
      最近更新 更多