生成 Java 时 Swagger 映射 "on" 到 "true"

Swagger mapping "on" to "true" when generating Java

我正在使用 Swagger codegen 3.0.8 生成 Java 文件。 yaml 规范的一部分是

PrepositionalPhrase:
  type: object
  required:
  - preposition
  - objects
  properties:
    preposition:
      description: The preposition
      type: string
      enum:
      - of
      - on
      - or

(为简洁起见,删除了更多值)。生成的枚举是

  public enum PrepositionEnum {
    OF("of"),
    TRUE("true"),
    OR("or")
  }

出于某种原因,似乎 on 被映射到 true。我可以在某些配置解析器中看到这种情况,其中 "on" 在逻辑上意味着 "true",但这不适用于代码生成。

我用来生成的命令行是

swagger-codegen generate            \
                -i api.yaml \
                -l java             \
                --api-package com.example \
                --artifact-version 1.2.0 \
                --artifact-id example \
                --group-id com.example \
                --model-package com.example.model

有什么方法可以防止这种情况发生吗?

根据这张票swagger-codegen/issues/2559,它更像是一个YAML格式的特性,这似乎是对的:

Language Independent Scalar types:
    { ~, null }              : Null (no value).
    [ 1234, 0x4D2, 02333 ]   : [ Decimal int, Hexadecimal int, Octal int ]
    [ 1_230.15, 12.3015e+02 ]: [ Fixed float, Exponential float ]
    [ .inf, -.Inf, .NAN ]    : [ Infinity (float), Negative, Not a number ]
    { Y, true, Yes, ON  }    : Boolean true
    { n, FALSE, No, off }    : Boolean false

https://yaml.org/refcard.html

显然,解决方法是引用 YAML 文件中的值。