Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric enums with underscore at beginning get invalid code generated #2640

Closed
ddanielczyk opened this issue Nov 4, 2022 · 2 comments · Fixed by #2745
Closed

Numeric enums with underscore at beginning get invalid code generated #2640

ddanielczyk opened this issue Nov 4, 2022 · 2 comments · Fixed by #2745
Assignees
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation

Comments

@ddanielczyk
Copy link

ddanielczyk commented Nov 4, 2022

Bug report

We recently started migration to new apollo-ios-cli code generation tool and something that was working before, with old code generator, is no longer working.

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 1.0.3
  • Xcode version: 14.1
  • Swift version: 5.7
  • Package manager: Cocoapods

Steps to reproduce

Following enum in schema:

enum NumberOfStoriesEnum {
  _1
  _15
  _2
  _25
  _3
}

Generated code:

public enum NumberOfStoriesEnum: String, EnumType {
  case 1 = "_1"
  case 15 = "_15"
  case 2 = "_2"
  case 25 = "_25"
  case 3 = "_3"
}

As you can see, the case is just a number - which is not valid Swift code. In old code generator, the generated cases still had the underscore as a first character.

Note: If I change conversionStrategies.enumCases to .none - then it works, but it should work correctly with .camelCase as well, since it's mostly preferred strategy.

@ddanielczyk ddanielczyk changed the title Numeric enums with underscore at beginning get invalid code generated. Numeric enums with underscore at beginning get invalid code generated Nov 4, 2022
@calvincestari
Copy link
Member

Thanks for the bug report @ddanielczyk. I'll take a look into this next week.

Note: If I change conversionStrategies.enumCases to .none - then it works, but it should work correctly with .camelCase as well, since it's mostly preferred strategy.

This is a good tip, thanks for the debugging!

@calvincestari calvincestari added bug Generally incorrect behavior codegen Issues related to or arising from code generation labels Nov 5, 2022
@calvincestari calvincestari added this to the Release 1.0.4 milestone Nov 5, 2022
@calvincestari calvincestari self-assigned this Dec 22, 2022
@calvincestari
Copy link
Member

@ddanielczyk - this is fixed and available on the main branch. It will be included in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants