Generate JSON schema from your Typescript sources
Find a file
2019-01-14 09:12:50 +00:00
.vscode Use latest TS in vscode 2018-08-02 08:59:00 -07:00
bin Fix bin 2017-09-05 14:07:53 -07:00
dist fix typescript version 2018-12-11 19:16:54 -06:00
factory Merge 2019-01-14 09:12:30 +00:00
src Merge 2019-01-14 09:12:30 +00:00
test add support for unknown type keyword (#57) 2018-12-19 14:04:13 -08:00
.editorconfig Add .editorconfig file. 2017-02-01 17:13:41 +07:00
.gitignore Add dist 2018-12-11 19:00:17 -06:00
.npmignore Set up CI with Azure Pipelines (#48) 2018-10-01 22:45:26 -07:00
azure-pipelines.yml Test on node 11 (#53) 2018-12-04 18:40:50 -08:00
index.ts Add call expression parser so that we support Vega-Lite again 2018-05-06 20:33:24 -07:00
package.json v0.38.1 2018-12-29 23:30:40 -08:00
README.md Add command line option to skip type checks 2018-10-20 08:02:42 +02:00
ts-json-schema-generator.ts Add command line option to skip type checks 2018-10-20 08:02:42 +02:00
tsconfig.json Fix test 2018-09-24 16:47:06 -07:00
tslint.json Remove obvious arrow-parameter types. (#20) 2018-05-06 15:42:23 -07:00
yarn.lock Upgrade deps 2018-12-19 15:21:53 -08:00

ts-json-schema-generator

Build Status npm dependencies npm version

Extended version of https://github.com/xiag-ag/typescript-to-json-schema.

Inspired by YousefED/typescript-json-schema. Here's the differences list:

  • this implementation does not use typeChecker.getTypeAtLocation() (so probably it keeps correct type aliases)
  • the following features are not supported yet:
    • class types
  • processing AST and formatting JSON schema have been split into two independent steps
  • not exported types, interfaces, enums are not exposed in the definitions section in the JSON schema

Usage

npm install --save ts-json-schema-generator
./node_modules/.bin/ts-json-schema-generator \
    --path 'my/project/**.*.ts' \
    --type 'My.Type.Full.Name' \
    --expose 'export' \
    --jsDoc 'extended'

Options

-e, --expose <all|none|export>
    all: Create shared $ref definitions for all types.
    none: Do not create shared $ref definitions.
    export:  Create shared $ref definitions only for exported types.

-r, --no-top-ref
    Do not create a top-level $ref definition.

-j, --jsDoc <extended|none|basic>
    basic: Read JsDoc annotations to provide schema properties.
    extended: Also read @nullable, and @asType annotations.
    none: Do not use JsDoc annotations.

-c, --skip-type-check
    Skip type checks for better performance.

-s, --strict-tuples
    Do not allow additional items on tuples.

-u, --unstable
    Do not sort properties.

Current state

  • interface types
  • enum types
  • union, tuple, type[] types
  • string, boolean, number types
  • "value", 123, true, false, null, undefined literals
  • type aliases
  • generics
  • typeof
  • keyof

Debug

npm run debug -- test/programs/type-alias-single/main.ts --aliasRefs true MyString

And connect via the debugger protocol.

AST Explorer is amazing for developers of this tool!