swagger-api / swagger-api/swagger-codegen
Swift code generator produces code with compile warnings
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect modules/swagger-codegen/src/main/resources/swift/AlamofireImplementations.mustache, especially lines 172, 187, and 197. Generate a Swift client, compile the generated code, and verify that the warnings about forced downcasts being treated as optional no longer appear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100