swagger-api / swagger-api/swagger-codegen

[Swift4] Update response wrapper when using PromiseKit wrapper

Open
#8,779 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When using the swagger-codegen with the "responseAs": "PromiseKit" option to wrap the API responses, the generated code is not compatible with the PromiseKit framework version set in the Cartfile created by the generator.

Swagger-codegen version

2.3.1

Command line used for generation

swagger-codegen generate -i <swagger.json file> -l swift4 -c <config.json file> -o generatedFiles/

Content of Cartfile created by the generator
github "Alamofire/Alamofire" ~> 4.5.0
github "mxcl/PromiseKit" ~> 4.4
Content of config.json file
{
    "responseAs": "PromiseKit"
}
Generated code sample
open class func someMethod( someParam: String) -> Promise<[String]> {
    let deferred = Promise<[String]>.pending()
    someMethod(someParam: String) { data, error in
        if let error = error {
            deferred.reject(error) <-- Value of tuple type '(promise: Promise<[String]>, resolver: Resolver<[String]>)' has no member 'reject'
        } else {
            deferred.fulfill(data!) <-- Value of tuple type '(promise: Promise<[String]>, resolver: Resolver<[String]>)' has no member 'fulfill'
        }
    }
    return deferred.promise
}
Suggest a fix/enhancement

The generated code should be:

open class func someMethod( someParam: String) -> Promise<[String]> {
    let deferred = Promise<[String]>.pending()
    someMethod(someParam: String) { data, error in
        if let error = error {
            deferred.resolver.reject(error)
        } else {
            deferred.resolver.fulfill(data!)
        }
    }
    return deferred.promise
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Swift4 generation command with responseAs set to PromiseKit and compare the generated wrapper with the Swift code shown in the issue. Trace the Swift4 generator template responsible for the response wrapper, then verify that generated code uses the resolver API required by the PromiseKit version in the generated Cartfile.

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
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.