1.0.14 • Published 1 year ago

typescript-schema-generator v1.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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';"
    ]
  }
1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago