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

On enum name sanitize, convert colon to underscore #20391

Merged
merged 1 commit into from
Jan 6, 2025
Merged
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 @@ -6524,6 +6524,9 @@ public String sanitizeName(final String name, String removeCharRegEx, ArrayList<
// input.name => input_name
modifiable = this.sanitizeValue(modifiable, "\\.", "_", exceptions);

// input:name => input_name
modifiable = this.sanitizeValue(modifiable, ":", "_", exceptions);

// input-name => input_name
modifiable = this.sanitizeValue(modifiable, "-", "_", exceptions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public String sanitizeModelName(String modelName) {
String[] parts = modelName.split("::");
ArrayList<String> new_parts = new ArrayList<String>();
for (String part : parts) {
new_parts.add(sanitizeName(part));
new_parts.add(sanitizeName(part, "\\W", new ArrayList<>(List.of(":"))));
wing328 marked this conversation as resolved.
Show resolved Hide resolved
}
return String.join("::", new_parts);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ public void restrictedCharactersPropertiesTest() {

final CodegenProperty property = cm.vars.get(0);
Assert.assertEquals(property.baseName, "@Some:restricted%characters#to!handle+");
Assert.assertEquals(property.getter, "getAtSomeColonRestrictedPercentCharactersHashToExclamationHandlePlus");
Assert.assertEquals(property.setter, "setAtSomeColonRestrictedPercentCharactersHashToExclamationHandlePlus");
Assert.assertEquals(property.getter, "getAtSomeRestrictedPercentCharactersHashToExclamationHandlePlus");
Assert.assertEquals(property.setter, "setAtSomeRestrictedPercentCharactersHashToExclamationHandlePlus");
Assert.assertEquals(property.dataType, "Boolean");
Assert.assertEquals(property.name, "atSomeColonRestrictedPercentCharactersHashToExclamationHandlePlus");
Assert.assertEquals(property.name, "atSomeRestrictedPercentCharactersHashToExclamationHandlePlus");
Assert.assertNull(property.defaultValue);
Assert.assertEquals(property.baseType, "Boolean");
Assert.assertFalse(property.required);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void toEnumVarName() {
Assert.assertEquals(codegen.toEnumVarName("valid_var", "string"), "ValidVar");
Assert.assertEquals(codegen.toEnumVarName("-valid_var+", "string"), "ValidVar");
Assert.assertEquals(codegen.toEnumVarName("30valid_+var", "string"), "_30validVar");
Assert.assertEquals(codegen.toEnumVarName("VALID:var", "string"), "ValidVar");

codegen = new TypeScriptFetchClientCodegen();
codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, "original");
Expand All @@ -142,6 +143,7 @@ public void toEnumVarName() {
Assert.assertEquals(codegen.toEnumVarName("valid_var", "string"), "valid_var");
Assert.assertEquals(codegen.toEnumVarName("-valid_var+", "string"), "valid_var");
Assert.assertEquals(codegen.toEnumVarName("30valid_+var", "string"), "_30valid_var");
Assert.assertEquals(codegen.toEnumVarName("VALID:var", "string"), "VALID_var");

codegen = new TypeScriptFetchClientCodegen();
codegen.additionalProperties().put(CodegenConstants.ENUM_PROPERTY_NAMING, "UPPERCASE");
Expand All @@ -153,7 +155,7 @@ public void toEnumVarName() {
Assert.assertEquals(codegen.toEnumVarName("-valid_+var", "string"), "MINUS_VALID_PLUS_VAR");
Assert.assertEquals(codegen.toEnumVarName("-valid_var+", "string"), "MINUS_VALID_VAR_PLUS");
Assert.assertEquals(codegen.toEnumVarName("30valid_+var", "string"), "_30VALID_PLUS_VAR");

Assert.assertEquals(codegen.toEnumVarName("VALID:var", "string"), "VALID_VAR");
}

@Test
Expand Down
Loading