Skip to content
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

[Python] Code generator doesn't preserve original case for variables #12509

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -31,6 +31,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
public static final String CAMEL_CASE_OPTION = "camel";
public static final String SNAKE_CASE_OPTION = "snake";
public static final String KEBAB_CASE_OPTION = "kebab";
public static final String ORIGINAL_CASE_OPTION = "original";

protected String packageName; // e.g. petstore_api
protected String packageVersion;
Expand Down Expand Up @@ -308,7 +309,7 @@ public void postProcessPattern(String pattern, Map<String, Object> vendorExtensi

protected void setCaseType() {
final String caseType = String.valueOf(additionalProperties.get(CASE_OPTION));
if (CAMEL_CASE_OPTION.equalsIgnoreCase(caseType) || SNAKE_CASE_OPTION.equalsIgnoreCase(caseType) || KEBAB_CASE_OPTION.equalsIgnoreCase(caseType)) {
if (CAMEL_CASE_OPTION.equalsIgnoreCase(caseType) || SNAKE_CASE_OPTION.equalsIgnoreCase(caseType) || KEBAB_CASE_OPTION.equalsIgnoreCase(caseType) || ORIGINAL_CASE_OPTION.equalsIgnoreCase(caseType)) {
this.caseType = caseType;
} else {
this.caseType = SNAKE_CASE_OPTION;
Expand Down Expand Up @@ -425,11 +426,13 @@ public String toVarName(String name) {
// remove dollar sign
name = name.replaceAll("$", "");

// if it's all uppper case, convert to lower case
if (name.matches("^[A-Z_]*$")) {
// if it's all upper case, convert to lower case
if (!ORIGINAL_CASE_OPTION.equalsIgnoreCase(this.caseType) && name.matches("^[A-Z_]*$")) {
name = name.toLowerCase();
}
if (CAMEL_CASE_OPTION.equalsIgnoreCase(this.caseType)) {
if (ORIGINAL_CASE_OPTION.equalsIgnoreCase(this.caseType)) {
// leave the variable name as is
} else if (CAMEL_CASE_OPTION.equalsIgnoreCase(this.caseType)) {
name = camelize(name, true);
} else if (KEBAB_CASE_OPTION.equalsIgnoreCase(this.caseType)) {
name = dashize(name);
Expand Down