使用 open api 生成器不会在 int64 swagger 上生成模式注释

pattern annotation doesn't generate on int64 swagger using open api generator

我正在使用 swagger 2 并打开 api 5.3.1 生成器生成一些 类。目前,它似乎没有在 Long 上生成模式注释(在 swagger 中定义为 int64)。我该怎么做?

招摇:

id:
 type: integer
 format: int64
 pattern: '^\d{16,19}$'
 minLength: 16
 maxLength: 19

代码生成

  @javax.annotation.Nonnull
  @NotNull
  @ApiModelProperty( required = true, )
  @JsonProperty(JSON_PROPERTY_ID)
  @JsonInclude(value = JsonInclude.Include.ALWAYS)

  public Long getId() {
    return id;
  }

pattern 关键字允许您为 字符串值

不支持Integer/Long


https://swagger.io/docs/specification/data-models/data-types/#pattern

文档指出:

The pattern keyword lets you define a regular expression template for the string value. Only the values that match this template will be accepted. The regular expression syntax used is from JavaScript (more specifically, ECMA 262). Regular expressions are case-sensitive, that is, [a-z] and [A-Z] are different expressions. For example, the following pattern matches a Social Security Number (SSN) in the 123-45-6789 format:

ssn:
  type: string
  pattern: '^\d{3}-\d{2}-\d{4}$'

Note that the regular expression is enclosed in the ^…$ tokens, where ^ means the beginning of the string, and $ means the end of the string. Without ^…$, pattern works as a partial match, that is, matches any string that contains the specified regular expression. For example, pattern: pet matches pet, petstore and carpet. The ^…$ token forces an exact match.

对于整数数据类型,它看起来像:

    type: integer
    format: int64
    minimum: -86400
    maximum: 86400

澄清minimum/maximum:

最小值和最大值 使用 minimum 和 maximum 关键字指定可能值的范围:

type: integer
minimum: 1
maximum: 20

默认情况下,最小值和最大值都包含在范围内,即:

minimum ≤ value ≤ maximum

To exclude the boundary values, specify exclusiveMinimum: true and exclusiveMaximum: true. For example, you can define a floating-point number range as 0–50 and exclude the 0 value:

type: number
minimum: 0
exclusiveMinimum: true
maximum: 50

The word “exclusive” in exclusiveMinimum and exclusiveMaximum means the corresponding boundary is excluded: Keyword Description exclusiveMinimum: false or not included value ≥ minimum exclusiveMinimum: true value > minimum exclusiveMaximum: false or not included value ≤ maximum exclusiveMaximum: true value < maximum