glideapps/quicktype

Enum inference metric too conservative?

Open

#757 aperta il 5 apr 2018

Vedi su GitHub
 (3 commenti) (0 reazioni) (0 assegnatari)TypeScript (968 fork)batch import
good first issue

Metriche repository

Star
 (10.867 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

I have the below JSON and using this command:

$ quicktype --alphabetize-properties --density normal --no-initializers --src example.json --lang swift --top-level "Certificate" -o out.swift

I don't not get enums for Switch.type (see output below).

Input

{
    "expires": 1519873431,
    "modules": [
        {
            "name": "FPKit",
            "switches": [
                {
                    "key": "valueA",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "valueB",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "valueC",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "valueD",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "valueE",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "valueF",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "valueG",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "valueH",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "valueI",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "valueJ",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "value2",
                    "type": "int",
                    "type_info": null,
                    "value": "2"
                },
                {
                    "key": "value3",
                    "type": "double",
                    "type_info": null,
                    "value": "3.5"
                },
                {
                    "key": "value3a",
                    "type": "double",
                    "type_info": null,
                    "value": "3.5"
                },
                {
                    "key": "value4",
                    "type": "bool",
                    "type_info": null,
                    "value": "true"
                },
                {
                    "key": "value5",
                    "type": "data",
                    "type_info": null,
                    "value": "vafEXVIgdfg;svjKLIger/wFFFdfvkjadlluulfhj567gnlCWuukgj6dv5vCECWWaM,PiOEFGjdsv=="
                },
                {
                    "key": "value5a",
                    "type": "custom",
                    "type_info": "UIColor",
                    "value": "vafEXVIgdfg;svjKLIger/wFFFdfvkjadlluulfhj567gnlCWuukgj6dv5vCECWWaM,PiOEFGjdsv=="
                },
                {
                    "key": "value5b",
                    "type": "custom",
                    "type_info": "UIColor",
                    "value": "vafEXVIgdfg;svjKLIger/wFFFdfvkjadlluulfhj567gnlCWuukgj6dv5vCECWWaM,PiOEFGjdsv=="
                }
            ]
        },
        {
            "name": "main",
            "switches": [
                {
                    "key": "value",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "value",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "value2",
                    "type": "int",
                    "type_info": null,
                    "value": "2"
                },
                {
                    "key": "value3",
                    "type": "double",
                    "type_info": null,
                    "value": "3.5"
                },
                {
                    "key": "valuea",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "valueb",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                },
                {
                    "key": "value2",
                    "type": "int",
                    "type_info": null,
                    "value": "2"
                },
                {
                    "key": "value3",
                    "type": "double",
                    "type_info": null,
                    "value": "3.5"
                },
                {
                    "key": "value4",
                    "type": "bool",
                    "type_info": null,
                    "value": "true"
                },
                {
                    "key": "value4",
                    "type": "bool",
                    "type_info": null,
                    "value": "true"
                },
                {
                    "key": "value5b",
                    "type": "data",
                    "type_info": null,
                    "value": "vafEXVIgdfg;svjKLIger/wFFFdfvkjadlluulfhj567gnlCWuukgj6dv5vCECWWaM,PiOEFGjdsv=="
                },
                {
                    "key": "value5a",
                    "type": "custom",
                    "type_info": "UIColor",
                    "value": "vafEXVIgdfg;svjKLIger/wFFFdfvkjadlluulfhj567gnlCWuukgj6dv5vCECWWaM,PiOEFGjdsv=="
                },
                {
                    "key": "valuec",
                    "type": "string",
                    "type_info": null,
                    "value": "hello world"
                }
            ]
        }
    ],
    "signature": "vafEXVIgdfg;fEXVIgdfg;svjKLbsfgbfs%$^&*YHkbjvgkccIger/;svjKLIger/wFFFdfvkFdfvkjCWWaM,PiGjdsv==",
    "version": 1
}

Output


// To parse the JSON, add this file to your project and do:
//
//   let certificate = try? JSONDecoder().decode(Certificate.self, from: jsonData)

import Foundation

struct Certificate: Codable {
    let expires: Int
    let modules: [Module]
    let signature: String
    let version: Int

    enum CodingKeys: String, CodingKey {
        case expires = "expires"
        case modules = "modules"
        case signature = "signature"
        case version = "version"
    }
}

struct Module: Codable {
    let name: String
    let switches: [Switch]

    enum CodingKeys: String, CodingKey {
        case name = "name"
        case switches = "switches"
    }
}

struct Switch: Codable {
    let key: String
    let type: String
    let typeInfo: String?
    let value: String

    enum CodingKeys: String, CodingKey {
        case key = "key"
        case type = "type"
        case typeInfo = "type_info"
        case value = "value"
    }
}


Guida contributor