1

我无法使用 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);
}

这是我的 Spring 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 PATH 上是可以的。甚至 /profile/people PATH 似乎也是正确的。

我一定是错过了什么......感谢您的帮助。

4

1 回答 1

0

我希望你需要试试这个 URL。

http://localhost:8080/swagger-ui/index.html?configUrl=/v3/api-docs/swagger-config#

我的配置

另外,我创建了一个 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 Endpoint Method 上方,我添加了以下注释

 @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 包

于 2022-01-21T03:30:06.617 回答