Manage colon converting to underscore on sanitize
This commit is contained in:
AntoineDuComptoirDesPharmacies 2025-01-06 12:43:05 +01:00 committed by GitHub
parent e154903743
commit 4b5dfc430e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 5 deletions

View File

@ -6524,6 +6524,9 @@ public class DefaultCodegen implements CodegenConfig {
// 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);

View File

@ -405,7 +405,7 @@ public class CrystalClientCodegen extends DefaultCodegen {
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);
}

View File

@ -274,10 +274,10 @@ public class JavaModelTest {
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);

View File

@ -133,6 +133,7 @@ public class TypeScriptFetchClientCodegenTest {
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");
@ -142,6 +143,7 @@ public class TypeScriptFetchClientCodegenTest {
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");
@ -153,7 +155,7 @@ public class TypeScriptFetchClientCodegenTest {
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