Skip to content
Open
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 @@ -19,7 +19,7 @@

import java.util.*;

public class CodegenProperty implements Cloneable {
public class CodegenProperty implements Cloneable, Comparable<CodegenProperty> {
public String openApiType, baseName, complexType, getter, setter, description, dataType,
datatypeWithEnum, dataFormat, name, min, max, defaultValue, defaultValueWithParam,
baseType, containerType, title;
Expand Down Expand Up @@ -680,6 +680,18 @@ public java.lang.String toString() {
", isXmlWrapped=" + isXmlWrapped +
'}';
}

/**
* Allow sorting vars based on data-type
*/
@Override
public int compareTo(CodegenProperty that) {
if (getDatatypeWithEnum() == null || that.getDatatypeWithEnum() == null) {
return 0;
}
else if (getDatatypeWithEnum().compareTo(that.getDatatypeWithEnum()) == 0){
return getNameInCamelCase().compareTo(that.getNameInCamelCase());
}
return getDatatypeWithEnum().compareTo(that.getDatatypeWithEnum());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1923,6 +1923,7 @@ public CodegenModel fromModel(String name, Schema schema) {

// post process model properties
if (m.vars != null) {
m.vars.sort(null);
for (CodegenProperty prop : m.vars) {
postProcessModelProperty(m, prop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@ public void processOpts() {
}
} else if (dateLibrary.equals("legacy")) {
additionalProperties.put("legacyDates", "true");
} else if ("calendar".equals(dateLibrary)) {
typeMapping.put("date", "Calendar");
typeMapping.put("DateTime", "Calendar");
importMapping.put("Calendar", "java.util.Calendar");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public AbstractTypeScriptClientCodegen() {
typeMapping.put("Map", "any");
typeMapping.put("map", "any");
typeMapping.put("date", "string");
typeMapping.put("DateTime", "Date");
typeMapping.put("DateTime", "string");
typeMapping.put("binary", "any");
typeMapping.put("File", "any");
typeMapping.put("ByteArray", "string");
Expand Down Expand Up @@ -315,10 +315,12 @@ public String getTypeDeclaration(Schema p) {
if (ModelUtils.isArraySchema(p)) {
ArraySchema ap = (ArraySchema) p;
Schema inner = ap.getItems();
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
return getTypeDeclaration(inner) + "[]";
// return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">";
} else if (ModelUtils.isMapSchema(p)) {
Schema inner = ModelUtils.getAdditionalProperties(p);
return "{ [key: string]: " + getTypeDeclaration(inner) + "; }";
return "Map<string, " + getTypeDeclaration(inner) + ">";
// return "{ [key: string]: " + getTypeDeclaration(inner) + "; }";
} else if (ModelUtils.isFileSchema(p)) {
return "any";
} else if (ModelUtils.isBinarySchema(p)) {
Expand All @@ -334,10 +336,12 @@ protected String getParameterDataType(Parameter parameter, Schema p) {
if (ModelUtils.isArraySchema(p)) {
ArraySchema mp1 = (ArraySchema) p;
inner = mp1.getItems();
return this.getSchemaType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
return this.getParameterDataType(parameter, inner) + "[]";
// return this.getSchemaType(p) + "<" + this.getParameterDataType(parameter, inner) + ">";
} else if (ModelUtils.isMapSchema(p)) {
inner = ModelUtils.getAdditionalProperties(p);
return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
return "Map<string, " + this.getParameterDataType(parameter, inner) + ">";
// return "{ [key: string]: " + this.getParameterDataType(parameter, inner) + "; }";
} else if (ModelUtils.isStringSchema(p)) {
// Handle string enums
if (p.getEnum() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,15 @@ public void processOpts() {
additionalProperties.put("configOptions", configOptions);

// Process java8 option before common java ones to change the default dateLibrary to java8.
LOGGER.info("----------------------------------");
if (additionalProperties.containsKey(JAVA_8)) {
LOGGER.info("has JAVA8");
this.setJava8(Boolean.valueOf(additionalProperties.get(JAVA_8).toString()));
additionalProperties.put(JAVA_8, java8);
}
if (this.java8 && !additionalProperties.containsKey(DATE_LIBRARY)) {
setDateLibrary("java8");
}
// LOGGER.info("----------------------------------");
// if (additionalProperties.containsKey(JAVA_8)) {
// LOGGER.info("has JAVA8");
// this.setJava8(Boolean.valueOf(additionalProperties.get(JAVA_8).toString()));
// additionalProperties.put(JAVA_8, java8);
// }
// if (this.java8 && !additionalProperties.containsKey(DATE_LIBRARY)) {
// setDateLibrary("java8");
// }

if (!additionalProperties.containsKey(BASE_PACKAGE) && additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
// set invokerPackage as basePackage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public String toModelFilename(String name) {
return importMapping.get(name);
}

return DEFAULT_IMPORT_PREFIX + camelize(toModelName(name), true);
return DEFAULT_IMPORT_PREFIX + camelize(toModelName(name), false);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ public static String camelize(String word, boolean lowercaseFirstLetter) {
}

// Remove all underscores (underscore_case to camelCase)
p = Pattern.compile("(_)(.)");
m = p.matcher(word);
while (m.find()) {
String original = m.group(2);
String upperCase = original.toUpperCase(Locale.ROOT);
if (original.equals(upperCase)) {
word = word.replaceFirst("_", "");
} else {
word = m.replaceFirst(upperCase);
}
m = p.matcher(word);
}
// p = Pattern.compile("(_)(.)");
// m = p.matcher(word);
// while (m.find()) {
// String original = m.group(2);
// String upperCase = original.toUpperCase(Locale.ROOT);
// if (original.equals(upperCase)) {
// word = word.replaceFirst("_", "");
// } else {
// word = m.replaceFirst(upperCase);
// }
// m = p.matcher(word);
// }

// Remove all hyphens (hyphen-case to camelCase)
p = Pattern.compile("(-)(.)");
Expand All @@ -130,7 +130,7 @@ public static String camelize(String word, boolean lowercaseFirstLetter) {
}

// remove all underscore
word = word.replaceAll("_", "");
// word = word.replaceAll("_", "");

return word;
}
Expand Down
125 changes: 67 additions & 58 deletions modules/openapi-generator/src/main/resources/Java/pojo.mustache
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import android.util.Log;
import com.google.gson.Gson;
import co.poynt.model.Utils;

/**
* {{#description}}{{.}}{{/description}}{{^description}}{{classname}}{{/description}}
*/{{#description}}
@ApiModel(description = "{{{description}}}"){{/description}}
{{>generatedAnnotation}}{{#discriminator}}{{>typeInfoAnnotation}}{{/discriminator}}{{>xmlAnnotation}}
public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcelableModel}}implements Parcelable {{#serializableModel}}, Serializable {{/serializableModel}}{{/parcelableModel}}{{^parcelableModel}}{{#serializableModel}}implements Serializable {{/serializableModel}}{{/parcelableModel}}{

private static final String TAG = "{{classname}}";

{{#serializableModel}}
private static final long serialVersionUID = 1L;

Expand Down Expand Up @@ -59,10 +66,22 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
public static final String SERIALIZED_NAME_{{nameInSnakeCase}} = "{{baseName}}";
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
{{/gson}}
private {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};
protected {{{datatypeWithEnum}}} {{name}}{{#defaultValue}} = {{{.}}}{{/defaultValue}};

{{/vars}}
{{#parcelableModel}}

public {{classname}}({{#vars}}{{{datatypeWithEnum}}} {{name}}{{^-last}}, {{/-last}}{{/vars}}) {
{{#parent}}
super();
{{/parent}}
{{#gson}}
{{#discriminator}}
this.{{{discriminatorName}}} = this.getClass().getSimpleName();
{{/discriminator}}
{{/gson}}
}

public {{classname}}() {
{{#parent}}
super();
Expand Down Expand Up @@ -168,8 +187,8 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
return false;
}{{#hasVars}}
{{classname}} {{classVarName}} = ({{classname}}) o;
return {{#vars}}{{#isByteArray}}Arrays{{/isByteArray}}{{^isByteArray}}Objects{{/isByteArray}}.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
{{/hasMore}}{{/vars}}{{#parent}} &&
return {{#vars}}{{#isByteArray}}Arrays{{/isByteArray}}{{^isByteArray}}Objects{{/isByteArray}}.equals(this.{{name}}, {{classVarName}}.{{name}}){{^-last}} &&
{{/-last}}{{/vars}}{{#parent}} &&
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
return {{#parent}}super.equals(o){{/parent}}{{^parent}}true{{/parent}};{{/hasVars}}
{{/useReflectionEqualsHashCode}}
Expand All @@ -181,7 +200,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
return HashCodeBuilder.reflectionHashCode(this);
{{/useReflectionEqualsHashCode}}
{{^useReflectionEqualsHashCode}}
return Objects.hash({{#vars}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
return Objects.hash({{#vars}}{{^isByteArray}}{{name}}{{/isByteArray}}{{#isByteArray}}Arrays.hashCode({{name}}){{/isByteArray}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
{{/useReflectionEqualsHashCode}}
}

Expand All @@ -196,15 +215,15 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
return false;
}{{#hasVars}}
{{classname}} {{classVarName}} = ({{classname}}) o;
return {{#vars}}ObjectUtils.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
{{/hasMore}}{{/vars}}{{#parent}} &&
return {{#vars}}ObjectUtils.equals(this.{{name}}, {{classVarName}}.{{name}}){{^-last}} &&
{{/-last}}{{/vars}}{{#parent}} &&
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
return true;{{/hasVars}}
}

@Override
public int hashCode() {
return ObjectUtils.hashCodeMulti({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
return ObjectUtils.hashCodeMulti({{#vars}}{{name}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
}

{{/supportJava6}}
Expand Down Expand Up @@ -235,62 +254,52 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
}

{{#parcelableModel}}

public void writeToParcel(Parcel out, int flags) {
{{#model}}
{{#isArrayModel}}
out.writeList(this);
{{/isArrayModel}}
{{^isArrayModel}}
{{#parent}}
super.writeToParcel(out, flags);
{{/parent}}
{{#vars}}
out.writeValue({{name}});
{{/vars}}
{{/isArrayModel}}
{{/model}}
}

{{classname}}(Parcel in) {
{{#isArrayModel}}
in.readTypedList(this, {{arrayModelType}}.CREATOR);
{{/isArrayModel}}
{{^isArrayModel}}
{{#parent}}
super(in);
{{/parent}}
{{#vars}}
{{#isPrimitiveType}}
{{name}} = ({{{datatypeWithEnum}}})in.readValue(null);
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{name}} = ({{{datatypeWithEnum}}})in.readValue({{complexType}}.class.getClassLoader());
{{/isPrimitiveType}}
{{/vars}}
{{/isArrayModel}}
public int describeContents() {
return 0;
}

public int describeContents() {
return 0;
public void writeToParcel(Parcel parcel, int flags) {
long startTime = System.currentTimeMillis();
try {
Gson gson = Utils.getGsonObject();
String jsonString = gson.toJson(this);
byte[] compressedBytes = Utils.compress(jsonString);
parcel.writeInt(compressedBytes.length);
parcel.writeByteArray(compressedBytes);
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
Log.d(TAG, " MEASURE_TIME Total write time "+elapsedTime + " size:"+jsonString.length() + " compressedSize:"+compressedBytes.length);
} catch (IOException e) {
e.printStackTrace();
}
}

public static final Parcelable.Creator<{{classname}}> CREATOR = new Parcelable.Creator<{{classname}}>() {
public {{classname}} createFromParcel(Parcel in) {
{{#model}}
{{#isArrayModel}}
{{classname}} result = new {{classname}}();
result.addAll(in.readArrayList({{arrayModelType}}.class.getClassLoader()));
return result;
{{/isArrayModel}}
{{^isArrayModel}}
return new {{classname}}(in);
{{/isArrayModel}}
{{/model}}
}
public {{classname}}[] newArray(int size) {
return new {{classname}}[size];
}

public {{classname}}[] newArray(int size) {
return new {{classname}}[size];
}

public {{classname}} createFromParcel(Parcel source) {
long startTime = System.currentTimeMillis();
int length = source.readInt();
byte[] bytes = new byte[length];
source.readByteArray(bytes);
try {
String jString = Utils.decompress(bytes);
Log.d(TAG, " MEASURE_TIME Received bytes "+bytes.length+ " json size:"+jString.length() );
Gson gson = Utils.getGsonObject();
{{classname}} object = gson.fromJson(jString, {{classname}}.class);
Log.d(TAG, " Gson Json string size:" + jString.length());
long stopTime = System.currentTimeMillis();
long elapsedTime = stopTime - startTime;
Log.d(TAG, " MEASURE_TIME Total read time " + elapsedTime);
return object;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
};
{{/parcelableModel}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}}{{^parent}}
return false;
}{{#hasVars}}
{{classname}} {{classVarName}} = ({{classname}}) o;
return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{#hasMore}} &&
{{/hasMore}}{{/vars}}{{#parent}} &&
return {{#vars}}Objects.equals(this.{{name}}, {{classVarName}}.{{name}}){{^-last}} &&
{{/-last}}{{/vars}}{{#parent}} &&
super.equals(o){{/parent}};{{/hasVars}}{{^hasVars}}
return true;{{/hasVars}}
}

@Override
public int hashCode() {
return Objects.hash({{#vars}}{{name}}{{#hasMore}}, {{/hasMore}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
return Objects.hash({{#vars}}{{name}}{{^-last}}, {{/-last}}{{/vars}}{{#parent}}{{#hasVars}}, {{/hasVars}}super.hashCode(){{/parent}});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import { {{classname}} } from '{{filename}}';
*/
{{/description}}
{{^isEnum}}
export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
{{#vars}}
{{#description}}
/**
* {{{description}}}
*/
{{/description}}
'{{name}}'{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}};
{{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}};
{{/vars}}

{{#discriminator}}
Expand Down
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1318,7 +1318,7 @@
<module>modules/openapi-generator-cli</module>
<module>modules/openapi-generator-maven-plugin</module>
<module>modules/openapi-generator-gradle-plugin</module>
<module>modules/openapi-generator-online</module>
<!-- <module>modules/openapi-generator-online</module>-->
</modules>
<reporting>
<outputDirectory>target/site</outputDirectory>
Expand Down Expand Up @@ -1382,6 +1382,7 @@
</repository>
</repositories>
<properties>
<maven.test.skip>true</maven.test.skip>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<swagger-parser-groupid>org.openapitools.swagger.parser</swagger-parser-groupid>
Expand Down