【问题标题】:how can set properties swagger to list of String List<String>如何将属性大摇大摆地设置为 String List<String> 的列表
【发布时间】:2022-01-02 02:29:34
【问题描述】:

我正在尝试创建 springDoc swagger 文档,并且我想表示这样的数据 List&lt;String&gt; elements; 具有一些属性,如 minSize 和 MaxSize / minLength 列表中值的最大长度。 我试过这个

@Schema(required = true, minLength = 12,maxLength = 20)
List<String> elements;

@Size(min=10,max=20)
List<String> elements;

结果:

"Products": {
  "title": "Products",
  "type": "object",
  "properties": {
    "elements": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  }
}

任何想法得到这个结果:

"Products": {
    "title": "Products",
    "type": "object",
    "properties": {
        "elements": {
            "type": "array",
            "items": {
                "type": "string",
                "maxLength": 20,
                "minLength": 5
            }
        }
    }
}

【问题讨论】:

    标签: spring-boot annotations swagger


    【解决方案1】:

    我认为@ArraySchema 是您要查找的内容,如下所示:

    @Schema(minItems = 12, maxItems = 20)
    List<String> elements;
    

    @Schema 用于非数组元素,@ArraySchema 用于数组元素。两者不能共存。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      • 2023-02-07
      • 1970-01-01
      • 2018-12-21
      相关资源
      最近更新 更多