5

The issue is that I have a complex Object as Request Param for a GET-Request and after I place the Swagger Annotations inside the Object. The Swagger UI shows that the entry param is a body in which i have to place the Params.

 body: { "modelId": 0, "makeId": 0 } 

My REST controller looks like this

 @RequestMapping(method = RequestMethod.GET, value = "/model") public SearchModelsResponse searchModels( @ApiParam(value = "Search for something", required = true) final ModelSearch search) {...} 

And the Request object

public class ModelSearch { @ApiParam(value = "Something important)", required = true) private Long modelId; @ApiParam(value = "Something else important)", required = false) @Nullable private Long makeId; .... } 

Is there a Way to Annotate it correctly so Swagger shows it as correctly as Request Parameters and not as a body construct ?

4
  • Object as request parameter ? I don't think so. Only primitives are supported as request parameters. Commented Jul 1, 2017 at 12:50
  • Well it works well on Spring side and Jackson has no issues in the deserialising process. The only thing that breaks is swagger. Commented Jul 3, 2017 at 12:55
  • Exactly I meant It is not supported by swagger. In Spring, you can have whatever you want. Commented Jul 3, 2017 at 13:10
  • Is this kind of Implementation common on GET methods ? I saw some implementations also with an object to deserialize instead of primitives. Commented Jul 3, 2017 at 14:35

1 Answer 1

5

OK the solution in this kind of scenario is to manually define the Parameters, this is possible with the @ApiImplicitParam annotation.

So as result this looks like this.

 @ApiImplicitParams({ @ApiImplicitParam(name = "modelId", value = "this is modelId", required = true, dataType = "string", paramType = "query"), @ApiImplicitParam(name = "makeId", value = "this is makeId", required = true, dataType = "string", paramType = "query") }) @RequestMapping(method = RequestMethod.GET, value = "/model") public SearchModelsResponse searchModels( final ModelSearch search) {...} 

It's not a beautifull solution since I actually want swagger to interprete my code but the result gives the option to show it as request parameters not as a body construct.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.