Specifying maxItems for a List<List<Object>> using spring swagger.v3 ArraySchema annotation

1.2k views Asked by At

We are facing an issue where we are unable to use any variant of @ArraySchema to specify the limit of maxItems for the properties such as -

List<List< obj >> test;

List<List<List< obj >>>> listOfTest;

JSON Validation error:

Semantic error at test.items Arrays must have 'maxItems' property defined

Semantic error at listOfTest.items.items Arrays must have 'maxItems' property defined

Tried following -

@ArraySchema(schema = @ArraySchema(schema =@Schema(description = "test), maxItems =2))

@ArraySchema(arraySchema = @ArraySchema(schema =@Schema(description = "test), maxItems =2))

@ArraySchema(arraySchema = @Schema(//with type property)

But all the above flavors fail due to incompatibility error.

Incompatible Types : Found: ArraySchema, required: Schema

Project is using springdoc openapi version 1.6.5

Can someone please specify how to resolve this issue?

1

There are 1 answers

0
gearbase On

In Kotlin it can be done like this:

    @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>
    )