代码之家  ›  专栏  ›  技术社区  ›  jeff porter ichak khoury

swagger.io在json文件中错误地生成了“in”和“body”标记

  •  0
  • jeff porter ichak khoury  · 技术社区  · 7 年前

    我有这个密码…

      @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>
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   jeff porter ichak khoury    7 年前

    答案是不要混合JAXRS和Spring注释。

    应该是…@requestparam,而不是@queryparam

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