# typescript-to-json-schema

> Generate JSON schema from your Typescript sources

Latest version **0.6.1** (published 2020-08-17) · 0 weekly downloads

## Install

```sh
npm install typescript-to-json-schema
pnpm add typescript-to-json-schema
yarn add typescript-to-json-schema
bun add typescript-to-json-schema
```

Provides the command `typescript-to-json-schema`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.1 |
| Published | 2020-08-17 |
| First published | 2017-02-01 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 4 |
| Unpacked size | 235 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 75 |
| Author | Alexander Evtushenko |
| Maintainers | mrix |
| Keywords | ts, typescript, json, schema, jsonschema |

## Links

- npm: https://www.npmjs.com/package/typescript-to-json-schema
- Repository: https://github.com/xiag-ag/typescript-to-json-schema
- Homepage: https://github.com/xiag-ag/typescript-to-json-schema#readme
- Issues: https://github.com/xiag-ag/typescript-to-json-schema/issues
- npm.io page: https://npm.io/package/typescript-to-json-schema

## Dependencies (4)

- [glob](https://npm.io/package/glob.md) ^7.1.2
- [commander](https://npm.io/package/commander.md) ^2.15.1
- [typescript](https://npm.io/package/typescript.md) ~2.8.3
- [json-stable-stringify](https://npm.io/package/json-stable-stringify.md) ^1.0.1

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.6.1 (latest) — 2020-08-17
- 0.6.0 — 2018-05-18
- 0.5.0 — 2018-05-16
- 0.4.0 — 2018-05-08
- 0.3.0 — 2018-01-24
- 0.2.1 — 2017-03-14
- 0.2.0 — 2017-03-12
- 0.1.0 — 2017-03-11
- 0.0.2 — 2017-02-01
- 0.0.1 — 2017-02-01

## 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!

---
_Source: https://npm.io/package/typescript-to-json-schema · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
