elnabo / json2object

Type safe Haxe/JSON (de)serializer
MIT License
66 stars 17 forks source link

Arrays of string constants don't play nicely with VSCode #60

Closed Gama11 closed 5 years ago

Gama11 commented 5 years ago
import sys.io.File;
import json2object.utils.JsonSchemaWriter;

using StringTools;

class Main {
    static function main() {
        var schema = new JsonSchemaWriter<Config>("\t").schema;
        schema = schema.replace('"description"', '"markdownDescription"');
        File.saveContent("schema.json", schema);
    }
}

typedef Config = {
    /** stuff **/
    var foo:Foo;
}

enum abstract Foo(String) {
    /** a **/
    var A;
    /** b **/
    var B;
}

Generates something like this:

"Foo": {
    "anyOf": [
        {
            "const": "A",
            "markdownDescription": "a"
        },
        {
            "const": "B",
            "markdownDescription": "b"
        }
    ]
}

IIRC, this was a workaround for descriptions of enum values and enum only supporting that via VSCode's non-standard enumDescriptions / markdownEnumDescriptions. Originally we thought the approaches are equivalent, but it looks like that's not the case.


Hover with the generated schema:


With the schema edited to use the VSCode schema style:

"Foo": {
    "enum": [
        "A",
        "B"
    ],
    "markdownEnumDescriptions": [
        "a",
        "b"
    ]
}

elnabo commented 5 years ago

This should work starting with commit 05078e16699ff4020bd6aec72e297a5a2f439847 and version 3.6.3.

Like #59 VSCodeSchemaWriter is required.