swagger-api / swagger-api/swagger-codegen

[Swift] Obsoleted PromiseKit generated

Open
#9,884 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

Swift 5 Codegen generates an obsoleted Code with the "PromiseKit" option enabled in the "responseAs" field inside generate-config.json

Version

I used "swagger-codegen-cli-2.4.10" with "-l swift 5" option.
XCode 11.2

Issue examples

After Pods installation, Xcode returns a few errors in Pod library (inside Pods/PromiseKit/UIKit) like this:

/UIKit.UIViewAnimationOptions:3:18: 'UIViewAnimationOptions' was obsoleted in Swift 4.2

(Works):

public class func promise(animateWithDuration duration: TimeInterval, delay: TimeInterval = 0, options: UIView.AnimationOptions = [], animations: @escaping () -> Void) -> Promise<Bool> {
        return PromiseKit.wrap { animate(withDuration: duration, delay: delay, options: options, animations: animations, completion: $0) }
    }

(Returns error):

public class func promise(animateWithDuration duration: TimeInterval, delay: TimeInterval = 0, options: UIViewAnimationOptions = [], animations: @escaping () -> Void) -> Promise<Bool> {
        return PromiseKit.wrap { animate(withDuration: duration, delay: delay, options: options, animations: animations, completion: $0) }
    }

(Screenshot):

Screenshot at Nov 23 13-21-43
Command line used for generation

java -jar swagger-cli/swagger-codegen-cli-2.4.10.jar generate -l swift5 -o SomeLibrary/ -i swagger.json -c generate-config.json

generate-config.json content:

{
 "projectName": "SomeLibrary",
 "podDescription": "Implements SomeLibrary using PromiseKit",
 "podSummary": "SomeLibrary",
 "podHomepage": "SomeLibraryHomepage.com",
 "podAuthors": "Sergey Shoshin",
 "podVersion": "1.1.0",
 "responseAs": "PromiseKit"
}
Steps to reproduce
  • Add PromiseKit option to responseAs
  • Generate Library
  • Make "Pod install"
  • Open XCode project & build
Related issues/PRs
  • Swift 5 Support: #9386
  • PromiseKit Update: #9229
  • PromiseKit Update: #8481
Possible reason

It generates .podspec file with obsoleted PromiseKit, I think that this is the reason and suggest to update it to the latest PromiseKit 6 (at least for Swift 5).

From:

s.dependency 'PromiseKit/CorePromise', '~> 4.4.0'
s.dependency 'Alamofire', '~> 4.9.0'

To:

s.dependency 'PromiseKit', '~> 6.8'
s.dependency 'Alamofire', '~> 4.9.0'

But then need to change fulfill & reject part a little.

(Issue):

Value of tuple type '(promise: Promise<Response>, resolver: Resolver<Response>)' has no member 'fulfill'
Value of tuple type '(promise: Promise<Response>, resolver: Resolver<Response>)' has no member 'reject'

(Screenshot):

image

To fix it need just add the ".resolver" field.

From:
deferred.reject(error)
To:
deferred.resolver.reject(error)

Like that:

image

By the way, PromisKit has the Guideline for moving: https://mxcl.dev/PromiseKit/news/2018/02/PromiseKit-6.0-Released/

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

Start with the supplied generate-config.json and the Swift 5 output from the provided swagger-codegen command, especially the generated .podspec and PromiseKit calls. Compare the PromiseKit dependency and resolver usage with the reported Swift 5 errors; done means a generated library installs and builds in Xcode without obsolete API or fulfill/reject errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.