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',
'acronym-style': 'camel',
},
});
return header + lines.join('\n') + footer;
}
export async function genTSDeclarations(
events: TrackedEvent[],
client = Client.js
): Promise {
const { lines } = await quicktype({
lang: new AJSTSDeclarationsTargetLanguage(client),
inputData: processEventsForQuickType(events),
rendererOptions: { 'nice-property-names': 'true' }
})
return prettier.format(lines.join('\n'), { parser: 'typescript' })
}
inputData,
leadingComments: ["Generated by https://quicktype.io"].concat(additionalLeadingComments),
rendererOptions,
indentation,
inferMaps: configuration.inferMaps,
inferEnums: configuration.inferEnums,
inferDateTimes: configuration.inferDateTimes,
inferIntegerStrings: configuration.inferIntegerStrings
};
for (const flag of inferenceFlagNames) {
if (typeof configuration[flag] === "boolean") {
options[flag] = configuration[flag];
}
}
return await quicktype(options);
}
$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)
)
})
const lang = new AJSTargetLanguage()
const { lines } = await quicktype({
lang,
inputData,
rendererOptions: { 'nice-property-names': 'true' }
})
return lines.join('\n')
}