繁体   English   中英

OpenAPI 生成器 jaxrs-spec 停止缩短我的枚举值

[英]OpenAPI generator jaxrs-spec stop shorterning my enum values

鉴于项目model 的sizeRange字段的 OpenAPI 规范:

size:
  type: string
  description: Size range for this project
  enum: [RANGE_0_10M,RANGE_10M_50M,RANGE_50M_100M]
  example: RANGE_10M_50M

jaxrs-spec OpenAPI 生成器生成Project.class ,如:

public enum SizeEnum {
_0_10M(String.valueOf("RANGE_0_10M")), _10M_50M(String.valueOf("RANGE_10M_50M")), _50M_100M(String.valueOf("RANGE_50M_100M"));

生成的枚举值被缩短(用于 Java):

Project.SizeEnum._0_10M

我准备忽略这种不便,但在这种情况下会导致异常:

Enum.valueOf(Project.SizeEnum.class, "RANGE_0_10M");

No enum constant com.mycompany.my_project.Project.SizeEnum.RANGE_0_10M

笔记

如果我在枚举中添加一个以RANGE_以外的值开头的值,这会导致所有枚举值正确显示。 我推断某些过程会自动缩短所有这些,因为它们共享一个前缀。

这是我可以访问的 OpenAPI 生成器配置吗? 我找不到它:

您可以通过将标志removeEnumValuePrefix=false additionalProperties到 OpenAPI 生成器configuration的 AdditionalProperties 部分来摆脱不需要的RANGE_前缀。


完整示例(maven):

<execution>
    <id>generate-id</id>
    <phase>generate-sources</phase>
    <goals>
        <goal>generate</goal>
    </goals>
    <configuration>
        <additionalProperties>
            removeEnumValuePrefix=false
        </additionalProperties>
        <inputSpec>spec.yaml</inputSpec>
        <generatorName>spring</generatorName>
        <configOptions>
            <identifierNamingConvention>snake_case</identifierNamingConvention>
        </configOptions>
        <output>${project.build.directory}/generated-sources/output</output>
    </configuration>
</execution>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM