3forges / poc-frontmatter-schema

A POC to choose the best JSON/YAML libraries, to define structures for a frontmatter
0 stars 0 forks source link

try quicktype #2

Open Jean-Baptiste-Lasselle opened 11 months ago

Jean-Baptiste-Lasselle commented 11 months ago

I need to try that one

Jean-Baptiste-Lasselle commented 11 months ago

ok, done with six.ts : i could successfully find how to configure the --no-enums option, the equivalent is inferEnums: false :

async function quicktypeJSON(targetLanguage: string, typeName: string, jsonString: any) {
    const jsonInput = jsonInputForTargetLanguage(targetLanguage);

    // We could add multiple samples for the same desired
    // type, or many sources for other types. Here we're
    // just making one type from one piece of sample JSON.
    await jsonInput.addSource({
        name: typeName,
        samples: [jsonString]
    });

    const inputData = new InputData();
    inputData.addInput(jsonInput);

    return await quicktype({
        inputData,
        lang: targetLanguage,
        outputFilename: `src/examples/.quicktype.generated/quicktype.generated.ts`,
        inferEnums: false // that's how to force gnerate Arrayof string instead of an enum
    });
}