admin管理员组文章数量:1312763
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.
本文标签: spring bootGradle openapi generator apply field level pattern in kotlin model classStack Overflow
版权声明:本文标题:spring boot - Gradle open-api generator apply field level pattern in kotlin model class - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741850184a2401019.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论