Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function generate(inPath) {
// Best description of how to use the API was found at
// https://blog.quicktype.io/customizing-quicktype/
const inputData = new InputData();
const content = fs.readFileSync(inPath, 'utf-8');
const source = { name: 'Schema', schema: appendDeprecatedDescription(content) };
await inputData.addSource('schema', source, () => {
return new JSONSchemaInput(new FetchingJSONSchemaStore(inPath));
});
const lang = new TypeScriptTargetLanguage();
const { lines } = await quicktype({
lang,
inputData,
alphabetizeProperties: true,
rendererOptions: {
'just-types': 'true',
'explicit-unions': 'true',
const configuration = vscode.workspace.getConfiguration(configurationSection);
const justTypes = forceJustTypes || configuration.justTypes;
const rendererOptions: RendererOptions = {};
if (justTypes) {
// FIXME: The target language should have a property to return these options.
if (lang.name === "csharp") {
rendererOptions["features"] = "just-types";
} else if (lang.name === "kotlin") {
rendererOptions["framework"] = "just-types";
} else {
rendererOptions["just-types"] = "true";
}
}
const inputData = new InputData();
switch (kind) {
case "json":
await inputData.addSource("json", { name: topLevelName, samples: [content] }, () =>
jsonInputForTargetLanguage(lang)
);
break;
case "schema":
await inputData.addSource(
"schema",
{ name: topLevelName, schema: content },
() => new JSONSchemaInput(undefined)
);
break;
case "typescript":
await inputData.addSource(
"schema",
export async function genTS(events: TrackedEvent[]) {
const inputData = new InputData()
events.forEach(({ name, rules }) => {
const schema = {
$schema: 'http://json-schema.org/draft-04/schema#',
title: rules.title,
description: rules.description,
...rules.properties.properties
}
inputData.addSource(
'schema',
{ name, uris: [name], schema: JSON.stringify(schema) },
() => new JSONSchemaInput(undefined)
)
})
export const processEventsForQuickType = (events: TrackedEvent[]) => {
const inputData = new InputData()
events.forEach(({ name, rules }) => {
const schema = {
$schema: rules.$schema || 'http://json-schema.org/draft-07/schema#',
title: rules.title,
description: rules.description,
...get(rules, 'properties.properties', {})
}
inputData.addSource(
'schema',
{ name, uris: [name], schema: JSON.stringify(schema) },
() => new JSONSchemaInput(undefined)
)
})
augmentModule: boolean,
leadingComments: string[] | undefined,
rendererOptions: RendererOptions,
) => {
const src: JSONSchemaSourceData = {
name,
schema: JSON.stringify(schema),
};
class FetchingJSONSchemaStore extends JSONSchemaStore {
async fetch(address: string): Promise {
return (schemaRefs as any)[address];
}
}
const inputData = new InputData();
await inputData.addSource(
'schema',
src,
() => new JSONSchemaInput(new FetchingJSONSchemaStore(), []),
);
const { lines } = await quicktype({
inputData,
lang: type,
indentation: ' ',
leadingComments: (leadingComments || [
'AUTO GENERATED CODE',
'Run app-config with \'generate\' command to regenerate this file',
]),
rendererOptions: {
'just-types': 'true',