3

I've started a new Spring Boot app (2.2.1.RELEASE) using MongoDB.

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

To have some API documentation created I added springdoc-api:

<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-ui</artifactId>
  <version>1.1.49</version>
</dependency>

As I am relying on Spring to take care of the generation of the REST endpoint, I created this simple repository:

@RepositoryRestResource(collectionResourceRel = "profile", path = "profile")
public interface ProfileRepository extends MongoRepository<Profile, String> {

  List<Profile> findByLastname(@Param("n") String lastname);
  List<Profile> findByFirstname(@Param("n") String firstname);
  List<Profile> findByEmail(@Param("e") String email);

}

So I have no class with @RestController.

I tried to add some io.swagger.v3.oas.annotations annotations to the methods in ProfileRepository, but nothing gets generated.

@Operation(summary = "Find Profile by first name", description = "Find Profile by first name")
List<Profile> findByLastname(@Param("n") String lastname);

Result of http://localhost:8080/v3/api-docs/:

{
  "openapi": "3.0.1",
  "info": {
    "title": "OpenAPI definition",
    "version": "v0"
  },
  "servers": [
    {
      "url": "http://localhost:8080",
      "description": "Generated server url"
    }
  ],
  "paths": {},
  "components": {}
}

How can I have the API documentation generated for my Spring Data REST repository endpoints?

1

2 Answers 2

1

According to this issue: https://github.com/springdoc/springdoc-openapi/issues/282, it is not possible to generate the OpenAPI docs from spring-boot-starter-data-rest since

spring-data-rest entities endpoints are dynamically generated at runtime [...]

Quoting from user "bnasslahsen" on the GitHub issue above.

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

1 Comment

This issue has been deleted, though it's present on archive.org: web.archive.org/web/20201217021135/https://github.com/springdoc/…
0

As of version 1.2.11 of springdoc-openapi, adding the org.springdoc:springdoc-openapi-data-rest dependency will generate API documentation for the Spring Data REST endpoints.

<dependency>
  <groupId>org.springdoc</groupId>
  <artifactId>springdoc-openapi-data-rest</artifactId>
  <version>1.5.10</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.