Spring 使用 Spring 数据 REST 引导 OpenAPI 3
Spring Boot OpenAPI 3 with Spring Data REST
我无法使用 OpenAPI 记录我的 Spring 数据 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 引导设置:
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 似乎也是正确的。
我一定是遗漏了什么...感谢您的帮助。
我希望你需要试试这个 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 端点方法
,我添加了以下注释
@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 包裹
我无法使用 OpenAPI 记录我的 Spring 数据 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 引导设置:
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 似乎也是正确的。
我一定是遗漏了什么...感谢您的帮助。
我希望你需要试试这个 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 端点方法 ,我添加了以下注释
@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 包裹