GithubHelp home page GithubHelp logo

json-schema-tools / transpiler Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 7.0 1.65 MB

Transpile JSON Schema to Type aliases for many languages

Home Page: https://json-schema-tools.github.io/transpiler/

License: Apache License 2.0

Shell 0.36% JavaScript 0.32% TypeScript 45.42% Go 23.65% Python 11.03% Rust 19.21%
jsonschema json-schema-generator typings open-rpc open-api

transpiler's Introduction

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/[email protected] 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.