forked from loafle/openapi-generator-original
[2.0 Spec] Java generator: Implement Enums #287
Very basic implementation
This commit is contained in:
parent
2787fa82c6
commit
3971bbf334
@ -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;
|
||||
@ -441,6 +442,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>();
|
||||
@ -449,7 +451,9 @@ public class DefaultCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
property.datatype = getTypeDeclaration(p);
|
||||
property.datatype = property.isEnum
|
||||
? StringUtils.capitalize(getTypeDeclaration(p)) + "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}}}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user