最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring boot - Gradle open-api generator apply field level pattern in kotlin model class - Stack Overflow

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论