spring-data-jpa 带Spring Data REST的Sping Boot OpenAPI 3

dy2hfwbg  于 2022-11-10  发布在  Spring
关注(0)|答案(1)|浏览(265)

我在用OpenAPI记录我的Spring Data REST API时失败了。swagger-ui的主页上什么都没有显示(显然还有/v3/api-docs)。
下面是我的依赖关系的摘录:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.6.4</version>
    </dependency>
    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-data-rest</artifactId>
        <version>1.6.4</version>
    </dependency>

这是我的JPA存储库:

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonsRepository extends JpaRepository<Person, Long> {
Person findByLastname(@Param("name") @RequestParam("name") String lastname);
}

这是我的Sping Boot 设置:

spring.datasource.url=jdbc:h2:mem:testdb;DATABASE_TO_UPPER=false
spring.jpa.defer-datasource-initialization=true
spring.jpa.open-in-view=false
management.endpoints.web.exposure.include=*
springdoc.swagger-ui.operationsSorter=method

# springdoc.paths-to-match=/people/**

当然,我的CRUD API在/people路径上是可以的,甚至/profile/people路径看起来也是正确的。
我一定是错过了什么...谢谢你的帮助。

v1l68za4

v1l68za41#

请尝试此URL:
您的位置:首页〉〉〉
我的配置
我还创建了这个OpenAPI Bean:

@Bean
    public OpenAPI customOpenAPI() {
        return new OpenAPI()
                .components(new Components())
                .info(new Info().title("Test")
                        .description("Test Description")
                        .version("1.0.0"));
    }

在RestController API端点方法之上,我添加了以下注解

@Operation(summary = "Send Messages to Ibm Mq", description = "Send Message to the related ibm mq")
    @ApiResponses(value = {
            @ApiResponse(responseCode = "200", description = "Success Response",
                    content = @Content(schema = @Schema(implementation = SomeClass.class), mediaType = "application/json")),
            @ApiResponse(responseCode = "500", description = "Internal System Error",
                    content = @Content(schema = @Schema(implementation = SomeClass.class), mediaType = "application/json")),
            @ApiResponse(responseCode = "400", description = "Invalid Parameter Request",
                    content = @Content(schema = @Schema(implementation = SomeClass.class), mediaType = "application/json"))
    })

所有的导入都来自io.swagger.v3.oas.annotations包

相关问题