Syngularity
Syngularity

Reputation: 824

Spring boot GET and GET with parameter endpoints missing from Swagger docs

I have two get mapping in rest controller, one with a required request parameter (item ID), one without request param with the same path.

Also, have a basic Swagger with UI set up in the project. At first from the 2 get mapping I described earlier one is randomly missing, then I annotated them properly with swagger annotations, but now the get without parameter constantly missing.

@ApiOperation("Get item with the given ID")
@GetMapping(value="/resource/item", params = "id")
public Item getOne(@ApiParam(value = "the ID of the item want to view") @RequestParam(name = "id") Long id) {
    //things...
}

@ApiOperation("Get all item")
@GetMapping(value="/resource/item")
public List<Item> getAll() {
    //things...
}

Is there a way to force swagger to map both get mapping?

Update: Yes, path variable can be a good solution, but i can't do that because of legacy reasons.

Upvotes: 0

Views: 1816

Answers (1)

Simon B
Simon B

Reputation: 98

Rather than RequestParam I would use Pathvariable

@ApiOperation("Get item with the given ID")
@GetMapping(value="/resource/item/{id}")
public Item getOne(@ApiParam(value = "the ID of the item want to view") @PathVariable Long id) {
    //things...
}

That way your mappings are different and most likely will show up in swagger.

Upvotes: 3

Related Questions