Vitor Fontoura
Vitor Fontoura

Reputation: 31

Binding requests path parameters to object

I'm trying to bind some path parameters to an object so i can make all the validaton based on annotations inside that class.

It works fine but the swagger documentation generated by springfox dont recongnize the @ApiParam annotations from the class as path variables. Instead, it show them as query variables and tells me that my yml has semantic errors:

Semantic error at paths./{param1}/{param2} Declared path parameter "param1" needs to be defined as a path parameter at either the path or operation level

I can get a workaround by using @ApiImplicitParams, but the disavantage of it is that i have to use it for every method that can receive an object of that class, duplicating information.

In my controller i have the method set in this way:

@GetMapping("{param1}/{param2}")
@ApiOperation(value="Returns a register of composite key param1|param2")
public RegisterDTO findRegisterByKey(@Valid RegisterKey registerKey)
{
    return this.service.findRegisterByKey(registerKey);
}

And my RegisterKey class

public class RegisterKey {

    @NotNull
    @Min(value = 1)
    @ApiParam(value = "First key", required = true)
    private Long param1;

    @NotNull
    @Min(value = 1)
    @ApiParam(value = "Second key", required = true)
    private Long param2;

    [... getters and setters ...]

}

What can i do to make springfox generate the spring json and see that param1 and param2 as path parameters instead of query?

How Swagger Editor shows the parameters

Upvotes: 3

Views: 513

Answers (0)

Related Questions