spring-bootspring-data-jpaspring-data-restspringdocspringdoc-ui

Spring Boot OpenAPI 3 with Spring Data REST


I'm failing at documenting my Spring Data REST API with OpenAPI. Nothing show in swagger-ui's homepage (and /v3/api-docs obviously).

Here is an excerpt from my dependencies:

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

And there is my JPA repository:

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

And this my Spring Boot setup:

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/**

Of course, my CRUD API is ok over /people PATH. Even the /profile/people PATH seems right.

I must be missing something... Thanks for any help.


Solution

  • Try this URL:

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

    My Configurations

    I have also created this OpenAPI Bean:

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

    Above the RestController API Endpoint Method ,I added the following annotations

     @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"))
        })
    

    All the imports came from io.swagger.v3.oas.annotations package