1

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.

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much for that tip! Is this documented anywhere, though? I've tried hard coding the property (springdoc.swagger-ui.configUrl=/v3/api-docs/swagger-config#) but ended up with a petstore demo...
SURPRISE: after discarding the above property, the main URL (localhost:8080/swagger-ui/index.html) finally started to show the right API documentation... I'm so confused, right now :-D
1

I suppose that your spring boot parent is in version 3+

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.1.0</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

You have to use the dedicated springdoc openapi dependencies for spring data rest which are :

<dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
        <version>2.1.0</version>
    </dependency>
<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-api</artifactId>
    <version>2.1.0</version>
</dependency>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.