mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-06-29 20:20:53 +00:00
Merge branch 'develop_2.0' of github.com:wordnik/swagger-codegen into develop_2.0
This commit is contained in:
commit
c10cf7bf7f
@ -18,6 +18,7 @@ public class CodegenProperty {
|
||||
public Double minimum, maximum, exclusiveMinimum, exclusiveMaximum;
|
||||
public Boolean hasMore = null, required = null, secondaryParam = null;
|
||||
public Boolean isPrimitiveType, isContainer, isNotContainer;
|
||||
public boolean isEnum;
|
||||
public List<String> _enum;
|
||||
public Map<String, Object> allowableValues;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.wordnik.swagger.util.Json;
|
||||
import com.wordnik.swagger.models.*;
|
||||
import com.wordnik.swagger.models.parameters.*;
|
||||
import com.wordnik.swagger.models.properties.*;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.io.File;
|
||||
@ -443,6 +444,7 @@ public class DefaultCodegen {
|
||||
if(sp.getEnum() != null) {
|
||||
List<String> _enum = sp.getEnum();
|
||||
property._enum = _enum;
|
||||
property.isEnum = true;
|
||||
|
||||
// legacy support
|
||||
Map<String, Object> allowableValues = new HashMap<String, Object>();
|
||||
@ -451,7 +453,9 @@ public class DefaultCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
property.datatype = getTypeDeclaration(p);
|
||||
property.datatype = property.isEnum
|
||||
? StringUtils.capitalize(property.name) + "Enum"
|
||||
: getTypeDeclaration(p);
|
||||
property.baseType = getSwaggerType(p);
|
||||
|
||||
if(p instanceof ArrayProperty) {
|
||||
|
@ -17,10 +17,10 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} { {{#vars}
|
||||
* minimum: {{minimum}}{{/minimum}}{{#maximum}}
|
||||
* maximum: {{maximum}}{{/maximum}}
|
||||
**/
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{#allowableValues}}
|
||||
private {{{datatype}}} {{name}} = {{{defaultValue}}};{{#isEnum}}
|
||||
|
||||
//{{^min}}public enum {{name}}Enum { {{#values}} {{.}}, {{/values}} };
|
||||
{{/min}}{{/allowableValues}}{{/vars}}
|
||||
public enum {{datatype}} { {{#_enum}}{{.}}{{^-last}}, {{/-last}}{{/_enum}} };
|
||||
{{/isEnum}}{{/vars}}
|
||||
|
||||
{{#vars}}
|
||||
@ApiModelProperty(required = {{required}}, value = "{{{description}}}")
|
||||
|
33
src/test/scala/Java/JavaModelEnumTest.scala
Normal file
33
src/test/scala/Java/JavaModelEnumTest.scala
Normal file
@ -0,0 +1,33 @@
|
||||
package Java
|
||||
|
||||
import com.wordnik.swagger.codegen.languages.JavaClientCodegen
|
||||
import com.wordnik.swagger.models._
|
||||
import com.wordnik.swagger.models.properties._
|
||||
import org.junit.runner.RunWith
|
||||
import org.scalatest.{FlatSpec, Matchers}
|
||||
import org.scalatest.junit.JUnitRunner
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
@RunWith(classOf[JUnitRunner])
|
||||
class JavaModelEnumTest extends FlatSpec with Matchers {
|
||||
|
||||
it should "convert a java model with an enum" in {
|
||||
val enumProperty = new StringProperty()
|
||||
enumProperty.setEnum(List("VALUE1", "VALUE2", "VALUE3").asJava)
|
||||
val model = new ModelImpl()
|
||||
.property("name", enumProperty)
|
||||
|
||||
val codegen = new JavaClientCodegen()
|
||||
val cm = codegen.fromModel("sample", model)
|
||||
|
||||
cm.vars.size should be(1)
|
||||
val enumVar = cm.vars.get(0)
|
||||
enumVar.baseName should be("name")
|
||||
enumVar.datatype should be("NameEnum")
|
||||
enumVar.name should be("name")
|
||||
enumVar.defaultValue should be("null")
|
||||
enumVar.baseType should be("String")
|
||||
enumVar.isEnum should equal(true)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user