Skip to content

[core] Handle referenced enum case correctly #2001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1927,57 +1927,17 @@ public CodegenProperty fromProperty(String name, Schema p) {
if (property.minimum != null || property.maximum != null)
property.hasValidation = true;

// legacy support
Map<String, Object> allowableValues = new HashMap<String, Object>();

if (p.getEnum() != null) {
List<Object> _enum = p.getEnum();
property._enum = new ArrayList<String>();
for (Object i : _enum) {
property._enum.add(String.valueOf(i));
}
property.isEnum = true;
allowableValues.put("values", _enum);
}

if (allowableValues.size() > 0) {
property.allowableValues = allowableValues;
}
} else if (ModelUtils.isBooleanSchema(p)) { // boolean type
property.isBoolean = true;
property.getter = toBooleanGetter(name);
} else if (ModelUtils.isDateSchema(p)) { // date format
property.isString = false; // for backward compatibility with 2.x
property.isDate = true;
if (p.getEnum() != null) {
List<String> _enum = p.getEnum();
property._enum = new ArrayList<String>();
for (String i : _enum) {
property._enum.add(i);
}
property.isEnum = true;

// legacy support
Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
property.allowableValues = allowableValues;
}
} else if (ModelUtils.isDateTimeSchema(p)) { // date-time format
property.isString = false; // for backward compatibility with 2.x
property.isDateTime = true;
if (p.getEnum() != null) {
List<String> _enum = p.getEnum();
property._enum = new ArrayList<String>();
for (String i : _enum) {
property._enum.add(i);
}
property.isEnum = true;

// legacy support
Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
property.allowableValues = allowableValues;
}
} else if (ModelUtils.isStringSchema(p)) {
if (ModelUtils.isByteArraySchema(p)) {
property.isByteArray = true;
Expand Down Expand Up @@ -2005,16 +1965,6 @@ public CodegenProperty fromProperty(String name, Schema p) {
if (property.pattern != null || property.minLength != null || property.maxLength != null)
property.hasValidation = true;

if (p.getEnum() != null) {
List<String> _enum = p.getEnum();
property._enum = _enum;
property.isEnum = true;

// legacy support
Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
property.allowableValues = allowableValues;
}
} else if (ModelUtils.isNumberSchema(p)) {
property.isNumeric = Boolean.TRUE;
if (ModelUtils.isFloatSchema(p)) { // float
Expand Down Expand Up @@ -2043,21 +1993,35 @@ public CodegenProperty fromProperty(String name, Schema p) {
if (property.minimum != null || property.maximum != null)
property.hasValidation = true;

if (p.getEnum() != null && !p.getEnum().isEmpty()) {
List<Object> _enum = p.getEnum();
property._enum = new ArrayList<String>();
for (Object i : _enum) {
property._enum.add(String.valueOf(i));
}
property.isEnum = true;
} else if (ModelUtils.isFreeFormObject(p)){
property.isFreeFormObject = true;
}

//Inline enum case:
if (p.getEnum() != null && !p.getEnum().isEmpty()) {
List<Object> _enum = p.getEnum();
property._enum = new ArrayList<String>();
for (Object i : _enum) {
property._enum.add(String.valueOf(i));
}
property.isEnum = true;

Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
if (allowableValues.size() > 0) {
property.allowableValues = allowableValues;
}
}
//Referenced enum case:
Schema r = ModelUtils.getReferencedSchema(this.openAPI, p);
if (r.getEnum() != null && !r.getEnum().isEmpty()) {
List<Object> _enum = r.getEnum();

// legacy support
Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
Map<String, Object> allowableValues = new HashMap<String, Object>();
allowableValues.put("values", _enum);
if (allowableValues.size() > 0) {
property.allowableValues = allowableValues;
}
} else if (ModelUtils.isFreeFormObject(p)){
property.isFreeFormObject = true;
}

property.dataType = getTypeDeclaration(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ public String getAlias(String name) {

@Override
public String toDefaultValue(Schema p) {
p = ModelUtils.getReferencedSchema(this.openAPI, p);
if (ModelUtils.isArraySchema(p)) {
final ArraySchema ap = (ArraySchema) p;
final String pattern;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static EnumNumberEnum fromValue(String text) {
private EnumNumberEnum enumNumber;

@JsonProperty("outerEnum")
private OuterEnum outerEnum = null;
private OuterEnum outerEnum;

public EnumTest enumString(EnumStringEnum enumString) {
this.enumString = enumString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static EnumNumberEnum fromValue(String text) {
private EnumNumberEnum enumNumber;

@JsonProperty("outerEnum")
private OuterEnum outerEnum = null;
private OuterEnum outerEnum;

public EnumTest enumString(EnumStringEnum enumString) {
this.enumString = enumString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static EnumNumberEnum fromValue(String text) {
private EnumNumberEnum enumNumber;

@JsonProperty("outerEnum")
private OuterEnum outerEnum = null;
private OuterEnum outerEnum;

public EnumTest enumString(EnumStringEnum enumString) {
this.enumString = enumString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static EnumNumberEnum fromValue(String text) {
private EnumNumberEnum enumNumber;

@JsonProperty("outerEnum")
private OuterEnum outerEnum = null;
private OuterEnum outerEnum;

public EnumTest enumString(EnumStringEnum enumString) {
this.enumString = enumString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public static EnumNumberEnum fromValue(String text) {
private EnumNumberEnum enumNumber;

@JsonProperty("outerEnum")
private OuterEnum outerEnum = null;
private OuterEnum outerEnum;

public EnumTest enumString(EnumStringEnum enumString) {
this.enumString = enumString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static EnumNumberEnum fromValue(String text) {
private EnumNumberEnum enumNumber;

@JsonProperty("outerEnum")
private OuterEnum outerEnum = null;
private OuterEnum outerEnum;

public EnumTest enumString(EnumStringEnum enumString) {
this.enumString = enumString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public static EnumNumberEnum fromValue(String text) {
private EnumNumberEnum enumNumber;

@JsonProperty("outerEnum")
private OuterEnum outerEnum = null;
private OuterEnum outerEnum;

public EnumTest enumString(EnumStringEnum enumString) {
this.enumString = enumString;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public EnumNumberEnum read(final JsonReader jsonReader) throws IOException {

public static final String SERIALIZED_NAME_OUTER_ENUM = "outerEnum";
@SerializedName(SERIALIZED_NAME_OUTER_ENUM)
private OuterEnum outerEnum = null;
private OuterEnum outerEnum;

public EnumTest() {
}
Expand Down
21 changes: 21 additions & 0 deletions samples/client/petstore/java/okhttp-gson/bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# exclude jar for gradle wrapper
!gradle/wrapper/*.jar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# build files
**/target
target
.gradle
build
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4.0.0-SNAPSHOT
17 changes: 17 additions & 0 deletions samples/client/petstore/java/okhttp-gson/bin/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# Generated by: https://openapi-generator.tech
#
language: java
jdk:
- oraclejdk8
- oraclejdk7
before_install:
# ensure gradlew has proper permission
- chmod a+x ./gradlew
script:
# test using maven
- mvn test
# uncomment below to test using gradle
# - gradle test
# uncomment below to test using sbt
# - sbt test
Loading