Swift code generator produces code with compile warnings · Issue #4098 · swagger-api/swagger-codegen (original) (raw)

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.

My searched turned up no related issues.

Suggest a Fix

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