Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 可选查询字符串枚举参数-openapi,springboot_Spring Boot_Spring Mvc_Swagger_Openapi - Fatal编程技术网

Spring boot 可选查询字符串枚举参数-openapi,springboot

Spring boot 可选查询字符串枚举参数-openapi,springboot,spring-boot,spring-mvc,swagger,openapi,Spring Boot,Spring Mvc,Swagger,Openapi,我有一个OpenApi规范: paths: /lessons: get: tags: - lesson operationId: getLessons parameters: - in: query name: daysOfWeek schema: type: array items: $ref: '#

我有一个OpenApi规范:

paths:
  /lessons:
    get:
      tags:
        - lesson
      operationId: getLessons
      parameters:
        - in: query
          name: daysOfWeek
          schema:
            type: array
            items:
              $ref: '#/components/schemas/DaysOfWeekEnum'
使用swagger codegen,这将生成一个端点,如:

 @ApiOperation(value = "Get a collection lessons", nickname = "getLessons", notes = "", response = LessonDto.class, responseContainer = "List", tags={ "lesson", })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "List of Lessons", response = LessonDto.class, responseContainer = "List") })
    @RequestMapping(value = "/lessons",
        produces = { "application/json" }, 
        method = RequestMethod.GET)
    default ResponseEntity<List<LessonDto>> _getLessons(@ApiParam(removed for brevity) @Valid @RequestParam(value = "daysOfWeek", required = false, defaultValue="new ArrayList<>()") List<DaysOfWeekEnum> daysOfWeek) {
        return getLessons(daysOfWeek);
    }
这些URL不包括:

/lessons
/lessons?daysOfWeek=SOME_INVALID_VALUE
…我得到以下错误:

嵌套异常是 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法 反序列化
java.util.ArrayList
out-of-START\u对象的实例 代币


非常感谢您的帮助。

为了给您一个
空列表
,您需要将默认值设置为空字符串:

@RequestParam(value = "daysOfWeek", 
              required = false, 
              defaultValue = "") List<DaysOfWeekEnum> daysOfWeek) 
@RequestParam(value=“daysOfWeek”,
必需=错误,
defaultValue=“”)列表日期(每周)

因此,该问题与一个问题有关。总结如下:

将类型为array的参数添加到操作时,将生成 Spring代码在Spring MVC中包含无效的defaultValue 参数注释

修复方法是升级到更高版本的
openapi generator
-
4.0.0
为我做到了这一点

另外,错误消息:

例外是 com.fasterxml.jackson.databind.exc.MismatchedInputException:无法 从START\u对象标记反序列化java.util.ArrayList的实例

…有点像是在转移视线,它实际上是
testrestemplate
相关的,即
参数化类型引用
部分。将其更改为
String.class
可以识别错误的真实性质

/lessons
/lessons?daysOfWeek=SOME_INVALID_VALUE
@RequestParam(value = "daysOfWeek", 
              required = false, 
              defaultValue = "") List<DaysOfWeekEnum> daysOfWeek)