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?

M. Justin
  • 14,487
  • 7
  • 91
  • 130
klind
  • 855
  • 2
  • 21
  • 33
  • Have you been able to solve this? It's probably not supported (see https://github.com/springdoc/springdoc-openapi/issues/298). Also related; My own question on this topic: https://stackoverflow.com/questions/59868163/why-is-springfox-not-exposing-repositoryrestresource – Stefan Falk Jan 23 '20 at 18:47

2 Answers2

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.

  • This issue has been deleted, though it's present on archive.org: https://web.archive.org/web/20201217021135/https://github.com/springdoc/springdoc-openapi/issues/282 – M. Justin Sep 21 '21 at 20:01
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>
M. Justin
  • 14,487
  • 7
  • 91
  • 130