未在 Swagger UI 中生成的 Spring Data REST 端点 [英] Spring Data REST Endpoints Not Generating In Swagger UI

查看:58
本文介绍了未在 Swagger UI 中生成的 Spring Data REST 端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 @BasePathAwareController 实现了一个控制器,它也利用了 Spring Data REST(用于显示排序/大小等的发现)以及一些自定义端点(用于更新等).应用程序按预期工作,端点 SpringREST 生成的数据按预期工作,我可以看到响应中出现自链接,但是,我看不到Swagger UI 中的这些端点.我只能看到我的自定义端点在我的控制器中定义.

I've implemented a controller using @BasePathAwareController which also takes advantage of Spring Data REST (for finds to expose sort/size etc.) along with some custom endpoints (for updates etc.). The application is working as expected and the endpoints Spring Data REST generates are working as expected and I can see the self links appear in the responses, however, i can't see these endpoints in Swagger UI. I can just see my custom endpoints defined in my Controller.

根据这个帖子我需要使用 Swagger 3.0.0-SNAPSHOT@EnableSwagger2WebMvc

According to this post I need to use Swagger 3.0.0-SNAPSHOT with @EnableSwagger2WebMvc

这是我的配置:

我的app.yml:

spring:
    data:
      rest:
        basePath: /api/v1

我的POM文件:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.8.RELEASE</version>
    <relativePath/>
</parent>
<properties>        
        <springfox.swagger.version>3.0.0-SNAPSHOT</springfox.swagger.version>       
</properties>

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>${springfox.swagger.version}</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>${springfox.swagger.version}</version>         
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-data-rest</artifactId>
    <version>${springfox.swagger.version}</version>
</dependency>

Swagger 配置文件:

Swagger Config File:

@Configuration
@Import(SpringDataRestConfiguration.class)
@EnableSwagger2WebMvc
public class SwaggerConfig {

    @Bean
    public Docket api(ServletContext servletContext) {
        return new Docket(DocumentationType.SWAGGER_2)          
        .select()
        .apis(RequestHandlerSelectors.basePackage("my.package.name"))
        .paths(PathSelectors.any())
        .build().apiInfo(apiEndPointsInfo());
    }

    private ApiInfo apiEndPointsInfo() {
        return new ApiInfoBuilder().title("My App REST API's")
            .description("My App REST API's")            
            .version("1.0").build();
    }

}

我的仓库:

  @RepositoryRestResource(exported=true, collectionResourceRel="group", path="group")
public interface GroupRepository extends JpaRepository<Group, Long>, JpaSpecificationExecutor<Group> {


}

为什么我看不到 Spring Data REST 生成的默认端点?

Why can't i see the default endpoints that Spring Data REST produces?

推荐答案

我发现了我的问题.我不知道 Spring Data REST 不会在我在此处指定的控制器包名称下公开生成的端点:

I found the issue to my problem. I wasn't aware that Spring Data REST doesn't expose the generated endpoints under the controller package name I had specified here:

.apis(RequestHandlerSelectors.basePackage("my.package.name"))

所以当我将上面的行更改为:

so when I changed the above line to:

.apis(RequestHandlerSelectors.any())

我可以看到 JPA 存储库端点.

and I could see the JPA respository endpoints.

这篇关于未在 Swagger UI 中生成的 Spring Data REST 端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆