Swagger.io 在 json 文件中错误地生成了 "in" 和 "body" 标签

Swagger.io incorrectly generates "in" and "body" tags in json file

我有这个代码...

  @RequestMapping(value = "/search/",
      method = RequestMethod.GET,
      produces = org.springframework.http.MediaType.APPLICATION_JSON_VALUE)
  @ApiOperation(value = "Search for a Device",
      response = DeviceSummary.class,
      position = 0)
  List<DeviceSummary> search(@ApiParam(value = "The store code", required = true) @QueryParam("storeCode") String storeCode,
                             @ApiParam(value = "The device type code", required = false) @QueryParam("deviceType") String deviceType,
                             @ApiParam(value = "The device type codes", required = false) @QueryParam("deviceTypes") String deviceTypes,
                             @ApiParam(value = "The device group code", required = false) @QueryParam("deviceGroupCode") String deviceGroupCode,
                             @ApiParam(value = "Max results to return", required = false) @QueryParam("maxResults") String maxResults);

swagger.json 文件看起来像这样..

"parameters" : [ {
          "in" : "body",
          "name" : "body",
          "description" : "The store code",
          "required" : true,
          "schema" : {
            "type" : "string"
          }
        }, {
          "in" : "body",
          "name" : "body",
          "description" : "The device type code",
          "required" : false,
          "schema" : {
            "type" : "string"
          }
        }, <SNIP>

我希望查询参数看起来像这样... 请注意 "in" 类型是 "query",而不是 "body"。还有,名字是正确的。

{
    "name" : "storeCode",
    "in" : "query",
    "description" : "The store code",
    "required" : true,
    "type" : "string"
}

我正在使用这些依赖项

<dependency>
    <groupId>com.github.kongchen</groupId>
    <artifactId>swagger-maven-plugin</artifactId>
    <version>3.1.0</version>
</dependency>
<dependency>
  <groupId>io.swagger</groupId>
  <artifactId>swagger-core</artifactId>
  <scope>compile</scope>
  <version>1.5.3</version>
  <exclusions>
    <exclusion>
      <groupId>javax.ws.rs</groupId>
      <artifactId>jsr311-api</artifactId>
    </exclusion>
  </exclusions>
</dependency>

答案是不要混合使用 JaxRS 和 Spring 注释。

应该是...@RequestParam,不是@QueryParam

@ApiParam(value = "The store code", required = true) @RequestParam("storeCode") String storeCode,