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

To help you get started, we’ve selected a few json-schema-to-typescript 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 interledgerjs / rafiki / scripts / build_schema_types.js View on Github external
;(async function () {
  for (let schema of schemas) {
    // Have to pass an empty options object, otherwise we trigger a bug where
    // the cwd for the JSON schema $ref resolver defaults to the current
    // working directory instead of the file's directory.
    let ts = await compileFromFile(resolve(__dirname, '../src/schemas/', schema), {})

    if (schema === 'Config.json') {
      ts = ts
        // This is the only way to let Config inherit from the interface without
        // redefining all the fields.
        .replace('export interface Config', 'export class Config')
        // Ignore the error stating that `accounts` isn't assigned in the
        // constructor.
        .replace('accounts: {', 'accounts!: {')
    }

    fs.writeFileSync(resolve(__dirname, '../src/schemas/', schema.split('.')[0] + 'Typing.ts'), ts)
  }
})()
  .catch(err => console.error(err))
github tom-grey / fpl-api-graphql / tasks / prebuild / prebuild.ts View on Github external
}
  const fixturePath = `${fixturesDir}/${name}.data.json`;
  jsosnfile.writeFileSync(fixturePath, humps.camelizeKeys(data));
  console.log(chalk.green(`[task:prepbuild] writing fixture ${fixturePath}`));

  const schemaPath = `${schemaDir}/${name}.schema.json`;
  const schema = schemify(humps.camelizeKeys(data));
  jsosnfile.writeFileSync(schemaPath, schema, {
    spaces: 2,
  });
  console.log(
    chalk.green(`[task:prepbuild] writing json schema ${schemaPath}`),
  );

  const interfacesPath = `./src/interfaces/${name}.interface.ts`;
  const interfaces = await compileFromFile(
    `${buildRoot}/json-schemas/${name}.schema.json`,
  );
  fs.writeFileSync(interfacesPath, interfaces);
  console.log(
    chalk.green(`[task:prepbuild] writing interface ${interfacesPath}`),
  );
}
github prescottprue / fireadmin / packages / core / scripts / schemaToTypescript.ts View on Github external
fs.readdirSync('./src/schemas').forEach(file => {
  console.log(file);
  const { name: fileName } = parse(file)
  const resultPath = `${process.cwd()}/src/types/${fileName}.ts`
  if (fs.existsSync(resultPath)) {
    console.log(`${resultPath} already exists, skipping`)
    return null
  }
  compileFromFile(`${process.cwd()}/src/schemas/${file}`, { bannerComment: `/**\n\t* Value representing a ${fileName}.\n\t*/` })
  .then(ts => fs.writeFileSync(resultPath, ts))
});
github BjoernKW / spring-data-rest-json-schema-to-typescript-definitions / src / index.ts View on Github external
async function generateClassFromJSON(property: string) {
  writeFileSync(`${outputPath}/${property}.d.ts`, await compileFromFile(`${outputPath}/${property}.json`, {
    style: {
      singleQuote: true
    }
  }));

  console.log(`Type definition for '${property}' has been saved to: ${outputPath}/${property}.d.ts`);
}
github BjoernKW / spring-data-rest-json-schema-to-typescript-definitions / dist / index.js View on Github external
return __generator(this, function (_c) {
            switch (_c.label) {
                case 0:
                    _a = fs_1.writeFileSync;
                    _b = [outputPath + "/" + property + ".d.ts"];
                    return [4 /*yield*/, json_schema_to_typescript_1.compileFromFile(outputPath + "/" + property + ".json", {
                            style: {
                                singleQuote: true
                            }
                        })];
                case 1:
                    _a.apply(void 0, _b.concat([_c.sent()]));
                    console.log("Type definition for '" + property + "' has been saved to: " + outputPath + "/" + property + ".d.ts");
                    return [2 /*return*/];
            }
        });
    });
github bcherny / json-schema-to-typescript / example / index.ts View on Github external
async function generate() {
  writeFileSync('person.d.ts', await compileFromFile('person.json'))
}
github adobe / helix-pipeline / bin / schema2ts.js View on Github external
},
  bannerComment: `/*
 * Copyright 2018 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */`,
};

compileFromFile('docs/context.schema.json', options).then((ts) => writeFileSync('src/context.d.ts', ts));
compileFromFile('docs/action.schema.json', options).then((ts) => writeFileSync('src/action.d.ts', ts));
github intershop / intershop-pwa / schematics / scripts / generate-schema-defs.js View on Github external
schemaFiles.map(async (schemaFile, idx) => {
      const definitionFile = schemaFile.replace(extname(schemaFile), tsDefExtension);
      const output = await compileFromFile(schemaFile);

      const content = output.replace(new RegExp('.*any.*\n', 'g'), '');
      writeFileSync(definitionFile, content);
      return definitionFile;
    })
  );
github adobe / helix-pipeline / bin / schema2ts.js View on Github external
},
  },
  bannerComment: `/*
 * Copyright 2018 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */`,
};

compileFromFile('docs/context.schema.json', options).then((ts) => writeFileSync('src/context.d.ts', ts));
compileFromFile('docs/action.schema.json', options).then((ts) => writeFileSync('src/action.d.ts', ts));

json-schema-to-typescript

compile json schema to typescript typings

MIT
Latest version published 1 month ago

Package Health Score

87 / 100
Full package analysis