How to use the typescript-json-schema.getProgramFromFiles function in typescript-json-schema

To help you get started, we’ve selected a few typescript-json-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hpcc-systems / Visualization / packages / ddl-shim / util / createSchema.ts View on Github external
function genSchema(src: string, dest: string, type: string) {
    const ddl = TJS.getProgramFromFiles([resolve(`src/${src}.ts`)], {
        skipLibCheck: true
    });
    const ddlSchema = TJS.generateSchema(ddl, type, settings);

    fs.writeFile(`src/${dest}.json`, JSON.stringify(ddlSchema), function (err) {
        if (err) {
            return console.error(err);
        }
    });

    const tpl = `/* tslint:disable */\n` +
        `export const ${dest} =  \n` +
        JSON.stringify(ddlSchema, null, "    ") +
        `;\n`;

    fs.writeFile(`src/${dest}.ts`, tpl, function (err) {
github wavesplatform / waves-transactions / build / schemas.ts View on Github external
excludePrivate: true,
    noExtraProps: false,
  }

  // optionally pass ts compiler options
  const compilerOptions: TJS.CompilerOptions = {
    strictNullChecks: true,
    resolveJsonModule: true,
    allowSyntheticDefaultImports: true,
    downlevelIteration: true,
    lib: [
      'esnext'
    ]
  }

  const program = TJS.getProgramFromFiles([resolve('src/transactions.ts')], compilerOptions)


  TYPES.forEach(type => {
    const id = `https://raw.githubusercontent.com/wavesplatform/waves-transactions/master/src/schemas/${type}.json`
    let schema = TJS.generateSchema(program, type, { ...settings, id })
    //Define generic LONG as string | number in JSON schema. Otherwise ot would be object. Should probably pass param that defines LONG schema;
    schema!.definitions = {...schema!.definitions,  LONG:{type:['string', 'number']}};
    const filePath = `src/schemas/${type}.json`
    const fileContent = JSON.stringify(schema, null, 2)
    writeFile(filePath, fileContent, (err) => {
      if (err) throw err
      console.log(`${type} schema has been written`)
    })
  })

  const manifest = `${TYPES.map(type => `import ${type} from './${type}.json'`).join('\n')}
github contentful / rich-text / packages / rich-text-types / tools / jsonSchemaGen.ts View on Github external
lib: ['es2015', 'es2016', 'es2017', 'dom'],
};

const createJsonSchema = (symbolName: string, nodeType: string): void => {
  const doc = TJS.generateSchema(program, symbolName, settings);

  const schemaString = JSON.stringify(doc, null, 2);

  writeFile(`./src/schemas/generated/${nodeType}.json`, schemaString, (err: Error) => {
    if (err) {
      return console.log(err);
    }
  });
};

const program = TJS.getProgramFromFiles(
  [resolve('./src/types.ts'), resolve('./src/nodeTypes.ts')],
  compilerOptions,
);

const blockSymbolsMap = new Map([
  [BLOCKS.DOCUMENT, 'Document'],
  [BLOCKS.PARAGRAPH, 'Paragraph'],
  [BLOCKS.HEADING_1, 'Heading1'],
  [BLOCKS.HEADING_2, 'Heading2'],
  [BLOCKS.HEADING_3, 'Heading3'],
  [BLOCKS.HEADING_4, 'Heading4'],
  [BLOCKS.HEADING_5, 'Heading5'],
  [BLOCKS.HEADING_6, 'Heading6'],
  [BLOCKS.OL_LIST, 'OrderedList'],
  [BLOCKS.UL_LIST, 'UnorderedList'],
  [BLOCKS.LIST_ITEM, 'ListItem'],
github phodal / mest / src / mest.ts View on Github external
private getInterfaceScheme(interfaceName: any) {
    let splitInterfaceUrl = interfaceName.split('/')
    let fileName = splitInterfaceUrl[splitInterfaceUrl.length - 1]
    let typeName = fileName.substr(0, fileName.length - '.ts'.length)

    const program = TJS.getProgramFromFiles([resolve(interfaceName)], compilerOptions, basePath)
    return TJS.generateSchema(program, typeName, settings)
  }
github jumattos / lsif-util / src / validate.ts View on Github external
/*
     * Check #2: vertices are used in at least one edge
     */
    for (let key in vertices) {
        if (!visited[key] && vertices[key].label !== "metaData"){
            console.error(`Vertex ${key} is not connected to any other`);
            return false;
        }
    }
    printPass("Vertices are used in at least one edge");

    /*
     * Thorough validation
     */
    if (fs.existsSync(protocolPath)) {
        const program = TJS.getProgramFromFiles([protocolPath]);

        /*
         * Check #3: vertices properties are correct
         */
        const vertexSchema = TJS.generateSchema(program, "Vertex", { required: true });
        let count = 1;
        let length = Object.keys(vertices).length;
        for (let key in vertices) {
            outputMessage = `Verifying vertex ${count} of ${length}...`;
            process.stdout.write(`${outputMessage}\r`);
            count++;

            const validation = validateSchema(vertices[key], vertexSchema);
            if (!validation.valid) {
                console.log(`${outputMessage} error`);
                console.error(`Vertex ${key} is not valid:\n${JSON.stringify(vertices[key], null, 2)}`);
github keesschollaart81 / vscode-home-assistant / src / schemas / generateSchemas.ts View on Github external
import {resolve} from "path";
import * as TJS from "typescript-json-schema";
import * as fs from "fs";

const settings: TJS.PartialArgs = {
    required: true,
    noExtraProps: true
};

const compilerOptions: TJS.CompilerOptions = {
    strictNullChecks: true 
}
 

let program = TJS.getProgramFromFiles([resolve("src/schemas/ui-lovelace.ts")], compilerOptions); 
let schema = TJS.generateSchema(program, "LovelaceConfig", settings);
fs.writeFileSync("src/schemas/json/ui-lovelace.json", JSON.stringify(schema));

program = TJS.getProgramFromFiles([resolve("src/schemas/homeassistant.ts")], compilerOptions); 
schema = TJS.generateSchema(program, "HomeAssistantRoot", settings);
fs.writeFileSync("src/schemas/json/homeassistant.json", JSON.stringify(schema));

program = TJS.getProgramFromFiles([resolve("src/schemas/homeassistant.ts")], compilerOptions); 
schema = TJS.generateSchema(program, "HomeAssistantRoot", settings);
fs.writeFileSync("src/schemas/json/homeassistant-packages.json", JSON.stringify(schema));

program = TJS.getProgramFromFiles([resolve("src/schemas/ui-lovelace.ts")], compilerOptions); 
schema = TJS.generateSchema(program, "LovelaceViewConfig", settings);
fs.writeFileSync("src/schemas/json/lovelace-views-named.json", JSON.stringify(schema));

program = TJS.getProgramFromFiles([resolve("src/schemas/ui-lovelace.ts")], compilerOptions);
github Zilliqa / Zilliqa-JavaScript-Library / scripts / schema.ts View on Github external
.forEach((pkg) => {
      const settings = {
        ref: false,
      };

      const tsConfig: tjs.CompilerOptions = {
        lib: ['es2015'],
      };

      const prog = tjs.getProgramFromFiles(
        [path.resolve(path.join(pkg.src, 'types.ts'))],
        tsConfig,
      );

      const schema = tjs.generateSchema(prog, '*', settings);

      fs.writeFileSync(
        path.join(pkg.path, 'test', 'schema.json'),
        JSON.stringify(schema, undefined, 2),
      );
    });
}
github natergj / excel4node / scripts / generateJsonSchemas.ts View on Github external
import * as path from 'path';
import * as fs from 'fs';
import * as TJS from 'typescript-json-schema';

const settings: TJS.PartialArgs = {
  required: true,
};

const compilerOptions: TJS.CompilerOptions = {
  strictNullChecks: true,
  required: true,
};

const entryFile = path.resolve(__dirname, '../src/index.ts');
const program = TJS.getProgramFromFiles([entryFile], compilerOptions);
const generator = TJS.buildGenerator(program, settings);

if (generator) {
  const symbols = generator.getSymbols();
  symbols.forEach(symbol => {
    if (
      symbol.fullyQualifiedName.includes('excel4node') &&
      symbol.fullyQualifiedName.includes('types') &&
      !symbol.fullyQualifiedName.includes('node_modules')
    ) {
      const outFile = getSchemaPath(symbol.fullyQualifiedName);
      const schema = TJS.generateSchema(program, symbol.name, settings);
      fs.writeFileSync(outFile, JSON.stringify(schema, null, '  '));
    }
  });
}
github hmmhmmhm / dva-engine / bin / core / generator / util.ts View on Github external
export const parseInterfaces = async ( filePath: string) => {
    const settings: TJS.PartialArgs = {
        aliasRef: true,
        required: true
    }
    const compilerOptions: TJS.CompilerOptions = { strictNullChecks: true }

    const program = TJS.getProgramFromFiles([Path.resolve(filePath)], compilerOptions)

    const schema = TJS.generateSchema(program, '*', settings)
    if(schema == null || schema.definitions == null) throw new Error('Failed Generator Init')
    return schema.definitions
}