[英]Generate Enum in Java Client with Swagger
I am trying to create an API using Swagger 2.0. 我正在尝试使用Swagger 2.0创建API。 I would like to generate an interactive documentation using SwaggerUI and also generate API clients (in Java, JavaScript...). 我想使用SwaggerUI生成交互式文档,还希望生成API客户端(使用Java,JavaScript ...)。 I just tried to generate a small Java Client. 我只是尝试生成一个小型Java客户端。
I have a problem with Enumerations... In Swagger I can write the following (YAML here, the problem is the same if directly writing JSON): 我在枚举方面有问题...在Swagger中,我可以编写以下内容(YAML,如果直接编写JSON,问题是相同的):
definitions:
MediumStatus:
type: string
enum:
- CLOSED
- OPEN_AVAILABLE
- OPEN_NOT_AVAILABLE
- NOT_AVAILABLE
In the generated Java Client, what is expect/want is something like: 在生成的Java客户端中,期望/想要的东西是这样的:
public enum MediumType
{
CLOSED,
OPEN_AVAILABLE,
OPEN_NOT_AVAILABLE,
NOT_AVAILABLE;
public String value()
{
return name();
}
public static MediumType fromValue(String v)
{
return valueOf(v);
}
} }
but the SwaggerCodegen generate a client with: 但是SwaggerCodegen生成具有以下内容的客户端:
@ApiModel(description = "")
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.JavaClientCodegen", date = "2015-12-21T14:03:23.470Z")
public class MediumType {
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class MediumType {\n");
sb.append("}");
return sb.toString();
}
}
This class is not really correct, it don't even contains the enum values ! 这个类不是真的正确,它甚至不包含枚举值!
Can someone can tell me what I am missing ? 有人可以告诉我我在想什么吗?
EDIT/ 编辑/
Problem sovlded with https://github.com/swagger-api/swagger-codegen/pull/1740 用https://github.com/swagger-api/swagger-codegen/pull/1740解决的问题
通过提交解决了问题: https : //github.com/swagger-api/swagger-codegen/pull/1740
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.