OrKoN / schema-script

Zero-configuration pre-processor for generating runtime and static TypeScript/GraphQL types based on JSON schemas.

Repository from Github https://github.comOrKoN/schema-scriptRepository from Github https://github.comOrKoN/schema-script

schema-script npm

newsletter cli demo

Zero-configuration pre-processor for generating runtime and static TypeScript/GraphQL types based on JSON schemas.

Features

✍️ JSON Schema for defining external interfaces (APIs, database, user input)

🌈 Generate static and runtime TypeScript types

😎 Generated files look great thanks to prettier, formatted according to your project settings.

Prerequisites

  • put your JSON schemas files in the folders where you want the generated types to be placed
  • use the following pattern for naming files <typeName>.schema.json
  • add a $comment attribute to your schemas and define what schema-script should generate:
      "$comment": "+ts +iots +graphql"
    

Note: for +iots install io-ts(a TypeScript compatible runtime type system for IO decoding/encoding).

Note: +graphql support is coming.

Getting Started

npm i schema-script -g
schema-script <dir-with-schemas>
ss  <dir-with-schemas>

schema-script will go over all files matching the pattern <typeName>.schema.json. It will generate TypeScript files next to the schema file as following <TypeName>.ts.

Examples

See ./examples for some examples of generated types.

Get Help

Probably schema-script is not working as expected for all possible JSON schemas. It needs more testing and your feedback:

Open an issue

About

Zero-configuration pre-processor for generating runtime and static TypeScript/GraphQL types based on JSON schemas.

License:MIT License


Languages

Language:TypeScript 99.2%Language:JavaScript 0.8%