Files
vscode-codeql/extensions/ql-vscode/scripts/generate-schemas.ts
Koen Vlaswinkel db55e9cd42 Generate schema for extension pack metadata
After the upgrade to the correct types for js-yaml, the return type
of `load` is correctly typed as `unknown`. This means that we can't
use the return value directly, but need to validate it first.

This adds such validation by generating a JSON schema for a newly
created typed. The JSON schema generation is very similar to how we do
it in https://github.com/github/codeql-variant-analysis-action.
2023-09-25 15:25:37 +02:00

46 lines
1.0 KiB
TypeScript

import { createGenerator } from "ts-json-schema-generator";
import { join, resolve } from "path";
import { outputJSON } from "fs-extra";
const extensionDirectory = resolve(__dirname, "..");
const schemas = [
{
path: join(
extensionDirectory,
"src",
"model-editor",
"extension-pack-metadata.ts",
),
type: "ExtensionPackMetadata",
schemaPath: join(
extensionDirectory,
"src",
"model-editor",
"extension-pack-metadata.schema.json",
),
},
];
async function generateSchemas() {
for (const schemaDefinition of schemas) {
const schema = createGenerator({
path: schemaDefinition.path,
tsconfig: resolve(extensionDirectory, "tsconfig.json"),
type: schemaDefinition.type,
skipTypeCheck: true,
topRef: true,
additionalProperties: true,
}).createSchema(schemaDefinition.type);
await outputJSON(schemaDefinition.schemaPath, schema, {
spaces: 2,
});
}
}
generateSchemas().catch((e: unknown) => {
console.error(e);
process.exit(2);
});