使用带有swagger ui的@RequestParam注释方法

jny*_*jny 24 swagger-ui spring-boot swagger-2.0 springfox

我正在使用Springfox库来生成REST服务的文档,并在Swagger UI中显示它.我按照Springfox文档中的说明进行操作.

我有一个控制器,它使用查询字符串中的参数,方法映射如下:

@ApiOperation(value = "")
@RequestMapping(method = GET, value = "/customcollection/{id}/data")
public Iterable<CustomeType> getData(@ApiParam(value = "The identifier of the time series.") 
    @PathVariable String id,
    @ApiParam(name = "startDate", value = "start date", defaultValue = "")
    @RequestParam("startDate") String startDate,
    @ApiParam(name = "endDate", value = "end date", defaultValue = "")
    @RequestParam("endDate") String endDate)
Run Code Online (Sandbox Code Playgroud)

swagger-ui中生成的映射器显示为:

GET /customcollection/{id}/data{?startDate,endDate}
Run Code Online (Sandbox Code Playgroud)

参数在UI中正确显示: 在此输入图像描述

但是当我点击Try it Out时,请求URL会被误认为:

http:// localhost:8080/customcollection/1/data {?startDate,endDate}?startDate = 1&endDate = 2

怎么修好?

jny*_*jny 29

这是由线路造成的

 enableUrlTemplating(true)
Run Code Online (Sandbox Code Playgroud)

Docket我从示例中复制并忘记删除的配置中.

删除此行后,一切都按预期工作.