Extract JSON Schema from TypeScript
Generate a json schema from a TypeScript interface.
Supported features:
Literals
([], "foo", 123,...)Keywords
(number, string, boolean,...)Union Types
Interfaces
Type Alias
Mapped Types
(Record, Partial, Readonly, Pick)extends
enums
Installation
# npm npm install --save ts-extract # yarn yarn add ts-extract
Usage
ts-extract
can be both used as a standard node module or as a cli binary.
Node
const path = ;const createSchema = ; const file = path;const type = "Foo" // Type to extractconst schema = ;// Logs:// {// "$schema": "http://json-schema.org/draft-06/schema#",// "definitions": { ... },// "type": "object",// "properties": { ... },// }
CLI
$ ts-extract --help ts-extract [options] -t MyType my/source.ts Options: -t, --type Name of type [required] -c, --config path to tsconfig.json [string] -h, --help Show help [boolean] -v, --version Show version [boolean] Example: ts-extract -t MyType my/source.ts
License
MIT
, see License file.