Skip to content

Swift code generator produces code with compile warnings #4098

Open
@davidsantiago

Description

@davidsantiago
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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions