swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.05k stars 6.03k forks source link

swift codegen does not support query parameters on POST #1564

Open tigaris opened 9 years ago

tigaris commented 9 years ago

POST methods with query parameter types map to Alamofire.ParameterEncoding.URL which means they are sent in the body of the request as application/x-www-form-urlencoded.

I need to support POST methods with query parameter types that map to Alamofire.ParameterEncoding.URLEncodedInURL. The generated code does not make it easy to support this due to its use of a boolean flag isBody, rather than an enumeration.

The following line in AlamofireImplementations.swift within the execute method is the issue: let encoding = isBody ? Alamofire.ParameterEncoding.JSON : Alamofire.ParameterEncoding.URL

I believe the solution would be to refactor the isBody variable away in favor of an explicit ParameterEncoding type enum. This would make it easy to override the encoding behavior at the individual method level.

wangzilong commented 9 years ago

@tigaris I am a newer can you please give your email to me I want to ask how to use the swift code that be generated by codegen. Thank you

conet commented 8 years ago

+1 I encountered the same problem.

wing328 commented 8 years ago

A good starting point for the fix is https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/swift/AlamofireImplementations.mustache#L31.

If anyone from the community has cycle to contribute the fix, please reply to let us know.

AMiketta commented 8 years ago

I think the starting point for the fix is: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/swift/api.mustache

the {#allParams} is unused if there is an body parameter in this case they should be added to the URL or im am wrong ?

wing328 commented 8 years ago

@AMiketta do you mind submitting a PR so that we can more easily review the fix?

{{#allParams}} stores all the parameters (query, form, body, etc) so using it to obtain the query parameters is a good starting point.

cc @jaz-ah @Edubits

kamil-mrzyglod commented 7 years ago

Is there any work on this currently?