英文:
PathVariable as optional in swagger SpringFox(3.0.0)
问题
我最近已经升级到了最新版本的 SpringFox(3.0.0)
。PathVariable
标记为 required = false
,但在显示中仍然被视为必需。
以下是我的控制器方法代码:
@GetMapping(path = { "/persons", "/persons/{id}" })
public List<Person> getPerson(@PathVariable(required = false) String id) {
}
我尝试过添加 @ApiParam
,默认情况下它是 false
。但是在 Swagger 上仍然显示为必需。
之前使用 SpringFox(2.9.0)
时,它正常工作,在 Swagger 上被标记为可选。
对此的任何帮助将不胜感激。
谢谢
英文:
I have upgraded to the latest version of SpringFox(3.0.0)
recently.<br/>
PathVariable
marked as required = false
is showing as mandatory.
Below is my controller method code
@GetMapping(path = { "/persons", "/persons/{id} })
public List<Person> getPerson(@PathVariable(required = false) String id) {
}
I have tried adding @ApiParam
, by default it is false
. But still, on swagger it is showing as mandatory.
Previously with SpringFox(2.9.0)
it was working fine, on swagger it was marked as optional
Any help in this will be appreciated.<br/>
Thank you
答案1
得分: 4
Path参数始终是必需的。如果我们有一个可选的路径变量,那么我们需要定义两个单独的端点。
我已经添加了两个端点来解决我的问题,如下所示。
@GetMapping(path = { "/persons" })
public List<Person> getAllPerson() {
}
@GetMapping(path = { "/persons/{id}" })
public List<Person> getPersonById(@PathVariable String id) {
}
英文:
Path parameters are always required. If we are having an optional path variable then we need to define the two separate end poinds.
I have added two endpoints to solve my problem as shown below.
@GetMapping(path = { "/persons })
public List<Person> getAllPerson() {
}
@GetMapping(path = {"/persons/{id} })
public List<Person> getPersonById(@PathVariable String id) {
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论