glideapps/quicktype

Enum inference metric too conservative?

Open

#757 aberto em 5 de abr. de 2018

Ver no GitHub
 (3 comments) (0 reactions) (0 assignees)TypeScript (968 forks)batch import
good first issue

Métricas do repositório

Stars
 (10.867 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

Description

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"
    }
}


Guia do colaborador