用于POST的Spring Boot Swagger UI中的400错误请求

时间:2016-03-21 04:13:59

标签: spring-boot swagger-ui springfox

我用RestController创建了一个Spring Boot应用程序。我启用了Swagger UI,它工作正常,因为我可以登录到UI并执行任何GET方法。但是对于接受正文中对象的POST方法,当我使用Swagger UI触发请求时,它总是返回400状态代码。我可以看到请求永远不会到达特定的POST方法。我可以知道Swagger UI需要的任何特殊配置吗?

我的Spring Boot RestController中的特定方法

@ApiOperation(value = "Query requests by search criteria")
@RequestMapping(value = "/api/query", method = POST)
public PageResult<MyPOJO> find(@RequestBody SearchRequest request) {
    //implementation omitted.
}

我正在使用

 "io.springfox:springfox-swagger2:2.1.2",
 "io.springfox:springfox-swagger-ui:2.1.2"

这个(由Swagger UI生成)对应的api给了我400个错误请求:

 {
  "listEntrySearchCriteria": {
    "summary": {
      "createdBy": "string",
      "createdOn": "2016-03-21T10:33:05.048Z",
      "effectiveEnd": "2016-03-21T10:33:05.048Z",
      "effectiveStart": "2016-03-21T10:33:05.048Z",
      "id": 0,
      "region": "string",
      "type": "ETB",
      "updatedBy": "string",
      "updatedOn": "2016-03-21T10:33:05.048Z",
      "version": 0
    }
  },
  "listSummarySearchCriteria": {
    "effectiveEnd": "2016-03-21T10:33:05.048Z",
    "effectiveStart": "2016-03-21T10:33:05.048Z",
    "statuses": [
      "string"
    ],
    "types": [
      "string"
    ]
  },
  "pageRequest": {
    "orders": [
      {
        "direction": "ASC",
        "ignoreCase": true,
        "nullHandling": "NATIVE",
        "property": "string"
      }
    ],
    "page": 0,
    "size": 0
  }
}

但是如果我提供相同方法的随机请求,它至少会达到我的方法:

  {
  "orders": [
    {
      "direction": "ASC",
      "ignoreCase": true,
      "nullHandling": "NATIVE",
      "property": "id"
    }
  ],
  "page": 0,
  "size": 0
}

0 个答案:

没有答案