glideapps / quicktype-xcode

Xcode extension to paste JSON as Swift, Objective-C, and more
https://quicktype.io
Apache License 2.0
1.68k stars 53 forks source link

How do I customize the generation rules? #10

Closed rainedAllNight closed 6 years ago

rainedAllNight commented 6 years ago

How do I customize the generation rules?

dvdsgl commented 6 years ago

You can't within Xcode at the moment, but you can download our CLI or use https://app.quicktype.io

How would you like to customize them?

rainedAllNight commented 6 years ago

I am using the framework named ObjectMapper, and I want to generate code that works for it.

dvdsgl commented 6 years ago

Ah, very good.

We have some prelimary work to let you customize the output using handlebars but it's very prelimary. You can find an option for this in our CLI.

Another option is to actually change https://GitHub.com/quicktype/quicktype to add an option to do what you want. This is your best route for now. Would you mind filing an issue on that repo with some sample code for what you'd like the output to look like?

rainedAllNight commented 6 years ago

Ok,Here's a simple example.

struct VehicleBrandModel {
    var brandName: String = ""
    var brandPy: String = ""
    var brandImage: URL?
}

extension VehicleBrandModel: Mappable {
    init?(map: Map) {

    }

    mutating func mapping(map: Map) {
        brandName  <- map["brand_name"]
        brandPy    <- map["brand_py"]
        brandImage <- (map["brand_img"], URLTransform())
    }
}
dvdsgl commented 6 years ago

Why do you want to use ObjectMapper? Does it do anything that quicktype doesn't do?

rainedAllNight commented 6 years ago

Do you mean Codeable?

dvdsgl commented 6 years ago

Yes. 😄

rainedAllNight commented 6 years ago

I found that it had some defects in a particular structure and type. so I keep using ObjectMapper now

dvdsgl commented 6 years ago

Would you mind sharing what those defects are? We'd like to add them to our tests, or help generate a workaround without requiring you to abandon Codables.

rainedAllNight commented 6 years ago

And In any case, is it always a more friendly way to support a custom🙂

dvdsgl commented 6 years ago

Alright, we have an upstream issue for this: https://github.com/quicktype/quicktype/issues/223

rainedAllNight commented 6 years ago

ok, thanks