@etclabscore/json-schema-to-types
v1.12.0
Published
This is a JSON-Schema transpiler. It converts a JSON Schema into types for various strongly typed languages.
Downloads
38
Keywords
Readme
JSON-Schema-To-Types
This is a JSON-Schema transpiler. It converts a JSON Schema into types for various strongly typed languages.
Features:
- Supports the following languages:
- Typescript
- Rust
- Go
- Python
- minimal external dependencies
- circular JSON structure handling
- Supports merging multiple JSONSchema into one set of types
- Generates titles for schemas that are missing them
- Run in browser / node
Installing
npm install --save @etclabscore/json-schema-to-types
Usage
const schema = {
title: "testerooskies",
type: "object",
properties: {
fooThing: { title: "foo", type: "string" },
barThing: { title: "bar", type: "number" },
},
};
const transpiler = new JsonSchemaToTypes(schema);
console.log(transpiler.toRust())
/** outputs:
"#[derive(Serialize, Deserialize)]
pub struct testerooskies {
pub(crate) fooThing: foo,
pub(crate) barThing: bar,
**
pub type foo = String;
pub type bar = String;"
**/
console.log(transpiler.toTypescript());
/**outputs
"export interface testerooskies {
fooThing: foo;
barThing: bar;
}
export type foo = string;
export type bar = string;"
**/
To add a new integration test case
npm run test:generate
Contributing
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.