mirror of
https://github.com/JakeStanger/ts-json-schema-generator.git
synced 2026-07-11 07:44:42 +01:00
Generate JSON schema from your Typescript sources
- TypeScript 100%
| .vscode | ||
| bin | ||
| dist | ||
| factory | ||
| src | ||
| test | ||
| .editorconfig | ||
| .gitignore | ||
| .npmignore | ||
| azure-pipelines.yml | ||
| index.ts | ||
| package.json | ||
| README.md | ||
| ts-json-schema-generator.ts | ||
| tsconfig.json | ||
| tslint.json | ||
| yarn.lock | ||
ts-json-schema-generator
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:
classtypes
- processing AST and formatting JSON schema have been split into two independent steps
- not exported types, interfaces, enums are not exposed in the
definitionssection 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
interfacetypesenumtypesunion,tuple,type[]typesstring,boolean,numbertypes"value",123,true,false,null,undefinedliterals- type aliases
- generics
typeofkeyof
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!