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 3]How to send non dictionary body #5639

Open
bharathreddy-97 opened this issue May 15, 2017 · 1 comment
Open

[Swift 3]How to send non dictionary body #5639

bharathreddy-97 opened this issue May 15, 2017 · 1 comment

Comments

@bharathreddy-97
Copy link

bharathreddy-97 commented May 15, 2017

I am facing a issue while POST and PUT requests. By default Swagger expects a body as dictionary type. I have requests where i have to send json array, String etc. For example this is one sample method which got created while generating

open class func FunctionName(lbid: Int64, lasid: Int64, luid: Int64, lcasid: Int64? = nil, lupid: Int64? = nil, ptype: String? = nil, cform: Bool? = nil, csform: Bool? = nil, body: [SomeModel]? = nil) -> RequestBuilder<SomeResponseObject> {
        let path = "<some path>"
        let URLString = SwaggerClientAPI.basePath + path
        let parameters = body?.encodeToJSON() as? [String:AnyObject] -----> This line has a problem
 
        let convertedParameters = APIHelper.convertBoolToString(parameters)
 
        let requestBuilder: RequestBuilder<SomeResponseObject>.Type = SwaggerClientAPI.requestBuilderFactory.getBuilder()

        return requestBuilder.init(method: "POST", URLString: URLString, parameters: convertedParameters, isBody: false)
    }

When encodeToJson() method is called it is expecting result to be of dictionary type but I had to pass array here as seen in method signature. When i send array, String parameters is becoming nil. How can i send array without disturbing Swagger code(because new methods will be added and I don't want to change everytime I generate Swagger code). Can I somehow pass my request object directly which will avoid this situation?

@wing328
Copy link
Contributor

wing328 commented Jun 5, 2017

@bharathreddy-97 How do you define the endpoint? Are you using BodyParameter (array of models)?

If you can share the spec, the community can use it to more easily reproduce the issue.

You may want to checkout the 2.3.0 branch as well, which contains enhancements (breaking changes) to Swift3 generator.

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

2 participants