How to use the typescript-json-schema.generateSchema 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 jumattos / lsif-util / src / validate.ts View on Github external
});
                    }
                    catch {
                        // Failed to get more details for the error
                    }
                }
                return false;
            }
        }
        console.log(`${outputMessage} done`);
        printPass("Vertices properties are correct");

        /*
         * Check #4: edges properties are correct
         */
        const edgeSchema = TJS.generateSchema(program, "Edge", { required: true, noExtraProps: true });
        count = 1;
        length = Object.keys(edges).length;
        for (let key in edges) {
            outputMessage = `Verifying edge ${count} of ${length}...`;
            process.stdout.write(`${outputMessage}\r`);
            count++;

            const validation = validateSchema(edges[key], edgeSchema);
            if (!validation.valid) {
                console.log(`${outputMessage} error`);
                console.error(`Edge ${key} is not valid:\n${JSON.stringify(edges[key], null, 2)}`);
                
                // Since we checked for inV and outV before, the only possible problem is the label
                if (!edges[key].label || edges[key].label === "") {
                    printError(`requires property "label"`);
                }
github transitive-bullshit / functional-typescript / packages / fts / src / parser.ts View on Github external
}

  if (!builder.definition.params.schema) {
    throw new Error(`Error generating params JSON schema for TS file "${file}"`)
  }

  // fix required parameters to only be those which do not have default values
  const { schema } = builder.definition.params
  schema.required = (schema.required || []).filter(
    (k) => schema.properties[k].default === undefined
  )
  if (!schema.required.length) {
    delete schema.required
  }

  builder.definition.returns.schema = TJS.generateSchema(program, FTSReturns, {
    ...jsonSchemaOptions,
    required: false
  })

  if (!builder.definition.returns.schema) {
    throw new Error(
      `Error generating returns JSON schema for TS file "${file}"`
    )
  }
}
github transitive-bullshit / functional-typescript / packages / fts / src / parser.ts View on Github external
const compilerOptions = {
    allowJs: true,
    lib: ['es2018', 'dom'],
    target: 'es5',
    esModuleInterop: true,
    ...jsonCompilerOptions
  }

  const program = TJS.getProgramFromFiles(
    [file],
    compilerOptions,
    process.cwd()
  )

  builder.definition.params.schema = {
    ...TJS.generateSchema(program, FTSParams, jsonSchemaOptions),
    ...(builder.definition.params.schema || {}) // Spread any existing schema params
  }

  if (!builder.definition.params.schema) {
    throw new Error(`Error generating params JSON schema for TS file "${file}"`)
  }

  // fix required parameters to only be those which do not have default values
  const { schema } = builder.definition.params
  schema.required = (schema.required || []).filter(
    (k) => schema.properties[k].default === undefined
  )
  if (!schema.required.length) {
    delete schema.required
  }
github jumattos / lsif-util / src / validate.ts View on Github external
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)}`);

                if (!vertices[key].label || vertices[key].label === "") {
                    printError(`requires property "label"`);
                }
                else {
github contentful / rich-text / packages / rich-text-types / tools / jsonSchemaGen.ts View on Github external
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);
    }
  });
};
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 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
}
github keesschollaart81 / vscode-home-assistant / src / schemas / generateSchemas.ts View on Github external
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); 
schema = TJS.generateSchema(program, "LovelaceViewConfigs", settings);
fs.writeFileSync("src/schemas/json/lovelace-views-list.json", JSON.stringify(schema));

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

program = TJS.getProgramFromFiles([resolve("src/schemas/automation.ts")], compilerOptions); 
schema = TJS.generateSchema(program, "Automations", settings);
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); 
schema = TJS.generateSchema(program, "LovelaceViewConfigs", settings);
github keesschollaart81 / vscode-home-assistant / src / schemas / generateSchemas.ts View on Github external
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); 
schema = TJS.generateSchema(program, "LovelaceViewConfigs", settings);
fs.writeFileSync("src/schemas/json/lovelace-views-list.json", JSON.stringify(schema));

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

program = TJS.getProgramFromFiles([resolve("src/schemas/automation.ts")], compilerOptions); 
schema = TJS.generateSchema(program, "Automations", settings);
fs.writeFileSync("src/schemas/json/automations-list.json", JSON.stringify(schema));