swagger-api/swagger-codegen

Swift code generator produces code with compile warnings

Open

#4,098 建立於 2016年10月28日

在 GitHub 查看
 (8 留言) (1 反應) (0 負責人)HTML (5,474 fork)batch import
Client: SwiftEnhancement: Generalhelp wanted

倉庫指標

Star
 (12,701 star)
PR 合併指標
 (30 天內沒有已合併 PR)

描述

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.

貢獻者指南