java 使用spring swagger.v3 ArraySchema annotation为List&lt;List &gt;指定maxItems< Object>

lhcgjxsq  于 2023-06-20  发布在  Java
关注(0)|答案(1)|浏览(184)

我们正面临一个问题,我们无法使用@ArraySchema的任何变体来指定属性的maxItems限制,例如-

    • List <List>测试;< obj >> test;
    • List <List <List>>> listOfTest;< obj >****

JSON验证错误:

  • 测试时出现语义错误。items数组必须定义'maxItems'属性 *
  • listOfTest.items.items数组中的语义错误必须定义“maxItems”属性 *

尝试跟踪-

  • @ArraySchema(schema =@ArraySchema(schema =@Schema(description ="test),maxItems = 2))*
  • @ArraySchema(arraySchema =@ArraySchema(schema =@Schema(description ="test),maxItems = 2))*
  • @ArraySchema(arraySchema =@Schema(//带type属性)*

但所有上述风味都因不兼容错误而失败。

  • 不兼容的类型:已找到:ArraySchema,必需:方案 *

项目使用的是SpringDoc OpenAPI版本1.6.5
有人能说明如何解决这个问题吗?

gzszwxb4

gzszwxb41#

在Kotlin中,可以这样做:

@Schema(description = "Your DTO")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    data class YourDTO(
        @JsonProperty
        @field:Schema(
            description = "Date",
            type = "date-time",
            example = "2023-12-30 09:00",
            required = true
        )
        @NotNull
        val date: LocalDateTime,
        @field:Schema(description = "Number")
        @field:Size(max = 27)
        val number_a: String?,
        @field:Schema(
            minimum = "0",
            maximum = Int.MAX_VALUE.toString(),
            description = "Count"
        )
        val count: Int = 1,
        @field:ArraySchema(
            schema = Schema(
                maxLength = 2147483646,
                required = false
            ),
            arraySchema = Schema(
                description = "Comment",
            ),
            maxItems = Int.MAX_VALUE,
        )
        val comments: List<String>
    )

相关问题