@etclabscore/json-schema-to-types
TypeScript icon, indicating that this package has built-in type declarations

1.12.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @etclabscore/json-schema-to-types

Weekly Downloads

25

Version

1.12.0

License

Apache-2.0

Unpacked Size

112 kB

Total Files

22

Last publish

Collaborators

  • belfordz
  • devonwesley
  • shanejonas
  • zcstarr