-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-json-schema.cjs
51 lines (44 loc) · 1.15 KB
/
generate-json-schema.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const tsj = require("ts-json-schema-generator");
const fs = require("fs");
// json file
const files = [
// backlog.json
{
filename: "backlog.json",
path: "src/app/api/backlog/route.ts",
type: "RawPayload"
},
// games.json
{
filename: "games.json",
path: "src/app/api/games/route.ts",
type: "RawPayload"
},
// series.json
{
filename: "series.json",
path: "src/app/api/series/route.ts",
type: "RawPayload"
},
// tests.json
{
filename: "tests.json",
path: "src/app/api/tests/route.ts",
type: "RawPayload"
},
]
// Iterate and generate file
for (let file of files) {
const { filename, ...rest } = file;
/** @type {import('ts-json-schema-generator/dist/src/Config').Config} */
let config = {
...rest,
tsconfig: "tsconfig.json"
};
let outputPath = `.vscode/schemas/${filename}`;
let schema = tsj.createGenerator(config).createSchema(config.type);
let schemaString = JSON.stringify(schema, null, 2);
fs.writeFile(outputPath, schemaString, (err) => {
if (err) throw err;
});
}