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
16.85k stars 6.02k forks source link

[Swift] Add ObjectMapper to Swift #2194

Open wing328 opened 8 years ago

wing328 commented 8 years ago

We want to leverage ObjectMapper for easier conversion between models and JSON.

If anyone from the community wants to work on this task, please reply to let us know.

Edubits commented 8 years ago

Would be awesome! Note there is AlamofireObjectMapper as well, which makes using ObjectMapper in combination with Alamofire even easier.

wing328 commented 8 years ago

For those who are interested in adding the mapping for ObjectMapper, e.g.

    // Mappable
    func mapping(map: Map) {
        username    <- map["username"]
        age         <- map["age"]
        weight      <- map["weight"]
        array       <- map["arr"]
        dictionary  <- map["dict"]
        bestFriend  <- map["best_friend"]
        friends     <- map["friends"]
        birthday    <- (map["birthday"], DateTransform())
    }

Here is the logic you can borrow from PHP model template (which needs something very similar for mapping attribute names):

    static $attributeMap = array(
        {{#vars}}'{{name}}' => '{{baseName}}'{{#hasMore}},
        {{/hasMore}}{{/vars}}
    );

Ref: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/php/model.mustache#L64-L67

romk1n commented 8 years ago

Would be great to move to this model instead of current one.

wing328 commented 8 years ago

@romk1n may I know if you would be interested in making the contribution?

romk1n commented 8 years ago

@wing328 unfortunately don't have time to get it done, sorry :(

cbornet commented 7 years ago

👍