Swagger文档中缺少参数端点的Spring引导GET和GET

问题描述 投票:0回答:1

我在rest控制器中有两个get映射,一个带有必需的请求参数(item ID),一个没有请求param,具有相同的路径。

此外,在项目中设置一个基本的Swagger UI。首先从我前面描述的2 get映射中随机丢失,然后我用swagger注释正确地注释它们,但是现在get参数不断丢失。

@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...
}

有没有办法强制招摇,以映射两者得到映射?

更新:是的,路径变量可能是一个很好的解决方案,但由于遗留原因,我不能这样做。

java spring spring-boot swagger
1个回答
3
投票

而不是RequestParam我会使用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...
}

这样你的映射就会有所不同,而且最有可能会出现在招摇之中。

© www.soinside.com 2019 - 2024. All rights reserved.