java - enunciate Enum with custom value or property
问题描述
I am now encountering the problem when generating Enum with custom properties.
In Project A, i build a API-webservice. I use enunciate-maven-plugin (version 2.12.1) to generate swagger documentation from Java code. When enunciate-maven-plugin runs, it will output the swagger.json
Then in the project B which consumes the Project A API-webservice, I use swagger-codegen-maven-plugin (version 2.3.1) to generate Java code from the above swagger.json.
maven configuration in Project B:
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.4.8</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>swagger-project-a.json</inputSpec>
<language>java</language>
<generateApis>false</generateApis>
<generateApiTests>false</generateApiTests>
<generateApiDocumentation>false</generateApiDocumentation>
<generateSupportingFiles>false</generateSupportingFiles>
<generateModelDocumentation>false</generateModelDocumentation>
<output>${project.basedir}</output>
<apiPackage>extern.api.swagger</apiPackage>
<modelNamePrefix></modelNamePrefix>
<modelPackage>extern.api.projecta</modelPackage>
</configuration>
</execution>
</executions>
</plugin>
Everything runs well, except the Enum. For example, I have enum
public enum ColorEnum {
RED("1"),
GREEN("2"),
BLUE("3")
private final String value;
ColorEnum(value) {
this.value = value;
}
public String getValue(){ return value;}
}
The generated swagger.json will be :
"json_ColorEnum" : {
"type" : "string",
"title" : "ColorEnum",
"enum" : [
"RED",
"GREEN",
"BLUE"
]
}
The enum values are not generated. I already tried the @JsonProperty like this: REF: https://github.com/stoicflame/enunciate/issues/653
public enum ColorEnum {
@JsonProperty("1")
RED("1"),
@JsonProperty("2")
GREEN("2"),
@JsonProperty("3")
BLUE("3")
private final String value;
ColorEnum(value) {
this.value = value;
}
public String getValue(){ return value;}
}
And the output is not as expected:
"json_ColorEnum" : {
"type" : "string",
"title" : "ColorEnum",
"enum" : [
"1",
"2",
"3"
]
}
How can i generate Enum documentation with both label and value ?
Any help is appreciated. Thank you.
解决方案
推荐阅读
- java - Apache Ignite:重新连接到 Ignite 服务器后缓存无法使用
- reactjs - 未捕获的 RangeError:动态递归 Treeview 函数超出了最大调用堆栈大小
- javascript - 为什么 getOwnPropertyDescriptor 在 event.target 上返回 undefined?
- bash - 仅从大型输入文件中提取与多个模式中的每一个匹配的最后一行
- angular - Angular - 输入文件字段中的验证器
- django - 如何在 django 3 中使用 RelatedFieldWidgetWrapper
- php - 将登录切换移动到结帐时的帐户部分
- java - 如何将附加属性设置为布尔值
- arrays - 如何修改数组中特定子文档中的字段?
- c - 如何使用#define 指令定义复杂类型?