Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiag-ag/typescript-to-json-schema
Generate JSON schema from your Typescript sources
https://github.com/xiag-ag/typescript-to-json-schema
cli generator json json-schema schema ts typescript
Last synced: 6 days ago
JSON representation
Generate JSON schema from your Typescript sources
- Host: GitHub
- URL: https://github.com/xiag-ag/typescript-to-json-schema
- Owner: xiag-ag
- Created: 2017-02-01T09:02:33.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T18:07:38.000Z (almost 2 years ago)
- Last Synced: 2024-10-25T06:40:44.348Z (16 days ago)
- Topics: cli, generator, json, json-schema, schema, ts, typescript
- Language: TypeScript
- Size: 306 KB
- Stars: 70
- Watchers: 3
- Forks: 8
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# typescript-to-json-schema
[![npm version](https://img.shields.io/npm/v/typescript-to-json-schema.svg)](https://www.npmjs.com/package/typescript-to-json-schema)
[![Build Status](https://travis-ci.org/xiag-ag/typescript-to-json-schema.svg?branch=master)](https://travis-ci.org/xiag-ag/typescript-to-json-schema)
[![Coverage Status](https://coveralls.io/repos/github/xiag-ag/typescript-to-json-schema/badge.svg?branch=master)](https://coveralls.io/github/xiag-ag/typescript-to-json-schema?branch=master)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)Inspired by [`YousefED/typescript-json-schema`](https://github.com/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
* conditional 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
```bash
npm install typescript-to-json-schema
./node_modules/.bin/typescript-to-json-schema \
--path 'my/project/**.*.ts' \
--type 'My.Type.Full.Name' \
--expose 'export' \
--topRef 'yes' \
--jsDoc 'extended'
```## 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](https://astexplorer.net/) is amazing for developers of this tool!