swagger-api / swagger-api/swagger-codegen
[Swift 3] body parameter cannot be an integer
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The generation of the Swift-3 client produces wrong code, when it comes to generating a call that has a parameter which is of integer (or more generally raw-type).
Swagger-codegen version
reproduced with both
- https://editor.swagger.io/
- latest editor from github
Swagger declaration file content or url
/users/cards:
delete:
description: Delete a card from a user
produces:
- application/json
parameters:
- in: body
name: cardSlot
description: the card that will be deleted
required: true
schema:
type: integer
format: int32
responses:
'200':
description: Success
Command line used for generation
Steps to reproduce
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/5639
https://github.com/swagger-api/swagger-codegen/issues/5480
Suggest a fix/enhancement
Generated code looks like this:
DefaultAPI.swift:
open class func usersCardsDeleteWithRequestBuilder(cardSlot: Int32) -> RequestBuilder<Void> {
let path = "/users/cards"
let URLString = SwaggerClientAPI.basePath + path
let parameters = cardSlot.encodeToJSON() as? [String:AnyObject] //-> this will fail and result in nil because of:
Extensions.swift:
extension Int32: JSONEncodable {
func encodeToJSON() -> Any { return NSNumber(value: self as Int32) }
}
why should the parameter be always a dictionary?
As a workaround, I will change my yaml, to contain an object.. but I think the above case should be supported as well.
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
Use the supplied /users/cards Swagger YAML and inspect the generated DefaultAPI.swift and Extensions.swift files, focusing on the integer body parameter and its JSON encoding. Reproduce Swift 3 client generation with the referenced Swagger Editor versions, then verify that the generated call supports a raw integer body without the reported dictionary cast failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, swift
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100