From d45d36d8a2e3c5dd0218d3a00b8d0ea9a3de33eb Mon Sep 17 00:00:00 2001 From: oskar Date: Wed, 6 Apr 2016 21:51:17 +0200 Subject: [PATCH] Fixing broken enumeration swagger/json types for JaxRS-CXF templates. --- .../main/resources/JavaJaxRS/cxf/api.mustache | 4 +++ .../JavaJaxRS/cxf/enumClass.mustache | 27 ++++++++++++------- .../resources/JavaJaxRS/cxf/pojo.mustache | 3 ++- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache index 346a7a7d0a..5d25496a1b 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/api.mustache @@ -3,6 +3,10 @@ package {{package}}; {{#imports}}import {{import}}; {{/imports}} +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Map; import javax.ws.rs.*; import javax.ws.rs.core.Response; diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/enumClass.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/enumClass.mustache index 1ef4a61efb..5d6d4805f8 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/enumClass.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/enumClass.mustache @@ -1,16 +1,23 @@ -import javax.xml.bind.annotation.XmlEnum; -import javax.xml.bind.annotation.XmlType; - -@XmlType(name="{{classname}}") +@XmlType(name="{{datatypeWithEnum}}") @XmlEnum -public enum {{classname}} { - {{#allowableValues}}{{.}}{{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/allowableValues}} - - public String value() { - return name(); +public enum {{datatypeWithEnum}} { + + {{#allowableValues}} + {{#enumVars}}{{name}}({{datatype}}.valueOf("{{value}}")){{^-last}}, {{/-last}}{{#-last}};{{/-last}}{{/enumVars}} + {{/allowableValues}} + + + private {{datatype}} value; + + {{datatypeWithEnum}} ({{datatype}} v) { + value = v; } - public static {{classname}} fromValue(String v) { + public String value() { + return value; + } + + public static {{datatypeWithEnum}} fromValue(String v) { return valueOf(v); } } \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache index b42a6d3b3e..f17abb0d22 100644 --- a/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache +++ b/modules/swagger-codegen/src/main/resources/JavaJaxRS/cxf/pojo.mustache @@ -3,9 +3,10 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.XmlEnum; @XmlAccessorType(XmlAccessType.FIELD) -{{#hasVars}} @XmlType(name = "{{classn,ame}}", propOrder = +{{#hasVars}} @XmlType(name = "{{classname}}", propOrder = { {{#vars}}"{{name}}"{{^-last}}, {{/-last}}{{/vars}} }){{/hasVars}} {{^hasVars}}@XmlType(name = "{{classname}}"){{/hasVars}}