Skip to content

Fix #2120, #2157 - Update Swift API method generation for ease of use #2244

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
Feb 27, 2016

Conversation

hideya
Copy link
Contributor

@hideya hideya commented Feb 25, 2016

Fix #2120, #2157 -- Note this is a Breaking Change.

The following illustrates the differences in the usage of generated SDK:

Before:

        PetstoreClientAPI.PetAPI.getPetById(petId: 1000).execute { response, error -> Void in
                let pet = response?.body

After:

        PetAPI.getPetById(petId: 1000) { pet, error -> Void in

PromiseKit ready version of simplified methods are also generated:

Before:

        PetstoreClientAPI.PetAPI.getPetById(petId: 1000).execute().then { response -> Void in
                let pet = response.body

After:

        PetAPI.getPetById(petId: 1000).then { pet -> Void in

The {{projectName}}API namespace for API classes (PetstoreClientAPI above) now became optional and can be turned on via a CLI option: -D swiftUseApiNamespace=true

In order to allow developers to access the response object when needed, the old methods still exist with WithRequestBuilder added to the end of the method name:

Before:

public class func getPetById(petId petId: Int) -> RequestBuilder<Pet> {

After:

public class func getPetByIdWithRequestBuilder(petId petId: Int) -> RequestBuilder<Pet> {

I initially thought to provide an improved abstraction over these WithRequestBuilder methods (to make them look closer to C#'s WithHttpInfo methods), but it will involve more lines to add (esp. to provide PromiseKit ready version). I thought it better be done in a separate PR.

@hideya hideya changed the title [Swift] Update Swift API method generation for ease of use Fix #2120 - Update Swift API method generation for ease of use Feb 26, 2016
@wing328
Copy link
Contributor

wing328 commented Feb 26, 2016

@hideya thanks for the PR. The description is very clear and the changes look good to me.

cc @jaz-ah @Edubits to see if they've any feedback.

@hideya hideya changed the title Fix #2120 - Update Swift API method generation for ease of use Fix #2120, #2157 - Update Swift API method generation for ease of use Feb 27, 2016
@hideya
Copy link
Contributor Author

hideya commented Feb 27, 2016

@wing328 I've updated this PR and included fix for #2157 (I've also updated the description above accordingly). Would you please review the changes once again?

@wing328
Copy link
Contributor

wing328 commented Feb 27, 2016

@hideya looks good to me and that's how I would have done it.

wing328 added a commit that referenced this pull request Feb 27, 2016
Fix #2120, #2157 - Update Swift API method generation for ease of use
@wing328 wing328 merged commit 72843ad into swagger-api:master Feb 27, 2016
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.

[Swift] simplifications for the API method usage?
2 participants