Skip to content

Commit ddb5ab4

Browse files
authored
Add name in various cases in property, parameter names (#18139)
* create nameInPascalCase * add back name in camel case * update abstract cpp codegen * update erlang templates, update samples * update tests * add param names in various cases * clean up * fix
1 parent 3155a70 commit ddb5ab4

76 files changed

Lines changed: 219 additions & 164 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public class CodegenParameter implements IJsonSchemaValidationProperties {
3939
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumDefaultValue, enumName, style;
4040

4141
public String nameInLowerCase; // property name in lower case
42+
public String nameInCamelCase; // property name in camel case (e.g. modifiedDate)
43+
public String nameInPascalCase; // property name in pascal case (e.g. ModifiedDate)
44+
public String nameInSnakeCase; // property name in upper snake case
4245
public String example; // example value (x-example)
4346
public Map<String, Example> examples;
4447
public String jsonSchema;
@@ -184,6 +187,11 @@ public CodegenParameter copy() {
184187
output.additionalProperties = this.additionalProperties;
185188
output.isNull = this.isNull;
186189
output.isVoid = this.isVoid;
190+
output.nameInPascalCase = this.nameInPascalCase;
191+
output.nameInCamelCase = this.nameInCamelCase;
192+
output.nameInLowerCase = this.nameInLowerCase;
193+
output.nameInSnakeCase = this.nameInSnakeCase;
194+
187195
output.setAdditionalPropertiesIsAnyType(this.getAdditionalPropertiesIsAnyType());
188196
output.setHasVars(this.hasVars);
189197
output.setHasRequired(this.hasRequired);
@@ -265,7 +273,22 @@ public CodegenParameter copy() {
265273

266274
@Override
267275
public int hashCode() {
268-
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, containerType, containerTypeMapped, defaultValue, enumDefaultValue, enumName, style, isDeepObject, isMatrix, isAllowEmptyValue, example, examples, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, isEnumRef, _enum, allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, isDeprecated, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull, isVoid, additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger, hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, schema, content, requiredVarsMap, ref, uniqueItemsBoolean, schemaIsFromAdditionalProperties);
276+
return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam,
277+
isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName,
278+
paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description,
279+
unescapedDescription, baseType, containerType, containerTypeMapped, defaultValue,
280+
enumDefaultValue, enumName, style, isDeepObject, isMatrix, isAllowEmptyValue, example, examples,
281+
jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal,
282+
isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword,
283+
isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, isEnumRef, _enum, allowableValues,
284+
items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation,
285+
getMaxProperties(), getMinProperties(), isNullable, isDeprecated, required, getMaximum(),
286+
getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(),
287+
getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull,isVoid,
288+
additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger,
289+
hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, schema, content,
290+
requiredVarsMap, ref, uniqueItemsBoolean, schemaIsFromAdditionalProperties,
291+
nameInPascalCase, nameInCamelCase, nameInLowerCase, nameInSnakeCase);
269292
}
270293

271294
@Override

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenProperty.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ public class CodegenProperty implements Cloneable, IJsonSchemaValidationProperti
182182
public boolean hasValidation; // true if pattern, maximum, etc are set (only used in the mustache template)
183183
public boolean isInherited;
184184
public String discriminatorValue;
185+
185186
public String nameInLowerCase; // property name in lower case
186-
public String nameInCamelCase; // property name in camel case
187+
public String nameInCamelCase; // property name in camel case (e.g. modifiedDate)
188+
public String nameInPascalCase; // property name in pascal case (e.g. ModifiedDate)
187189
public String nameInSnakeCase; // property name in upper snake case
188190
// enum name based on the property name, usually use as a prefix (e.g. VAR_NAME) for enum name (e.g. VAR_NAME_VALUE1)
189191
public String enumName;
@@ -697,6 +699,14 @@ public void setNameInCamelCase(String nameInCamelCase) {
697699
this.nameInCamelCase = nameInCamelCase;
698700
}
699701

702+
public String getNameInPascalCase() {
703+
return nameInPascalCase;
704+
}
705+
706+
public void setNameInPascalCase(String nameInPascalCase) {
707+
this.nameInPascalCase = nameInPascalCase;
708+
}
709+
700710
public String getNameInSnakeCase() {
701711
return nameInSnakeCase;
702712
}
@@ -1213,6 +1223,7 @@ public String toString() {
12131223
sb.append(", isInherited=").append(isInherited);
12141224
sb.append(", discriminatorValue='").append(discriminatorValue).append('\'');
12151225
sb.append(", nameInCamelCase='").append(nameInCamelCase).append('\'');
1226+
sb.append(", nameInPascalCase='").append(nameInPascalCase).append('\'');
12161227
sb.append(", nameInSnakeCase='").append(nameInSnakeCase).append('\'');
12171228
sb.append(", enumName='").append(enumName).append('\'');
12181229
sb.append(", maxItems=").append(maxItems);
@@ -1352,6 +1363,7 @@ public boolean equals(Object o) {
13521363
Objects.equals(vendorExtensions, that.vendorExtensions) &&
13531364
Objects.equals(discriminatorValue, that.discriminatorValue) &&
13541365
Objects.equals(nameInCamelCase, that.nameInCamelCase) &&
1366+
Objects.equals(nameInPascalCase, that.nameInPascalCase) &&
13551367
Objects.equals(nameInSnakeCase, that.nameInSnakeCase) &&
13561368
Objects.equals(enumName, that.enumName) &&
13571369
Objects.equals(maxItems, that.maxItems) &&
@@ -1376,7 +1388,7 @@ public int hashCode() {
13761388
isArray, isMap, isEnum, isInnerEnum, isEnumRef, isAnyType, isReadOnly, isWriteOnly, isNullable, isShort,
13771389
isUnboundedInteger, isSelfReference, isCircularReference, isDiscriminator, isNew, isOverridden, _enum,
13781390
allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars,
1379-
vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInCamelCase,
1391+
vendorExtensions, hasValidation, isInherited, discriminatorValue, nameInPascalCase, nameInCamelCase,
13801392
nameInSnakeCase, enumName, maxItems, minItems, isXmlAttribute, xmlPrefix, xmlName,
13811393
xmlNamespace, isXmlWrapped, isNull, isVoid, additionalPropertiesIsAnyType, hasVars, hasRequired,
13821394
hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, requiredVarsMap,

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import org.openapitools.codegen.serializer.SerializerUtils;
6666
import org.openapitools.codegen.templating.MustacheEngineAdapter;
6767
import org.openapitools.codegen.templating.mustache.*;
68+
import org.openapitools.codegen.utils.CamelizeOption;
6869
import org.openapitools.codegen.utils.ModelUtils;
6970
import org.openapitools.codegen.utils.OneOfImplementorAdditionalData;
7071
import org.slf4j.Logger;
@@ -82,6 +83,7 @@
8283
import java.util.stream.Stream;
8384

8485
import static org.openapitools.codegen.CodegenConstants.UNSUPPORTED_V310_SPEC_MSG;
86+
import static org.openapitools.codegen.utils.CamelizeOption.LOWERCASE_FIRST_LETTER;
8587
import static org.openapitools.codegen.utils.OnceLogger.once;
8688
import static org.openapitools.codegen.utils.StringUtils.*;
8789

@@ -4012,8 +4014,9 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
40124014
} else {
40134015
property.openApiType = p.getType();
40144016
}
4015-
property.nameInCamelCase = camelize(property.name);
4016-
property.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, property.nameInCamelCase);
4017+
property.nameInPascalCase = camelize(property.name);
4018+
property.nameInCamelCase = camelize(property.name, LOWERCASE_FIRST_LETTER);
4019+
property.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, property.nameInPascalCase);
40174020
property.description = escapeText(p.getDescription());
40184021
property.unescapedDescription = p.getDescription();
40194022
property.title = p.getTitle();
@@ -5458,6 +5461,11 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
54585461
codegenParameter.isCollectionFormatMulti = true;
54595462
}
54605463
codegenParameter.paramName = toParamName(parameter.getName());
5464+
codegenParameter.nameInCamelCase = camelize(codegenParameter.paramName, LOWERCASE_FIRST_LETTER);
5465+
codegenParameter.nameInPascalCase = camelize(codegenParameter.paramName);
5466+
codegenParameter.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, codegenParameter.nameInPascalCase);
5467+
codegenParameter.nameInLowerCase = codegenParameter.paramName.toLowerCase(Locale.ROOT);
5468+
54615469
// import
54625470
if (codegenProperty.complexType != null) {
54635471
imports.add(codegenProperty.complexType);
@@ -7185,6 +7193,11 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
71857193
codegenParameter.dataType = codegenProperty.dataType;
71867194
codegenParameter.baseName = codegenProperty.baseName;
71877195
codegenParameter.paramName = toParamName(codegenParameter.baseName);
7196+
codegenParameter.nameInCamelCase = camelize(codegenParameter.paramName, LOWERCASE_FIRST_LETTER);
7197+
codegenParameter.nameInPascalCase = camelize(codegenParameter.paramName);
7198+
codegenParameter.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, codegenParameter.nameInPascalCase);
7199+
codegenParameter.nameInLowerCase = codegenParameter.paramName.toLowerCase(Locale.ROOT);
7200+
71887201
codegenParameter.dataFormat = codegenProperty.dataFormat;
71897202
// non-array/map
71907203
updateCodegenPropertyEnum(codegenProperty);
@@ -7569,6 +7582,11 @@ protected void updateRequestBodyForArray(CodegenParameter codegenParameter, Sche
75697582
codegenParameter.baseName = bodyParameterName;
75707583
}
75717584
codegenParameter.paramName = toArrayModelParamName(codegenParameter.baseName);
7585+
codegenParameter.nameInCamelCase = camelize(codegenParameter.paramName, LOWERCASE_FIRST_LETTER);
7586+
codegenParameter.nameInPascalCase = camelize(codegenParameter.paramName);
7587+
codegenParameter.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, codegenParameter.nameInPascalCase);
7588+
codegenParameter.nameInLowerCase = codegenParameter.paramName.toLowerCase(Locale.ROOT);
7589+
75727590
codegenParameter.items = codegenProperty.items;
75737591
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
75747592
codegenParameter.dataType = getTypeDeclaration(arraySchema);

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractAdaCodegen.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,9 @@ else if ("Integer".equals(datatype) || "Long".equals(datatype) ||
469469
public CodegenProperty fromProperty(String name, Schema p, boolean required) {
470470
CodegenProperty property = super.fromProperty(name, p, required);
471471
if (property != null) {
472-
String nameInCamelCase = property.nameInCamelCase;
473-
nameInCamelCase = sanitizeName(nameInCamelCase);
474-
property.nameInCamelCase = nameInCamelCase;
472+
String nameInPascalCase = property.nameInPascalCase;
473+
nameInPascalCase = sanitizeName(nameInPascalCase);
474+
property.nameInPascalCase = nameInPascalCase;
475475
}
476476
return property;
477477
}
@@ -650,10 +650,6 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
650650
}
651651
}
652652
}
653-
for (CodegenProperty header : rsp.headers) {
654-
header.nameInCamelCase = toModelName(header.baseName);
655-
header.nameInLowerCase = header.baseName.toLowerCase(Locale.ROOT);
656-
}
657653
}
658654

659655
return op;
@@ -845,10 +841,6 @@ private void postProcessOperationWithModels(CodegenOperation op, List<ModelMap>
845841
}
846842
}
847843
}
848-
for (CodegenProperty header : rsp.headers) {
849-
header.nameInCamelCase = toModelName(header.baseName);
850-
header.nameInLowerCase = header.baseName.toLowerCase(Locale.ROOT);
851-
}
852844
}
853845

854846
/*

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public String toParamName(String name) {
280280
@Override
281281
public CodegenProperty fromProperty(String name, Schema p, boolean required) {
282282
CodegenProperty property = super.fromProperty(name, p, required);
283-
String nameInCamelCase = property.nameInCamelCase;
283+
String nameInCamelCase = property.nameInPascalCase;
284284
if (nameInCamelCase.length() > 1) {
285285
nameInCamelCase = sanitizeName(Character.toLowerCase(nameInCamelCase.charAt(0)) + nameInCamelCase.substring(1));
286286
} else {

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractKotlinCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ public String toEnumVarName(String value, String datatype) {
648648

649649
@Override
650650
public String toEnumName(CodegenProperty property) {
651-
return property.nameInCamelCase;
651+
return property.nameInPascalCase;
652652
}
653653

654654
@Override

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ private PythonType getType(CodegenProperty cp) {
20622062
values.add((String) enumVar.get("value"));
20632063
}
20642064
}
2065-
return String.format(Locale.ROOT, "%sEnum", cp.nameInCamelCase);
2065+
return String.format(Locale.ROOT, "%sEnum", cp.nameInPascalCase);
20662066
} else*/
20672067

20682068
if (result == null) {

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonPydanticV1Codegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,7 @@ private String getPydanticType(CodegenProperty cp,
13511351
values.add((String) enumVar.get("value"));
13521352
}
13531353
}
1354-
return String.format(Locale.ROOT, "%sEnum", cp.nameInCamelCase);
1354+
return String.format(Locale.ROOT, "%sEnum", cp.nameInPascalCase);
13551355
} else*/
13561356
if (cp.isArray) {
13571357
String constraints = "";

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required) {
453453
CodegenProperty prop = super.fromProperty(name, p, required);
454454
String cc = camelize(prop.name, LOWERCASE_FIRST_LETTER);
455455
if (isReservedWord(cc)) {
456-
cc = escapeReservedWord(cc);
456+
cc = escapeReservedWord(cc); // e.g. byte => byte_
457457
}
458458
prop.nameInCamelCase = cc;
459459
return prop;

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RustAxumServerCodegen.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -550,20 +550,6 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
550550
}
551551
}
552552
}
553-
554-
for (CodegenProperty header : rsp.headers) {
555-
header.nameInCamelCase = toModelName(header.baseName);
556-
header.nameInLowerCase = header.baseName.toLowerCase(Locale.ROOT);
557-
}
558-
}
559-
560-
for (CodegenParameter header : op.headerParams) {
561-
header.nameInLowerCase = header.baseName.toLowerCase(Locale.ROOT);
562-
}
563-
564-
for (CodegenProperty header : op.responseHeaders) {
565-
header.nameInCamelCase = toModelName(header.baseName);
566-
header.nameInLowerCase = header.baseName.toLowerCase(Locale.ROOT);
567553
}
568554

569555
return op;
@@ -636,15 +622,6 @@ private void postProcessOperationWithModels(CodegenOperation op) {
636622
param.vendorExtensions.put("x-consumes-json", true);
637623
}
638624
}
639-
640-
for (CodegenParameter header : op.headerParams) {
641-
header.nameInLowerCase = header.baseName.toLowerCase(Locale.ROOT);
642-
}
643-
644-
for (CodegenProperty header : op.responseHeaders) {
645-
header.nameInCamelCase = toModelName(header.baseName);
646-
header.nameInLowerCase = header.baseName.toLowerCase(Locale.ROOT);
647-
}
648625
}
649626

650627
@Override

0 commit comments

Comments
 (0)