Skip to content

Commit

Permalink
#20390 :
Browse files Browse the repository at this point in the history
Manage colon converting to underscore on sanitize
  • Loading branch information
AntoineDuComptoirDesPharmacies committed Dec 31, 2024
1 parent 8f4cfa3 commit 6bd3fb0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
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(":"))));
}
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

0 comments on commit 6bd3fb0

Please sign in to comment.