无法从 swagger 获取 @CustomRequestParam 值

问题描述 投票:0回答:1

我在从 swagger 运行 API 时遇到以下错误:

2023-09-14 14:38:07.208  WARN 45800 --- [nio-8080-exec-4] m.w.r.a.GlobalControllerExceptionHandler : Error = [Missing Required Field(s).  Please refer to the API documentation] Exception = [Required request parameter 'documentIds' for method parameter type List is not present]
2023-09-14 14:38:07.217  WARN 45800 --- [nio-8080-exec-4] m.w.r.a.GlobalControllerExceptionHandler : Exception

org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'documentIds' for method parameter type List is not present
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:122) ~[spring-web-5.3.27.jar:5.3.27]
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:179) ~[spring-web-5.3.27.jar:5.3.27]
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:146) ~[spring-web-5.3.27.jar:5.3.27]
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.27.jar:5.3.27]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.27.jar:5.3.27]
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.27.jar:5.3.27]

下面是我的控制器代码和我从 swagger 传递的请求数据

@RequestMapping(method = {RequestMethod.POST}, value = "/updateDocumentIds", headers = "Accept=application/json")
    @ResponseBody
    public ActionResult updateDocumentIds(@CustomRequestParam(value = "documentIds",required = true) List<String> documentIds, @RequestParam(value = "route") Boolean route) throws Exception {
        ActionResult actionResult = new ActionResult();
        //runs service method
        return actionResult;
    }

狂妄的要求

任何帮助表示赞赏!

java rest annotations swagger
1个回答
0
投票

您遇到的错误消息

Required request parameter 'documentIds' for method parameter type List is not present

表示您发送的 Swagger 请求不包含所需的

documentIds
参数。

您需要像这样修复您的 Swagger 请求

{
  "documentIds": [
    "Doc2133",
    "Doc2143",
    "Doc2153"
  ]
}
© www.soinside.com 2019 - 2024. All rights reserved.