Issue
I faced a problem using Swagger and Spring Boot. I have a method like this:
@ApiOperation(value = "Returns product of specified id")
@GetMapping("/{id}")
private ProductInShop getProduct(@ApiParam(name = "Product id", value = "Id of the product you want to get") @PathVariable String id) {
return productService.findById(id);
}
This operation works greatly in Postman and when I call GET
method on my path and specify the id, I get needed product. But it doesn't work with swagger. I tried to debug and I observed that on this operation call id obtaines '{id}'
value, not the product id. How can I solve this problem and make PathVariable to be fetched wrightfully?
Solution
The problem may be related with the @ApiParam
name
attribute: either get rid of it:
@ApiOperation(value = "Returns product of specified id")
@GetMapping("/{id}")
private ProductInShop getProduct(@ApiParam(value = "Id of the product you want to get") @PathVariable String id) {
return productService.findById(id);
}
Or provide the appropriate value:
@ApiOperation(value = "Returns product of specified id")
@GetMapping("/{id}")
private ProductInShop getProduct(@ApiParam(name = "id", value = "Id of the product you want to get") @PathVariable String id) {
return productService.findById(id);
}
Answered By - jccampanero