[Swift5] replace special characters in Swift enum var name #11131
[Swift5] replace special characters in Swift enum var name #11131wing328 merged 5 commits intoOpenAPITools:masterfrom mbruegmann:swift-enum-var-name-special-characters
Conversation
|
Hi @mbruegmann, first of all thanks for creating this PR 👍 Thanks |
|
|
||
| public enum JustSymbol: String, Codable, CaseIterable { | ||
| case greaterThanOrEqualTo = ">=" | ||
| case greaterThanEqual = ">=" |
There was a problem hiding this comment.
@mbruegmann I think those changes are not expected, or are they?
Could you please check what happened?
There was a problem hiding this comment.
@mbruegmann the previous changes are related to the changes you make in the Swift5ClientCodegen.java.
An easy way to test it is by adding the following test case here that should pass.
Assert.assertEquals(swiftCodegen.toEnumVarName(">=", null), "greaterThanOrEqualTo");
There was a problem hiding this comment.
It seems to be an rare edge case. I am doing the replacement character by character now to also replace special characters inside the name. Before only in case of a match of the whole string a replacement was done.
This was the previous code and it would not work for "3=>2" for example. It would only match "=>".
if (getSymbolName(name) != null) { return camelize(WordUtils.capitalizeFully(getSymbolName(name).toUpperCase(Locale.ROOT)), true); }
The problem comes from specialCharReplacements in DefaultCodegen. It's a map with replacements that could be reversed, but the order also is not garanteed.
|
Could you please confirm that the following command doesn't change the sample projects? Thanks |
|
After running the 3 commands there were no changes. |
4brunu
left a comment
There was a problem hiding this comment.
Looks good to me 👍
Thanks for creating this PR.
A fix for this issue: #11107
@jgavris (2017/07) @ehyche (2017/08) @Edubits (2017/09) @jaz-ah (2017/09) @4brunu (2019/11)
PR checklist
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.For Windows users, please run the script in Git BASH.
master(5.3.0),6.0.x