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.
- For a generic list it was easy enough to just use
@ArraySchema, but nothing like that exists for Maps - Unfortunately, the constraint annotations are not auto-detected & filled in like they were when using
@ArraySchemaeither - I've tried setting
additionalPropertiesSchemato an object with@Schemaand/or@SchemaPropertyannotations, but it appears to do nothing - I haven't found anything like
@AdditonalSchemaPropertyor@SchemaAdditionalPropertyor 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-uibut the annotations & functionality here appears to be just fromio.swagger.core.v3:swagger-annotations-jarakata(2.2.15)