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

Swift code generator produces code with compile warnings #4098

Open
davidsantiago opened this issue Oct 28, 2016 · 8 comments
Open

Swift code generator produces code with compile warnings #4098

davidsantiago opened this issue Oct 28, 2016 · 8 comments

Comments

@davidsantiago
Copy link

Description

The code generated by Swagger-codegen for Swift will produce a file, AlamofireImplementations.swift, which will have a number of compile warnings, all of them the same:

Treating a forced downcast to 'T' as optional will never produce 'nil'

There are a few different places that cause this, but here's an example:

                    completion(response: Response(response: response.response!, body: () as! T), error: nil)

where the warning is on "as!". Seems like an optional cast (as?) would fix these.

Swagger-codegen version

Using version 2.2.2-SNAPSHOT on master.

Swagger declaration file content or url

I don't have a swagger file to post here, because I can see already that this is invariant to the swagger declaration file. The file in question is mostly pre-defined as is in the template: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/swift/AlamofireImplementations.mustache

The warnings come on lines 172, 187, and 197.

Command line used for generation

This is run from gradle with a custom task I wrote in groovy to call the DefaultGenerator. Again, I don't believe this makes any difference.

Steps to reproduce

Generate a client library for swift and then try to compile that swift.

Related issues

My searched turned up no related issues.

Suggest a Fix

I think optional casts in the template file in question would fix it.

@jaz-ah
Copy link
Contributor

jaz-ah commented Oct 28, 2016

David I don't see these on the latest swift3 implementation - are you using that one or the older swift2 version?

@davidsantiago
Copy link
Author

Using the current swift2 implementation; we can't quite upgrade to swift3 yet.

@jaz-ah
Copy link
Contributor

jaz-ah commented Oct 28, 2016

if you'd like to submit a PR to that, it sounds like a reasonable answer...

@wing328
Copy link
Contributor

wing328 commented Nov 23, 2016

@davebaird let us know if you need help with the PR.

@wing328 wing328 modified the milestones: v2.2.2, Future Feb 15, 2017
@jaz-ah
Copy link
Contributor

jaz-ah commented Sep 8, 2017

@wing328 I'd like to obsolete any < Swift3 issues at this point so we can focus on Swift3/4

@wing328
Copy link
Contributor

wing328 commented Sep 8, 2017

@jaz-ah totally agree it has been almost a year when Swift3 was released: https://swift.org/blog/swift-3-0-released/ and we should definitely concentrate our efforts on Swift 3.x, 4.x

I'll update the help text for swift generator and add a FAQ on that over the weekend.

cc @jgavris @RobBlairInq @ehyche

@jgavris
Copy link
Contributor

jgavris commented Sep 8, 2017

Sounds good

@wing328
Copy link
Contributor

wing328 commented Sep 9, 2017

UPDATE:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants