3
votes

NB: using Spring Boot 1.4.2 + SpringFox 2.6.0

Hi, I'm having an issue with Swagger 2 forms on my API documentation over a @RepositoryRestResource. The code below works fine (REST access OK):

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

And the HATEOAS links are right too: calling URL /api/people/search ends up with this (notice parameter "name"):

{
  "_links": {
    "findByLastName": {
      "href": "http://localhost:8080/api/people/search/findByLastName{?name}",
      "templated": true
    },
    "self": {
      "href": "http://localhost:8080/api/people/search"
    }
  }
}

The REST API is ok: URL /api/people/search/findByLastName?name=foobar returns data when executed with a browser

BUT in Swagger the GET parameter type is interpreted as "body" instead of "query" and the form submission (curl ... -d 'foobar'...) fails in 404, attempting to submit "name" as request body. So I tried to set Swagger explicitly, like this:

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends JpaRepository<Person, Long> {
    @ApiOperation("Find somebody by it's last name")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "name", paramType = "query")
    })
    Person findByLastName(@Param("name") @ApiParam(name = "name") String name);
}

without any success, despite the fact that "name" is well retained in the form as the parameter name in this example :-(

body parameter type on GET query

Does anyone know what could be done to make that Swagger form to work? Thx for your help

1

1 Answers

2
votes

This is it : @Param configures Spring Data REST, while @RequestParam fits Swagger

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends JpaRepository<Person, Long> {

    // @Param Spring Data REST : Use @Param or compile with -parameters on JDK 8
    // @RequestParam Swagger : paramType=query cf. $Api*Param

    Person findByLastName(@Param("name") @RequestParam("name") String name);

}

Me happy!