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] body parameter cannot be an integer #7018

Open
papageo opened this issue Nov 21, 2017 · 0 comments
Open

[Swift 3] body parameter cannot be an integer #7018

papageo opened this issue Nov 21, 2017 · 0 comments

Comments

@papageo
Copy link

papageo commented Nov 21, 2017

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

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

#5639
#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.

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

No branches or pull requests

1 participant