0.0.7 • Published 6 years ago
ts-extract v0.0.7
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 = require("path");
const { createSchema } = require("ts-extract");
const file = path.resolve("./path/to/my/source.ts");
const type = "Foo" // Type to extract
const schema = createSchema(file, type);
// 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.