-
Notifications
You must be signed in to change notification settings - Fork 6k
SwiftCodegen : change typeMapping for 'long' (Int64 instead of Int). #2406
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
SwiftCodegen : change typeMapping for 'long' (Int64 instead of Int). #2406
Conversation
@kenjitayama thanks for the PR. Please update the languageSpecificPrimitives at https://github.com/kenjitayama/swagger-codegen/blob/fixSwiftCodegenTypeMapping/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SwiftCodegen.java#L76 to include Int64
adf63de to
929ea5e
Compare
@wing328 Didn't notice that part... Added now.
I think this (unfortunately) won't be enough. First as I commented on the issue, I think 32 version is also needed. But also, the code generated now is not functional. Indeed while Int can be automatically put in a AnyObject this is not the case of Int64 (see: http://stackoverflow.com/questions/28920232/why-do-integers-not-conform-to-the-anyobject-protocol for why, basically there is some auto-casting Swift is doing to NSNumber for Int but not bit-exact versions). So in the encodeToJSON method this case must be taken into account. I was actually working on a PR myself and faced that when testing the generated code :(
@wing328 Thanks for pointing out.
I was using my custom template, and Int64 was fine for that, and didn't notice that.
Looks like there is more work to do for a complete fix...
Sorry, intended to @ mention @cjolif in my previous comment.
I'm not sure I can come up with a complete fix, so maybe this PR can be closed for now.
I'll try to find time to propose a PR that does take that into account. But no promise on when.
Looks like I was not as far as I thought. At least a tentative here: #2417
@cjolif Awesome! Everyone will have a safer Swift client :)
I see why you needed to use NSNumber, mentioned in your previous comment.
It seems to me that this is why you said tentative, but looks best for now.
A fix without this kind of workaround would need a bigger fix, with a different approach.
It seems to me that this is why you said tentative, but looks best for now.
Yes I had the feeling there were possible cleaner solutions so that's why I said "tentative" ;). But as you said yourself:
A fix without this kind of workaround would need a bigger fix, with a different approach.
I tried a different path, but then indeed I ended up quickly changing a lot of things... so I sticked to the approach above to keep the changes are minimal as possible.
thanks!
longshould be mapped to Int64 instead of Int, becauselongwill have a range of signed 64 bits.Following the recommendation of the Swift Doc, fixing only the mapping for
longis necessary and sufficient.