Turn your JSON Schemas into types to be used in various languages.
npm install @json-schema-tools/transpiler
const JsonSchemaTranspiler = require("@json-schema-tools/transpiler").default;
const mySchema = {
"title": "PlowAnimals",
"description": "an array of animals that are good at pulling things",
"type": "array",
"items": {
"oneOf": [
{ "title": "Horse" },
{ "title": "Donkey" },
{ "title": "Elephant" },
]
}
};
const transpiler = new JsonSchemaTranspiler(mySchema);
console.log(transpiler.toTypescript());
console.log(transpiler.toRust());
console.log(transpiler.to("go")); // same thing, different form/interface
console.log(transpiler.to("python")); // works with shorthand of the language aswell (py or python)
npm run generateTest
outputs:
> @json-schema-tools/transpiler@0.0.0-development generateTest /Users/zb/Code/json-schema-tools/transpiler
> tsc && node ./build/integration-tests/generator.js
? What is the name of the test schema? type-as-array
? Enter a url to a JSON Schema, or press enter to get an empty one? false
Detecting languages...
Found 4 languages: go, py, rs, ts
Writing files...
All done
Edit schema if necessary, and run npm test
. Update expected results as needed.
How to contribute, build and release are outlined in CONTRIBUTING.md, BUILDING.md and RELEASING.md respectively. Commits in this repository follow the CONVENTIONAL_COMMITS.md specification.