Skip to content

Instantly share code, notes, and snippets.

@robertlong
Created March 20, 2017 19:43
Show Gist options
  • Save robertlong/3d5f771a992ff9374d64d92c95952674 to your computer and use it in GitHub Desktop.
Save robertlong/3d5f771a992ff9374d64d92c95952674 to your computer and use it in GitHub Desktop.
JSON Schema to Typescript with External References
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const RefParser = require('json-schema-ref-parser');
const Generator = require('json-schema-to-typescript');
const schemaPath = process.argv[2];
const outputPath = process.argv[3];
RefParser.dereference(schemaPath)
.then((schema) => {
return Generator.compile(schema)
})
.then((interface) => {
fs.writeFile(outputPath, interface, (err) => {
if (err) throw err;
console.log(`Success! \nOutput to ${outputPath}`);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment