Skip to content

[swift4] Use RequestBuilder directly for RxSwift and PromiseKit #1718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 26, 2018

Conversation

d-date
Copy link

@d-date d-date commented Dec 20, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.4.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

When we specify RxSwift or PromiseKit to ResponseAs in additional_properties, the generator will generate 3 methods, requestBuilder, default implementation and wrapped method.

We need only requestBuild and wrapped method so that reduce generated codes.
This is not breaking change for users.

Before:

open class func addPet(pet: Pet) -> Observable<Void> {
        return Observable.create { observer -> Disposable in
            addPet(pet: pet) { data, error in
                if let error = error {
                    observer.on(.error(error))
                } else {
                    observer.on(.next(data!))
                }
                observer.on(.completed)
            }
            return Disposables.create()
        }
    }

After:

open class func addPet(pet: Pet) -> Observable<Void> {
        return Observable.create { observer -> Disposable in
            addPetWithRequestBuilder(pet: pet).execute { (response, error) -> Void in
                if let error = error {
                    observer.onError(error)
                } else {
                    observer.onNext(())
                }
                observer.onCompleted()
            }
            return Disposables.create()
        }
    }

@auto-labeler
Copy link

auto-labeler bot commented Dec 20, 2018

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

Please review the labels and make any necessary changes.

@d-date
Copy link
Author

d-date commented Dec 20, 2018

Committes

@wing328 @jgavris (2017/07) @ehyche (2017/08) @Edubits (2017/09) @jaz-ah (2017/09) @d-date (2018/03)

@@ -54,7 +55,7 @@ open class {{classname}} {
{{/returnType}}
}
}

{{/useRxSwift}}{{/usePromiseKit}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@d-date minor suggestion: using the following instead to skip blank lines or trailing spaces in the output:

    {{^usePromiseKit}}
    {{^useRxSwift}}
....
    {{/useRxSwift}}
    {{/usePromiseKit}}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wing328 Thank you! Fix it.

@wing328
Copy link
Member

wing328 commented Dec 26, 2018

The Travis CI issue below has been fixed in master:

Fetching gem metadata from https://rubygems.org/.........
ZenTest-4.11.1 requires rubygems version < 3.0, which is incompatible with the
current version, 3.0.0

@wing328 wing328 added this to the 4.0.0 milestone Dec 26, 2018
@wing328 wing328 merged commit c13e089 into master Dec 26, 2018
@wing328 wing328 deleted the swift-reduce-defaults-code branch December 26, 2018 16:20
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
…APITools#1718)

* remove default implementation

* avoid insert blank lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants