swagger-api / swagger-api/swagger-codegen
[Swift 3]How to send non dictionary body
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the generated Swift method shown in the issue and trace the body through encodeToJSON(), convertBoolToString(), and RequestBuilder initialization. Reproduce the request with an array or string body and determine whether the generated client preserves it; done means non-dictionary bodies are sent without manual edits to newly generated methods.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100