Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
['json-schema-draft-07', 'settings', 'site'].map(async file => {
let schema = await readFile(path.join(schemaDir, `${file}.schema.json`), 'utf8')
// HACK: Rewrite absolute $refs to be relative. They need to be absolute for Monaco to resolve them
// when the schema is in a oneOf (to be merged with extension schemas).
schema = schema.replace(
/https:\/\/sourcegraph\.com\/v1\/settings\.schema\.json#\/definitions\//g,
'#/definitions/'
)
const types = await compileJSONSchema(JSON.parse(schema), 'settings.schema', {
cwd: schemaDir,
$refOptions: {
resolve: /** @type {import('json-schema-ref-parser').Options['resolve']} */ ({
draftV7resolver,
// there should be no reason to make network calls during this process,
// and if there are we've broken env for offline devs/increased dev startup time
http: false,
}),
},
})
await writeFile(path.join(outputDir, `${file}.schema.d.ts`), types)
})
)
const processTSResult = async (resource, schema) => {
const tsCode = await converter.compile(schema, resource.name.capitalize());
const output = tsLintDisable +
tsCode.replace(regexpExport, `\nexport interface I${resource.name.capitalize()} {\n`);
await fs.writeFile(path.join(outputPath, 'resources', `${resource.name}.ts` ), output);
console.log(`wrote interface ${resource.name}.ts`);
for (let str of ['import', 'export']) {
resourceInterface += `${str} {I${resource.name.capitalize()}} from './resources/${resource.name}';\n`;
}
}
const transformer = useCallback(async ({ value }) => {
return compile(JSON.parse(value), "MySchema", {
bannerComment: ""
});
}, []);
Object.entries(schemas).map(([name, schema]) => {
if (!name.match(/Schema$/)) {
return '';
}
return compile(schema, schema.title || firstUp(name), opts);
})
);
getTransformedValue = code => compile(eval("(" + code + ")"));
type: convertJSONSchemaType(param.attributes.type)
}
});
const properties: { [index: string]: any } = {};
propertyMap.forEach(prop => {
properties[prop.name] = {
type: prop.type,
description: prop.description
}
});
const required = parameters.filter(param => {
return param.attributes.optional !== "yes"
}).map(param => {
return camelCase(param.attributes.name);
});
return compile({
"title": name,
"type": "object",
"properties": properties,
"additionalProperties": false,
"required": required
}, name)
};
.then(data => compileToTS(parseFile(srcPath, data)))
.then(ts => fs.outputFile(dest, ts));