Skip to content

Commit

Permalink
Add CodegenProperty.nameInSnakeCase (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmini authored May 15, 2018
1 parent f0234b8 commit 673f2bc
Show file tree
Hide file tree
Showing 224 changed files with 1,260 additions and 1,237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -344,6 +345,10 @@ public void setNameInCamelCase(String nameInCamelCase) {
this.nameInCamelCase = nameInCamelCase;
}

public String getNameInSnakeCase() {
return nameInSnakeCase;
}

public String getEnumName() {
return enumName;
}
Expand Down Expand Up @@ -456,6 +461,7 @@ public int hashCode()
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());
Expand Down Expand Up @@ -642,6 +648,9 @@ public boolean equals(Object obj) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1636,6 +1637,7 @@ public CodegenProperty fromProperty(String name, Schema p) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcela
{{/isXmlAttribute}}
{{/withXml}}
{{#gson}}
public static final String SERIALIZED_NAME_{{nameInCamelCase}} = "{{baseName}}";
@SerializedName(SERIALIZED_NAME_{{nameInCamelCase}})
public static final String SERIALIZED_NAME_{{nameInSnakeCase}} = "{{baseName}}";
@SerializedName(SERIALIZED_NAME_{{nameInSnakeCase}})
{{/gson}}
{{#isContainer}}
private {{{datatypeWithEnum}}} {{name}}{{#required}} = {{{defaultValue}}}{{/required}}{{^required}} = null{{/required}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public void simpleModelTest() {

final CodegenProperty property1 = vars.get(0);
Assert.assertEquals(property1.baseName, "id");
Assert.assertEquals(property1.nameInCamelCase, "Id");
Assert.assertEquals(property1.nameInSnakeCase, "ID");
Assert.assertEquals(property1.getter, "getId");
Assert.assertEquals(property1.setter, "setId");
Assert.assertEquals(property1.datatype, "Long");
Expand All @@ -98,6 +100,8 @@ public void simpleModelTest() {

final CodegenProperty property2 = vars.get(1);
Assert.assertEquals(property2.baseName, "name");
Assert.assertEquals(property2.nameInCamelCase, "Name");
Assert.assertEquals(property2.nameInSnakeCase, "NAME");
Assert.assertEquals(property2.getter, "getName");
Assert.assertEquals(property2.setter, "setName");
Assert.assertEquals(property2.datatype, "String");
Expand All @@ -111,6 +115,8 @@ public void simpleModelTest() {

final CodegenProperty property3 = vars.get(2);
Assert.assertEquals(property3.baseName, "createdAt");
Assert.assertEquals(property3.nameInCamelCase, "CreatedAt");
Assert.assertEquals(property3.nameInSnakeCase, "CREATED_AT");
Assert.assertEquals(property3.getter, "getCreatedAt");
Assert.assertEquals(property3.setter, "setCreatedAt");
Assert.assertEquals(property3.datatype, "Date");
Expand Down Expand Up @@ -790,6 +796,8 @@ public void longPropertyTest() {
final CodegenProperty cp = codegen.fromProperty("property", property);

Assert.assertEquals(cp.baseName, "property");
Assert.assertEquals(cp.nameInCamelCase, "Property");
Assert.assertEquals(cp.nameInSnakeCase, "PROPERTY");
Assert.assertEquals(cp.datatype, "Long");
Assert.assertEquals(cp.name, "property");
Assert.assertEquals(cp.baseType, "Long");
Expand All @@ -813,13 +821,17 @@ public void integerPropertyInReferencedSchemaTest() {

CodegenProperty cp1 = cm.vars.get(0);
Assert.assertEquals(cp1.baseName, "Integer1");
Assert.assertEquals(cp1.nameInCamelCase, "Integer1");
Assert.assertEquals(cp1.nameInSnakeCase, "INTEGER1");
Assert.assertEquals(cp1.datatype, "Integer");
Assert.assertEquals(cp1.name, "integer1");
Assert.assertEquals(cp1.baseType, "Integer");
Assert.assertEquals(cp1.getter, "getInteger1");

CodegenProperty cp2 = cm.vars.get(1);
Assert.assertEquals(cp2.baseName, "Integer2");
Assert.assertEquals(cp2.nameInCamelCase, "Integer2");
Assert.assertEquals(cp2.nameInSnakeCase, "INTEGER2");
Assert.assertEquals(cp2.datatype, "Integer");
Assert.assertEquals(cp2.name, "integer2");
Assert.assertEquals(cp2.baseType, "Integer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Name | Type | Description | Notes
**enumQueryString** | **String**| Query parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]
**enumQueryInteger** | **Integer**| Query parameter enum test (double) | [optional] [enum: 1, -2]
**enumQueryDouble** | **Double**| Query parameter enum test (double) | [optional] [enum: 1.1, -1.2]
**enumFormStringArray** | **List<String>**| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormStringArray** | [**List<String>**](String.md)| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormString** | **String**| Form parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]

### Return type
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/jersey1/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Name | Type | Description | Notes
**enumQueryString** | **String**| Query parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]
**enumQueryInteger** | **Integer**| Query parameter enum test (double) | [optional] [enum: 1, -2]
**enumQueryDouble** | **Double**| Query parameter enum test (double) | [optional] [enum: 1.1, -1.2]
**enumFormStringArray** | **List<String>**| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormStringArray** | [**List<String>**](String.md)| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormString** | **String**| Form parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]

### Return type
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/jersey2-java6/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Name | Type | Description | Notes
**enumQueryString** | **String**| Query parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]
**enumQueryInteger** | **Integer**| Query parameter enum test (double) | [optional] [enum: 1, -2]
**enumQueryDouble** | **Double**| Query parameter enum test (double) | [optional] [enum: 1.1, -1.2]
**enumFormStringArray** | **List<String>**| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormStringArray** | [**List<String>**](String.md)| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormString** | **String**| Form parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]

### Return type
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/jersey2-java8/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Name | Type | Description | Notes
**enumQueryString** | **String**| Query parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]
**enumQueryInteger** | **Integer**| Query parameter enum test (double) | [optional] [enum: 1, -2]
**enumQueryDouble** | **Double**| Query parameter enum test (double) | [optional] [enum: 1.1, -1.2]
**enumFormStringArray** | **List<String>**| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormStringArray** | [**List<String>**](String.md)| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormString** | **String**| Form parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]

### Return type
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/java/jersey2/docs/FakeApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Name | Type | Description | Notes
**enumQueryString** | **String**| Query parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]
**enumQueryInteger** | **Integer**| Query parameter enum test (double) | [optional] [enum: 1, -2]
**enumQueryDouble** | **Double**| Query parameter enum test (double) | [optional] [enum: 1.1, -1.2]
**enumFormStringArray** | **List<String>**| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormStringArray** | [**List<String>**](String.md)| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormString** | **String**| Form parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]

### Return type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ Name | Type | Description | Notes
**enumQueryString** | **String**| Query parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]
**enumQueryInteger** | **Integer**| Query parameter enum test (double) | [optional] [enum: 1, -2]
**enumQueryDouble** | **Double**| Query parameter enum test (double) | [optional] [enum: 1.1, -1.2]
**enumFormStringArray** | **List<String>**| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormStringArray** | [**List<String>**](String.md)| Form parameter enum test (string array) | [optional] [default to $] [enum: >, $]
**enumFormString** | **String**| Form parameter enum test (string) | [optional] [default to -efg] [enum: _abc, -efg, (xyz)]

### Return type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@
*/

public class AdditionalPropertiesClass implements Parcelable {
public static final String SERIALIZED_NAME_MapProperty = "map_property";
@SerializedName(SERIALIZED_NAME_MapProperty)
public static final String SERIALIZED_NAME_MAP_PROPERTY = "map_property";
@SerializedName(SERIALIZED_NAME_MAP_PROPERTY)
private Map<String, String> mapProperty = null;

public static final String SERIALIZED_NAME_MapOfMapProperty = "map_of_map_property";
@SerializedName(SERIALIZED_NAME_MapOfMapProperty)
public static final String SERIALIZED_NAME_MAP_OF_MAP_PROPERTY = "map_of_map_property";
@SerializedName(SERIALIZED_NAME_MAP_OF_MAP_PROPERTY)
private Map<String, Map<String, String>> mapOfMapProperty = null;

public AdditionalPropertiesClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@


public class Animal implements Parcelable {
public static final String SERIALIZED_NAME_ClassName = "className";
@SerializedName(SERIALIZED_NAME_ClassName)
public static final String SERIALIZED_NAME_CLASS_NAME = "className";
@SerializedName(SERIALIZED_NAME_CLASS_NAME)
private String className = null;

public static final String SERIALIZED_NAME_Color = "color";
@SerializedName(SERIALIZED_NAME_Color)
public static final String SERIALIZED_NAME_COLOR = "color";
@SerializedName(SERIALIZED_NAME_COLOR)
private String color = "red";

public Animal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
*/

public class ArrayOfArrayOfNumberOnly implements Parcelable {
public static final String SERIALIZED_NAME_ArrayArrayNumber = "ArrayArrayNumber";
@SerializedName(SERIALIZED_NAME_ArrayArrayNumber)
public static final String SERIALIZED_NAME_ARRAY_ARRAY_NUMBER = "ArrayArrayNumber";
@SerializedName(SERIALIZED_NAME_ARRAY_ARRAY_NUMBER)
private List<List<BigDecimal>> arrayArrayNumber = null;

public ArrayOfArrayOfNumberOnly() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
*/

public class ArrayOfNumberOnly implements Parcelable {
public static final String SERIALIZED_NAME_ArrayNumber = "ArrayNumber";
@SerializedName(SERIALIZED_NAME_ArrayNumber)
public static final String SERIALIZED_NAME_ARRAY_NUMBER = "ArrayNumber";
@SerializedName(SERIALIZED_NAME_ARRAY_NUMBER)
private List<BigDecimal> arrayNumber = null;

public ArrayOfNumberOnly() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
*/

public class ArrayTest implements Parcelable {
public static final String SERIALIZED_NAME_ArrayOfString = "array_of_string";
@SerializedName(SERIALIZED_NAME_ArrayOfString)
public static final String SERIALIZED_NAME_ARRAY_OF_STRING = "array_of_string";
@SerializedName(SERIALIZED_NAME_ARRAY_OF_STRING)
private List<String> arrayOfString = null;

public static final String SERIALIZED_NAME_ArrayArrayOfInteger = "array_array_of_integer";
@SerializedName(SERIALIZED_NAME_ArrayArrayOfInteger)
public static final String SERIALIZED_NAME_ARRAY_ARRAY_OF_INTEGER = "array_array_of_integer";
@SerializedName(SERIALIZED_NAME_ARRAY_ARRAY_OF_INTEGER)
private List<List<Long>> arrayArrayOfInteger = null;

public static final String SERIALIZED_NAME_ArrayArrayOfModel = "array_array_of_model";
@SerializedName(SERIALIZED_NAME_ArrayArrayOfModel)
public static final String SERIALIZED_NAME_ARRAY_ARRAY_OF_MODEL = "array_array_of_model";
@SerializedName(SERIALIZED_NAME_ARRAY_ARRAY_OF_MODEL)
private List<List<ReadOnlyFirst>> arrayArrayOfModel = null;

public ArrayTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@
*/

public class Capitalization implements Parcelable {
public static final String SERIALIZED_NAME_SmallCamel = "smallCamel";
@SerializedName(SERIALIZED_NAME_SmallCamel)
public static final String SERIALIZED_NAME_SMALL_CAMEL = "smallCamel";
@SerializedName(SERIALIZED_NAME_SMALL_CAMEL)
private String smallCamel = null;

public static final String SERIALIZED_NAME_CapitalCamel = "CapitalCamel";
@SerializedName(SERIALIZED_NAME_CapitalCamel)
public static final String SERIALIZED_NAME_CAPITAL_CAMEL = "CapitalCamel";
@SerializedName(SERIALIZED_NAME_CAPITAL_CAMEL)
private String capitalCamel = null;

public static final String SERIALIZED_NAME_SmallSnake = "small_Snake";
@SerializedName(SERIALIZED_NAME_SmallSnake)
public static final String SERIALIZED_NAME_SMALL_SNAKE = "small_Snake";
@SerializedName(SERIALIZED_NAME_SMALL_SNAKE)
private String smallSnake = null;

public static final String SERIALIZED_NAME_CapitalSnake = "Capital_Snake";
@SerializedName(SERIALIZED_NAME_CapitalSnake)
public static final String SERIALIZED_NAME_CAPITAL_SNAKE = "Capital_Snake";
@SerializedName(SERIALIZED_NAME_CAPITAL_SNAKE)
private String capitalSnake = null;

public static final String SERIALIZED_NAME_ScAETHFlowPoints = "SCA_ETH_Flow_Points";
@SerializedName(SERIALIZED_NAME_ScAETHFlowPoints)
public static final String SERIALIZED_NAME_SC_A_E_T_H_FLOW_POINTS = "SCA_ETH_Flow_Points";
@SerializedName(SERIALIZED_NAME_SC_A_E_T_H_FLOW_POINTS)
private String scAETHFlowPoints = null;

public static final String SERIALIZED_NAME_ATTNAME = "ATT_NAME";
@SerializedName(SERIALIZED_NAME_ATTNAME)
public static final String SERIALIZED_NAME_A_T_T_N_A_M_E = "ATT_NAME";
@SerializedName(SERIALIZED_NAME_A_T_T_N_A_M_E)
private String ATT_NAME = null;

public Capitalization() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
*/

public class Cat extends Animal implements Parcelable {
public static final String SERIALIZED_NAME_Declawed = "declawed";
@SerializedName(SERIALIZED_NAME_Declawed)
public static final String SERIALIZED_NAME_DECLAWED = "declawed";
@SerializedName(SERIALIZED_NAME_DECLAWED)
private Boolean declawed = null;

public Cat() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
*/

public class Category implements Parcelable {
public static final String SERIALIZED_NAME_Id = "id";
@SerializedName(SERIALIZED_NAME_Id)
public static final String SERIALIZED_NAME_ID = "id";
@SerializedName(SERIALIZED_NAME_ID)
private Long id = null;

public static final String SERIALIZED_NAME_Name = "name";
@SerializedName(SERIALIZED_NAME_Name)
public static final String SERIALIZED_NAME_NAME = "name";
@SerializedName(SERIALIZED_NAME_NAME)
private String name = null;

public Category() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
@ApiModel(description = "Model for testing model with \"_class\" property")

public class ClassModel implements Parcelable {
public static final String SERIALIZED_NAME_PropertyClass = "_class";
@SerializedName(SERIALIZED_NAME_PropertyClass)
public static final String SERIALIZED_NAME_PROPERTY_CLASS = "_class";
@SerializedName(SERIALIZED_NAME_PROPERTY_CLASS)
private String propertyClass = null;

public ClassModel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
*/

public class Client implements Parcelable {
public static final String SERIALIZED_NAME_Client = "client";
@SerializedName(SERIALIZED_NAME_Client)
public static final String SERIALIZED_NAME_CLIENT = "client";
@SerializedName(SERIALIZED_NAME_CLIENT)
private String client = null;

public Client() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
*/

public class Dog extends Animal implements Parcelable {
public static final String SERIALIZED_NAME_Breed = "breed";
@SerializedName(SERIALIZED_NAME_Breed)
public static final String SERIALIZED_NAME_BREED = "breed";
@SerializedName(SERIALIZED_NAME_BREED)
private String breed = null;

public Dog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public JustSymbolEnum read(final JsonReader jsonReader) throws IOException {
}
}

public static final String SERIALIZED_NAME_JustSymbol = "just_symbol";
@SerializedName(SERIALIZED_NAME_JustSymbol)
public static final String SERIALIZED_NAME_JUST_SYMBOL = "just_symbol";
@SerializedName(SERIALIZED_NAME_JUST_SYMBOL)
private JustSymbolEnum justSymbol = null;

/**
Expand Down Expand Up @@ -131,8 +131,8 @@ public ArrayEnumEnum read(final JsonReader jsonReader) throws IOException {
}
}

public static final String SERIALIZED_NAME_ArrayEnum = "array_enum";
@SerializedName(SERIALIZED_NAME_ArrayEnum)
public static final String SERIALIZED_NAME_ARRAY_ENUM = "array_enum";
@SerializedName(SERIALIZED_NAME_ARRAY_ENUM)
private List<ArrayEnumEnum> arrayEnum = null;

public EnumArrays() {
Expand Down
Loading

0 comments on commit 673f2bc

Please sign in to comment.