【问题标题】:Swagger not accepting values in UISwagger 不接受 UI 中的值
【发布时间】:2020-10-29 08:44:02
【问题描述】:

我只观察到 PATCH API swagger 文档的奇怪行为。路径变量被标记为“ref”参数并且不接受提交值。

请注意,GET、POST 或 PUT API 文档不会发生这种情况。您可以在下面看到不同之处。

这里是 swagger API 配置:

@ApiOperation(value = "update Jurisdictions", response = JurisdictionDto.class, authorizations = {@Authorization(value = "oauth2schema")})
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "OK"),
        @ApiResponse(code = 401, message = "Unauthorized", response = AuthenticationError.class),
        @ApiResponse(code = 403, message = "Access Denied", response = AuthorizationError.class),
        @ApiResponse(code = 404, message = "Not found", response = NotFoundError.class),
        @ApiResponse(code = 500, message = "Internal server error", response = InternalServerError.class)
})
@ApiImplicitParams({
        @ApiImplicitParam(name = "jurisdiction", value = "jurisdiction", required = true, dataType = "integer", paramType = "path"),
        @ApiImplicitParam(
                name = "patch",
                value = "patch",
                dataType = "JsonPatchProperty",
                required = true)
})
@PatchMapping(value = "/v1/jurisdictions/{jurisdiction}", consumes = "application/json-patch+json")
public ResponseEntity<JurisdictionDto> updateJurisdiction(@PathVariable("jurisdiction") long id,
                                                          @RequestBody(required = true) JsonPatch patch) {
    return ResponseEntity.ok(jurisdictionSvc.getAndUpdate(id, patch));
}

谁能告诉我这里出了什么问题?

【问题讨论】:

    标签: spring spring-boot swagger swagger-ui springfox


    【解决方案1】:

    尝试使用对象类型Long 而不是原始long 作为方法参数。

    【讨论】:

    • 我的 GET api 有原始的long,它可以正常工作。这只发生在我的 PATCH api 文档中。