未填充 Map 类型的 OpenAPI @RequestBody 变量

OpenAPI @RequestBody variables of type Map are not populated

我有一个简单的 POST API,其中 @RequestBody 包含一个 HashMap 类型的变量。

问题是从未填充变量“myMap”。

Swagger UI 正确显示输入字段,并具有相应的默认值。 我还在配置文件中添加了一个静态块,否则 Swagger UI 不会显示 Map 类型的输入字段。

填充变量 myMap 需要什么?

配置class

static {
    SpringDocUtils.getConfig().removeRequestWrapperToIgnore(java.util.Map.class);
}

控制器class

@RequestMapping(value = "/process/start",method = RequestMethod.POST)
public void startProcess1(
        @RequestBody(description = "HashMap of strings", required = true) HashMap<String, String> myMap)  {
    Assert.notEmpty(myMap, "map may not be empty");
}

招摇UI

pom.xml

    <dependency>
        <groupId>org.springdoc</groupId>
        <artifactId>springdoc-openapi-ui</artifactId>
        <version>1.5.12</version>
    </dependency>

我发现我使用了错误的注解。 @RequestBody 是一个 class,它位于两个包中:

  1. org.springframework.web.bind.annotation
  2. io.swagger.v3.oas.annotations.parameters

我使用了包 io.swagger.v3.oas.annotations.parameters 中的注释,这是错误的。 正确的注释位于包 org.springframework.web.bind.annotation