|  | 
| 1 |  | -const tsj = require("ts-json-schema-generator"); | 
| 2 | 1 | const fs = require("fs"); | 
| 3 | 2 | const path = require("path"); | 
| 4 | 3 | 
 | 
| 5 |  | -const config = { | 
| 6 |  | -    tsconfig: path.join(__dirname, "../tsconfig.json"), | 
| 7 |  | -    type: "*", | 
| 8 |  | -    extraTags: ["errorMessage"] | 
| 9 |  | -}; | 
|  | 4 | +import("ts-json-schema-generator").then((tsj) => { | 
|  | 5 | +    const config = { | 
|  | 6 | +        tsconfig: path.join(__dirname, "../tsconfig.json"), | 
|  | 7 | +        type: "*", | 
|  | 8 | +        extraTags: ["errorMessage"] | 
|  | 9 | +    }; | 
| 10 | 10 | 
 | 
| 11 |  | -const schemaGenerator = tsj.createGenerator(config); | 
|  | 11 | +    const schemaGenerator = tsj.createGenerator(config); | 
| 12 | 12 | 
 | 
| 13 |  | -const requestTypes = schemaGenerator | 
| 14 |  | -    .getRootNodes() | 
| 15 |  | -    .map((x) => x.symbol.escapedName) | 
| 16 |  | -    .filter((x) => x.endsWith("Request")); | 
|  | 13 | +    const requestTypes = schemaGenerator | 
|  | 14 | +        .getRootNodes() | 
|  | 15 | +        .map((x) => x.symbol.escapedName) | 
|  | 16 | +        .filter((x) => x.endsWith("Request")); | 
| 17 | 17 | 
 | 
| 18 |  | -const schemaDeclarations = requestTypes | 
| 19 |  | -    .map((type) => { | 
| 20 |  | -        try { | 
| 21 |  | -            const schema = schemaGenerator.createSchema(type); | 
| 22 |  | -            return `export const ${type}: any = ${JSON.stringify(schema, undefined, 4)}`; | 
| 23 |  | -        } catch (e) { | 
| 24 |  | -            if (!(e instanceof tsj.NoRootTypeError)) throw e; | 
| 25 |  | -        } | 
| 26 |  | -    }) | 
| 27 |  | -    .filter((s) => s) | 
| 28 |  | -    .join("\n\n"); | 
|  | 18 | +    const schemaDeclarations = requestTypes | 
|  | 19 | +        .map((type) => { | 
|  | 20 | +            try { | 
|  | 21 | +                const schema = schemaGenerator.createSchema(type); | 
|  | 22 | +                return `export const ${type}: any = ${JSON.stringify(schema, undefined, 4)}`; | 
|  | 23 | +            } catch (e) { | 
|  | 24 | +                if (!(e instanceof tsj.NoRootTypeError)) throw e; | 
|  | 25 | +            } | 
|  | 26 | +        }) | 
|  | 27 | +        .filter((s) => s) | 
|  | 28 | +        .join("\n\n"); | 
| 29 | 29 | 
 | 
| 30 |  | -const output_path = path.join(__dirname, "../src/useCases/common/Schemas.ts"); | 
|  | 30 | +    const output_path = path.join(__dirname, "../src/useCases/common/Schemas.ts"); | 
| 31 | 31 | 
 | 
| 32 |  | -fs.writeFile(output_path, schemaDeclarations, (err) => { | 
| 33 |  | -    if (err) throw err; | 
|  | 32 | +    fs.writeFile(output_path, schemaDeclarations, (err) => { | 
|  | 33 | +        if (err) throw err; | 
|  | 34 | +    }); | 
| 34 | 35 | }); | 
0 commit comments