Add CodegenProperty.nameInSnakeCase (#42)

This commit is contained in:
Jérémie Bresson
2018-05-15 13:17:04 +02:00
committed by GitHub
parent f0234b8ab4
commit 673f2bc469
224 changed files with 1260 additions and 1237 deletions

View File

@@ -68,6 +68,7 @@ public class CodegenProperty implements Cloneable {
public boolean isInherited;
public String discriminatorValue;
public String nameInCamelCase; // property name in camel case
public String nameInSnakeCase; // property name in upper snake case
// enum name based on the property name, usually use as a prefix (e.g. VAR_NAME) for enum name (e.g. VAR_NAME_VALUE1)
public String enumName;
public Integer maxItems;
@@ -344,6 +345,10 @@ public class CodegenProperty implements Cloneable {
this.nameInCamelCase = nameInCamelCase;
}
public String getNameInSnakeCase() {
return nameInSnakeCase;
}
public String getEnumName() {
return enumName;
}
@@ -456,6 +461,7 @@ public class CodegenProperty implements Cloneable {
result = prime * result + Objects.hashCode(isInherited);
result = prime * result + Objects.hashCode(discriminatorValue);
result = prime * result + Objects.hashCode(nameInCamelCase);
result = prime * result + Objects.hashCode(nameInSnakeCase);
result = prime * result + Objects.hashCode(enumName);
result = prime * result + ((maxItems == null) ? 0 : maxItems.hashCode());
result = prime * result + ((minItems == null) ? 0 : minItems.hashCode());
@@ -642,6 +648,9 @@ public class CodegenProperty implements Cloneable {
if (!Objects.equals(this.nameInCamelCase, other.nameInCamelCase)) {
return false;
}
if (!Objects.equals(this.nameInSnakeCase, other.nameInSnakeCase)) {
return false;
}
if (!Objects.equals(this.enumName, other.enumName)) {
return false;
}

View File

@@ -18,6 +18,7 @@
package org.openapitools.codegen;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.CaseFormat;
import com.samskivert.mustache.Mustache.Compiler;
import io.swagger.v3.core.util.Json;
@@ -1636,6 +1637,7 @@ public class DefaultCodegen implements CodegenConfig {
property.name = toVarName(name);
property.baseName = name;
property.nameInCamelCase = camelize(property.name, false);
property.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, property.nameInCamelCase);
property.description = escapeText(p.getDescription());
property.unescapedDescription = p.getDescription();
property.title = p.getTitle();