-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-schema.mjs
36 lines (30 loc) · 1.05 KB
/
json-schema.mjs
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
import { createGenerator } from "ts-json-schema-generator";
import fs from "fs";
import path from "path";
const mainFile = path.resolve(process.cwd(), "src/config.ts");
const tsConfigFile = path.resolve(process.cwd(), "tsconfig.json");
const configMap = {
transactionsMSSchema: "Configuration",
transactionPCDHSchema: "PCDHConfiguration",
transactionFHIRDosage: "MedicationEntry",
};
for (let [fileName, technicalKey] of Object.entries(configMap)) {
/** @type {import('ts-json-schema-generator/dist/src/Config').Config} */
const config = {
path: mainFile,
tsconfig: tsConfigFile,
type: technicalKey, // Or <type-name> if you want to generate schema for that one type only
};
// Generate schema for Config
let schema = createGenerator(config).createSchema(config.type);
const schemaString = JSON.stringify(schema, null, "\t").replace(
/\n/g,
"\r\n",
);
const output_path = `${process.cwd()}/src/${fileName}.json`;
fs.writeFile(output_path, schemaString, (err) => {
if (err) {
console.error(err.message);
}
});
}