Skip to content

[Swift5] replace special characters in Swift enum var name #11131

Merged
wing328 merged 5 commits intoOpenAPITools:masterfrom
mbruegmann:swift-enum-var-name-special-characters
Dec 17, 2021
Merged

[Swift5] replace special characters in Swift enum var name #11131
wing328 merged 5 commits intoOpenAPITools:masterfrom
mbruegmann:swift-enum-var-name-special-characters

Conversation

@mbruegmann
Copy link
Copy Markdown
Contributor

A fix for this issue: #11107

@jgavris (2017/07) @ehyche (2017/08) @Edubits (2017/09) @jaz-ah (2017/09) @4brunu (2019/11)

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files.
    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.
  • File the PR against the correct branch: master (5.3.0), 6.0.x
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@4brunu
Copy link
Copy Markdown
Contributor

4brunu commented Dec 15, 2021

Hi @mbruegmann, first of all thanks for creating this PR 👍
Could you please run the following commands and commit the output please?

./mvnw clean package 
./bin/generate-samples.sh
./bin/utils/export_docs_generators.sh

Thanks


public enum JustSymbol: String, Codable, CaseIterable {
case greaterThanOrEqualTo = ">="
case greaterThanEqual = ">="
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbruegmann I think those changes are not expected, or are they?
Could you please check what happened?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@4brunu
Copy link
Copy Markdown
Contributor

4brunu commented Dec 15, 2021

Could you please confirm that the following command doesn't change the sample projects?

./mvnw clean package 
./bin/generate-samples.sh
./bin/utils/export_docs_generators.sh

Thanks

@mbruegmann
Copy link
Copy Markdown
Contributor Author

After running the 3 commands there were no changes.

Copy link
Copy Markdown
Contributor

@4brunu 4brunu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍
Thanks for creating this PR.

@wing328 wing328 added this to the 5.3.1 milestone Dec 17, 2021
@wing328 wing328 merged commit 1e3dd1f into OpenAPITools:master Dec 17, 2021
@mbruegmann mbruegmann deleted the swift-enum-var-name-special-characters branch December 17, 2021 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants