I am using open-api generator gradle plugin to generate kotlin models from the open-api spec. I would like to bring in some field level validations for the generated models.
Below is the portion of the open-api spec
timeRange:
required:
- from
type: object
additionalProperties: false
properties:
from:
type: string
format: date-time
pattern: '^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?([+-]\d{2}:\d{2}|Z)$'
description: >-
Start time
to:
type: string
format: date-time
description: >-
End time
However, in the generated model the pattern is applied on the getter rather than the field level. How can I apply the pattern validation on the field level rather than the getter
Below is the generated model
data class TimeRange(
@get:Pattern(regexp="^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?([+-]\\d{2}:\\d{2}|Z)$")
@Schema(example = "null", required = true, description = "Start time")
@get:JsonProperty("from", required = true) val from: String,
@Schema(example = "null", description = "End time")
@get:JsonProperty("to") val to: String? = null
) {
}
I would like to get the pattern applied to the field on the generated models.
@field:Pattern(regexp="^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?([+-]\\d{2}:\\d{2}|Z)$")
Much appreciate any help in solving this.