【问题标题】:How to generate RequestBody of type Map<String, Object> using springdoc for swagger open api 3.0?如何使用 springdoc 为 swagger open api 3.0 生成 Map<String, Object> 类型的 RequestBody?
【发布时间】:2020-05-22 02:00:46
【问题描述】:
public Item addProperties(
        @Parameter(description = "identifier of the item")
        @PathVariable("id") String id,
        @Parameter(description = "map of property names and values ", 
                content = @Content(schema = @Schema(type = "object", implementation = Map.class)))
        @RequestBody Map<String, Object> properties) 

对于上面的代码,只有参数id 正在生成并且它完全缺少requestBody。我基于 https://swagger.io/docs/specification/data-models/dictionaries/ 添加了 type="object" 。

【问题讨论】:

    标签: spring-boot swagger openapi springdoc springdoc-openui


    【解决方案1】:

    RequestBody 类型必须是一个类。所以任何 Map 的实现都可以工作(即 HashMap)

    @RequestBody HashMap<String, Object> properties
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 1970-01-01
      • 2018-03-22
      • 2020-04-05
      • 1970-01-01
      • 2020-08-06
      • 1970-01-01
      相关资源
      最近更新 更多