Détail du package

@json-schema-tools/transpiler

json-schema-tools17.7kApache-2.01.10.5

Turn your json schema into typings for various languages. Achieve master class dev tooling.

readme

JSON Schema Transpiler

CircleCI branch npm GitHub release GitHub commits since latest release

Turn your JSON Schemas into types to be used in various languages.

Try Me

  • Generate types for:
    • Golang
    • Typescript
    • Rust
    • Python
  • handles cycle detection
  • automatically determines references
  • includes documentation annotations for easy documentation generation with native language tools.
  • minimal dependencies (wip)
  • Creates 1 type alias per 1 schema
  • Autogenerated deterministic titles where missing
  • Autoreferencer (removes duplication)
  • Code is synchronous - no IO keeps it lean and fast
  • Convert schema to types in browser too!

Getting Started

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)

Testing

Generate a test case

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.

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.

changelog

1.10.5 (2024-05-07)

Bug Fixes

1.10.4 (2024-05-07)

Bug Fixes

  • bump node 20 (e9c3031)
  • remove inquirer dep (24a512f)
  • test generator working and update referencer (9e6db32)

1.10.3 (2023-01-17)

Bug Fixes

  • add circle ci context and update node version (70a4044)
  • languageSafeName leading digits to words (d7b23a4)
  • tests and typedoc (a91c694)
  • update deps (26572d9)

1.10.2 (2021-07-30)

Bug Fixes

  • replaceTypeAsArray should use titleizer (951d511)

1.10.1 (2021-06-24)

Bug Fixes

  • update to new meta-schema (13487f5)

1.10.0 (2021-06-18)

Features

  • rust boxing properly now (d1b2981)

1.9.0 (2021-06-17)

Bug Fixes

  • add return types to most of the utils (75b3245)
  • clean up remenants of bad ideas (9d0ef32)
  • run lint fix (9a2d65e)
  • update deps and regen package-lock (6ea95ee)

Features

1.8.2 (2021-06-15)

Bug Fixes

1.8.1 (2021-06-15)

Bug Fixes

  • non literal enum should not derive eq (b86f15c), closes #384

1.8.0 (2021-06-11)

Features

  • rust fixes & general maintenance items (4b78a06)

1.7.6 (2021-05-27)

Bug Fixes

  • update test and fix edge case (8ea5304)

1.7.5 (2021-05-27)

Bug Fixes

  • reserved words checked after prefix (59b8e10)

1.7.4 (2021-05-27)

Bug Fixes

1.7.3 (2021-05-26)

Bug Fixes

  • rust struct field naming (cc664d5)

1.7.2 (2021-05-26)

Bug Fixes

  • remove leading symbols in languages that dont allow them (8ab3291)

1.7.1 (2021-05-20)

Bug Fixes

  • bump deps for security fixes (32cb664)
  • code cleanup (03cad4e)
  • string enums for rust python and go (206d288)

1.7.0 (2020-12-10)

Bug Fixes

Features

  • handle type as array in best way possible (e435656)

1.6.1 (2020-12-07)

Bug Fixes

  • no longer use nodenv in gh action (3a91e8e)

1.6.0 (2020-11-16)

Bug Fixes

  • replace referencer with packaged one (ce62da2)
  • run lint fix (6a2e926)

Features

  • implement const in ts and rust (cbeb502)

1.5.7 (2020-11-04)

Bug Fixes

1.5.6 (2020-10-29)

Bug Fixes

1.5.5 (2020-10-28)

Bug Fixes

1.5.4 (2020-10-23)

Bug Fixes

1.5.3 (2020-10-23)

Bug Fixes

1.5.2 (2020-10-23)

Bug Fixes

1.5.1 (2020-10-23)

Bug Fixes

1.5.0 (2020-10-09)

Bug Fixes

Features

  • implement imports as part of IR (9f7ba6b)

1.4.3 (2020-10-08)

Bug Fixes

  • update docs for titleizer (5c6f8fa)

1.4.2 (2020-09-09)

Bug Fixes

1.4.1 (2020-07-28)

Bug Fixes

  • only publish built files (bd90329)

1.4.0 (2020-07-28)

Bug Fixes

Features

  • generate code for patternProperties (c5e38b9)

1.3.0 (2020-07-21)

Features

  • all tests passing with new newnew (5e2a135)

1.2.1 (2020-07-20)

Bug Fixes

1.2.0 (2020-07-20)

Bug Fixes

  • all unit tests passing (15cb174)
  • almost there... (0f5db50)
  • broken test and extra garbage log (65739ff)
  • getting close to being the best in the world (31b9168)
  • oh my god its alive (cd0b386)
  • things looking good (36e4b1f)
  • update package lock after rebase (5692401)
  • wip wip (a92df4a)

Features

1.1.0 (2020-07-02)

Bug Fixes

Features

1.0.1 (2020-06-30)

Bug Fixes

1.0.0 (2020-06-25)

Bug Fixes

Features