How to set addtionalProperties via OpenAPI 3.0 Java annotations?

56 views Asked by At

My end goal is to simply have some generated OAS 3.0 documentation contain the size constraints on a Map<String, String> 's keys and values. This code will be in Kotlin, but it shouldn't muddle the example too much:

    @RouterOperation(
        operation = Operation(operationId = ":POST/foo/bar",
            requestBody = RequestBody(
                content = [Content(
                    mediaType = MediaType.APPLICATION_JSON_VALUE,
                    schema = Schema(implementation = MyRequestData::class)
                )]
            )
        )
    )
    suspend fun myHandler(@Valid request: Request, @Valid data: MyRequestData) {}

//
// and
//

    @Serializable
    data class MyRequestData(
        @field:Valid
        @field:Schema(description = "A map")
        val someKeysToValues: Map<
                @Size(max = 100) String,
                @Size(max = 50) String>? = null

        @field:Valid
        @field:ArraySchema(schema = Schema(description = "A list item"))
        val someOtherKeys: List<@Size(max = 100) String>? = null,
    )

I am having a bear of time trying to figure out how to add in the key & value constraint information to the generated swagger json for the map. According to the documentation I should be using additionalProperties ... but my only options in a @Schema are to turn it to true or false.

  1. For a generic list it was easy enough to just use @ArraySchema, but nothing like that exists for Maps
  2. Unfortunately, the constraint annotations are not auto-detected & filled in like they were when using @ArraySchema either
  3. I've tried setting additionalPropertiesSchema to an object with @Schema and/or @SchemaProperty annotations, but it appears to do nothing
  4. I haven't found anything like @AdditonalSchemaProperty or @SchemaAdditionalProperty or similar to just add on top

I feel like I must be missing something incredibly obvious. At the moment, this the UI output I wind up getting:

MyRequestData{
  someKeysToValues {
    description:   A map
    < * >:    string
              A map

  }
  someOtherKeys  [
    string
    maxLength: 100
    minLength: 0
    A list item
  ]
}

I cannot seem to figure out how to get to that inner schema to add in max-length information. Any tips or examples?

Notes:

  • This is being included via org.springdoc:springdoc-openapi-starter-webflux-ui but the annotations & functionality here appears to be just from io.swagger.core.v3:swagger-annotations-jarakata (2.2.15)
0

There are 0 answers