Skip to content
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

[Swift] Operations with both query-based parameters & body-based parameters are not working #2483

Closed
cjolif opened this issue Apr 1, 2016 · 7 comments

Comments

@cjolif
Copy link
Contributor

cjolif commented Apr 1, 2016

If in your operations you have something as follows:

             {
                        "name": "param1",
                        "in": "query",
                        "required": false,
                        "type": "string",
                        "enum": [
                            "true",
                            "false"
                        ]
                    },
                    {
                        "name": "param2",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/MyType"
                        }

The generated swift will contain something of the following form:

 public class func myOperationWithRequestBuilder(param2: MyType, param1: String?) -> RequestBuilder<> {
        var path = ...
        let URLString = SwaggerClientAPI.basePath + path

        let parameters = param2.encodeToJSON() as? [String:AnyObject]

        let requestBuilder: RequestBuilder<>.Type = SwaggerClientAPI.requestBuilderFactory.getBuilder()

        return requestBuilder.init(method: "PUT", URLString: URLString, parameters: parameters, isBody: false)

ignoring the query parameter (param1) and passing isBody false to the init.

The root limitation is that Alamofire either send parameters as query parameters or body but can't do both.

@wing328
Copy link
Contributor

wing328 commented Apr 15, 2016

@cjolif may I know if you or someone has already opened a ticket with https://github.com/Alamofire/Alamofire/ team? (I did a search in that repo but couldn't find one)

@cjolif
Copy link
Contributor Author

cjolif commented Apr 15, 2016

no, but actually in the interim someone told me that using lower-level Alamofire APIs (i.e. not the high level API used in swagger-codegen) it should be feasible. I don't have the details however.

@wing328 wing328 modified the milestones: v2.3.0, v2.2.0 Jul 7, 2016
@wing328 wing328 modified the milestones: v2.2.1, v2.2.2 Aug 8, 2016
@HSchultjan
Copy link

Im willing to work on this issue.
I already have a mustache template that will properly encode query parameters for POST requests, but since Alamofire doesn't really support this its a quite hacky solution which i would like to avoid.
Im trying to find a clean solution. So if you have any ideas where to start, please comment.

@fehguy
Copy link
Contributor

fehguy commented Nov 1, 2016

Typically we've been building the URL manually in other languages. I believe this was the same approach in the Objective-C library here, which also uses AFNetworking. So I don't see a way around doing that.

@HSchultjan
Copy link

Okay. Do you have any coding conventions/guidelines?

@wing328
Copy link
Contributor

wing328 commented Nov 1, 2016

@HSchultjan please have a look at https://github.com/swagger-api/swagger-codegen/blob/master/CONTRIBUTING.md

@wing328
Copy link
Contributor

wing328 commented Jan 7, 2017

@cjolif @HSchultjan the fix by @tomekc has been merged into master. Please pull the latest to give it a try.

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

No branches or pull requests

4 participants