typescript-schema-generator

1.0.14 • Public • Published

TypeScript Schema Generator

This project is CLI command used to generate TypeScript schemas from JSON files with custom imports and types.

Installation

  yarn install -D typescript-schema-generator

Usage

CLI Options

  Usage: ts-generator [options]

  Options:
   -p, --projectPath <path>  Path to the project
   -s, --srcDir <path>       Path to the templates source directory
   -d, --destDir <path>      Path to the output directory
    

Example

  ts-generator -p /path/to/project -s /path/to/templates -d /path/to/output

Templates

Schema definitions

Refer to this repository for Schema Definition: https://github.com/bcherny/json-schema-to-typescript

Custom Schema

The templates are written in json and can be customized to fit your needs. A single schema template can define multiple schema types and group into single file.

 [
  {
    "title": "PermissionManifest",
    "tsType": "Record<UserStateCode, UserStateManifest>"
  },
  {
    "title": "UserStateManifest",
    "type": "object",
    "additionalProperties": false,
    "properties": {
      "permissions": {
        "tsType": "UserPermission[]"
      },
      "transitionRules": {
        "tsType": "TransitionRule"
      }
    },
    "required": [
      "permissions",
      "transitionRules"
    ]
  }
]

The following schema object are available in the templates:

  {
    "customTypeImports": [
      "import {  UserPermission, UserStateCode } from './user.type';"
    ]
  }

Readme

Keywords

none

Package Sidebar

Install

npm i typescript-schema-generator

Weekly Downloads

2

Version

1.0.14

License

MIT

Unpacked Size

6.69 kB

Total Files

4

Last publish

Collaborators

  • thomas.tran.dev