I have just evaluated generating a Swagger Documentation for a Spring Data Rest repository with the Spring Data Rest Integration feature in the current 2.7.0 release and came upon the following bug.
When creating a custom query method in a Spring Data repository like findByCustomerId() in the snippet below, Springfox documents the input parameters to that method incorrectly. In the generated documentation the parameter is called param0 instead of customerId and is of type body instead of query as it should be (see screenshot). Probably, Springfox should support the @Param annotation since that is the least intrusive annotation to define a parameter name in Spring Data repositories.
@Api(tags = "Address Entity")
@RepositoryRestResource(path = "addresses")
public interface AddressRepository extends PagingAndSortingRepository<Address, Long> {
@ApiOperation("find all Addresses that are associated with a given Customer")
List<Address> findByCustomerId(@Param("customerId") Long customerId);
}

Workaround for this issue (see code below) is to annotate the parameter with @RequestParam to mark it as a query parameter and to override the name of the parameter using @ApiParam (can also be done with @RequestParam but you cannot define a description of the parameter then). But this workaround obviously relies on redundant information that may not reflect the actual API.
@Api(tags = "Address Entity")
@RepositoryRestResource(path = "addresses")
public interface AddressRepository extends PagingAndSortingRepository<Address, Long> {
@ApiOperation("find all Addresses that are associated with a given Customer")
List<Address> findByCustomerId(@Param("customerId") @RequestParam @ApiParam(name="customerId", value="ID of the customer") Long customerId);
}
Working code containing this workaround: https://github.com/thombergs/code-examples/blob/master/spring-data-rest-springfox/src/main/java/com/example/demo/AddressRepository.java. Issue can be reproduced by removing the @RequestParam and @ApiParam annotations.
Have you tried this snapshot build? I think this should be fixed
Yep, works with 2.7.1-SNAPSHOT, thanks. Any idea when the 2.7.1 release will be coming?
Hi,
Any idea about 2.7.1 release date? I am getting following error while use 2.7.1-SNAPSHOT version.
org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: springfox.documentation.spring.web.WebMvcRequestHandler.
My pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.14</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
<version>2.6.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.2.1.jre8</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-data-rest</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
</dependencies>