Skip to content

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

Open
@papageo

Description

@papageo
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions