codegen: add == -> 'Double_Equal' to specialCharReplacements (#19125)

* codegen: add == -> 'Double_Equal' to specialCharReplacements

The double equal '==' is a common operator in a few contexts (specific use case for me is haystack operators). Currently if this value appears in an enum its name gets sanitized to empty and generates invalid syntax. Very similar to https://github.com/OpenAPITools/openapi-generator/pull/12801

* makes java underscore test more flexible

Given the name and purpose of this test, maybe it is better to test that the generated value is not an underscore rather than to test that it _is_ a specific (and possibly arbitrary) substitute value.
This commit is contained in:
Luke Tudge 2024-07-10 11:02:48 +02:00 committed by GitHub
parent ba056dbf10
commit 005d5b0232
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View File

@ -1833,6 +1833,7 @@ public class DefaultCodegen implements CodegenConfig {
specialCharReplacements.put("!=", "Not_Equal");
specialCharReplacements.put("<>", "Not_Equal");
specialCharReplacements.put("~=", "Tilde_Equal");
specialCharReplacements.put("==", "Double_Equal");
}
/**

View File

@ -80,8 +80,8 @@ public class AbstractJavaCodegenTest {
*/
@Test
public void toEnumVarNameShouldNotResultInSingleUnderscore() {
Assert.assertEquals(codegen.toEnumVarName(" ", "String"), "SPACE");
Assert.assertEquals(codegen.toEnumVarName("==", "String"), "u");
Assert.assertNotEquals(codegen.toEnumVarName(" ", "String"), "_");
Assert.assertNotEquals(codegen.toEnumVarName("==", "String"), "_");
}
@Test