-
-
Notifications
You must be signed in to change notification settings - Fork 67
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
Retain leading underscores in enum case names #123
Retain leading underscores in enum case names #123
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Set swift-format to v508.0.0
…r-is-an-integer Prepend an underscore to the identifier if it is an integer
hey 👋 , Thank you for making this PR. Before I merge it in, could you help me understand what kind of enum declaration you are using. I thought the GraphQLSpec forbids the use of digits-only enum value names (http://spec.graphql.org/October2021/#sec-Enums). |
Hey @maticzav, Thanks for considering my PR and for pointing me to the spec. 🙂 It's odd, our schema's enum looks like this: enum CDLType {
UNKNOWN
A
AZ
B
C
D
E
_1
_2
_3
_4
_5
UNRECOGNIZED
} so I'm unsure why the generated code doesn't have the underscore. Any ideas? |
Hey @maticzav, I've updated my PR to allow for all prepending underscores according to the GraphQL spec. The issue was here: extension String {
public var pascalCase: String {
// ...
// line 22:
// Skip all special characters.
guard char.isLetter else {
capitalize = true
isAbbreviation = false
continue
}
// ...
}
} which would strip all special chars. |
Excuse my absence. I am really thankful that you took time and created this PR. Now that I spent some time pondering and investigating the issue, I think we should do more than just handle this case. Ideally, we would actually rename I think this is the way to go because from my new understanding of the spec, any object field name might encounter the same problem and only fixing the issue in enums is going to lead to code duplication. It's also quite likely that #113 is related to this issue. |
Sounds good! I see that you self assigned to this issue. Feel free to close this PR or continue working on it to consider the cases you mentioned. Anyway, this was a good exercise since I'm fairly new to Swift. |
Hey there 👋 I'm having a similar (but not identical) issue, some of my enum cases have a trailing underscore which is being omitted causing duplicate enum case space = "space"
case space = "space_" Would I be correct in assuming this is related? |
EDIT
|
Running the Codegen on our GraphQL endpoint failed with the error:
I did some investigation and found out it was because the generated enums contained integers as identifiers yielding the error:
The generated code looks like this:
This PR checks if the identifier is an integer and will prepend an underscore if it is, resulting in:
Now, I don't know if my solution is any good - I am very new to Swift. Any feedback is appreciated.