typescript-schema-generator
v1.0.14
Published
This project is CLI command used to generate TypeScript schemas from JSON files with custom imports and types.
Downloads
5
Readme
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';"
]
}