为什么Swagger Codegen会将ON / OFF字符串枚举转换为TRUE / FALSE?

问题描述 投票:1回答:1

我正在使用Swagger Codegen 3.0.19,也尝试过OpenAPI Generator 4.0.3。

Java环境:

Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

赛跑者:

java -jar ./libs/openapi-generator-cli-4.3.0.jar  generate \
       -i pet.yaml \
       -g spring \
       -o ./OUTPUT/api/

这是我的OpenAPI架构:

openapi: "3.0.0"
....
CaptureStatus:
  type: object
  description: Holds current capture status.
  properties:
    status:
      type: string
      enum:
        - ON
        - OFF
      description: Capture status values.
....

输出为:

  ....
  public enum StatusEnum {
    TRUE("true"),

    FALSE("false");

    private String value;

    StatusEnum(String value) {
      this.value = value;
    }
  ....

为什么代码生成器将ON / OFF枚举转换为TRUE / FALSE?当我使用Swagger Editor GUI生成时,它不会执行此操作。

yaml openapi swagger-codegen openapi-generator
1个回答
0
投票

在YAML 1.1中,onoffynyesnoboolean values。在YAML 1.2中为changed,此版本不再将这些值视为布尔值。

看起来Swagger Codegen和OpenAPI Generator使用YAML 1.1解析器。在这种情况下,您需要将'ON''OFF'括在引号中,以将它们视为字符串:

      enum:
        - 'ON'
        - 'OFF'
© www.soinside.com 2019 - 2024. All rights reserved.