TypeScript d.ts file generator for JSON Schema file

Usage no npm install needed!

<script type="module">
  import dtsgeneratorRr from 'https://cdn.skypack.dev/dtsgenerator-rr';



TypeScript d.ts file generator from JSON Schema file or OpenAPI(Swagger) spec file.

nodejs version npm version build status Coverage Status npm download count dtsgenerator Dev Token MIT license

Table of Contents


npm install -g dtsgenerator


$ dtsgen --help
Usage: dtsgenerator [options] <file ... | file patterns using node-glob>

  -V, --version           output the version number
  -c, --config <file>     set configuration file path. (default: "dtsgen.json")
  --url <url>             input json schema from the url. (default: [])
  --stdin                 read stdin with other files or urls.
  -o, --out <file>        output filename.
  -t, --target <version>  Specify ECMAScript target version: 'ES3', 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT' (default).
  --info                  for developer mode. output loaded config and plugin details only.
  --output-ast            output TypeScript AST instead of d.ts file.
  -h, --help              display help for command


    $ dtsgen --help
    $ dtsgen --out types.d.ts schema/**/*.schema.json
    $ cat schema1.json | dtsgen -c dtsgen.json
    $ dtsgen -o swaggerSchema.d.ts --url https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v2.0/schema.json
    $ dtsgen -o petstore.d.ts --url https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/yaml/petstore.yaml
    $ dtsgen -c dtsgen-test.json --info


If you need a proxy to fetch the schema, please set the following environment variables.

export http_proxy=http://proxy.example.com:8080/
export https_proxy=http://proxy.example.com:8080/
# If there are exceptionally hosts that do not go through a proxy
export no_proxy=google.com, yahoo.com

Migration from v2

The dtsgenerator v3 has made the following braking changes from v2.

  • Support Plug-in feature. See the Plug-in section for more information.
  • Change the command line options.
    • Remove the --namespace option. Use the @dtsgenerator/replace-namespace plug-in instead.
    • Add the --config option. Mainly for setting up the Plug-in.
    • And add more options.
  • TypeScript AST is now used internally to generate type definitions.


How to find plug-in

How to create plug-in

  1. Scaffold by the command:
    • npm init @dtsgenerator **plugin-name**
  2. Edit **plugin-name**/index.ts
  3. Do test:
    • npm test
  4. Build it:
    • npm run build
  5. Publish to npm:
    • npm publish



Output debug message by debug library.

$ DEBUG=dtsgen dtsgen schema/news.json

Links about JSON Schema and Swagger

Supported spec and features

  • JSON Schema

    • Draft-04 and before
    • Draft-07 and before
  • OpenAPI

    • OpenAPI Specification version 2.0
    • OpenAPI Specification version 3.0
  • supported features in these spec


v3.3.0 (2020-07-29)

  • features:
    • Support the patternProperties by #436. Thank you @nfroidure :+1:
  • fixed:
    • Definition generated improperly when multiple instances of a resource are inherited by #279. Thank you @btg5679 :+1:
    • Apply the prettier config on .eslintrc.json.

v3.2.0 (2020-07-20)

  • features:
    • Add support for application/octet-stream media type by #431. Thank you @MisterChateau :+1:

v3.1.1 (2020-06-23)

  • fixed:
    • Cannot load config file of relative path by #428. Thank you @DamianOsipiuk :+1:

v3.1.0 (2020-06-22)

  • features:
    • Add support for nullable anyOf in OpenApi v3 by #426. Thank you @joost-kersjes-webpower :+1:

v3.0.3 (2020-06-15)

  • fixed:
    • Fix the command option example by #422. Thank you @maapteh :+1:
    • Omit load config error on not config option by #425. Thank you @Christian24 :+1:

v3.0.2 (2020-06-11)

  • fixed:
    • Remove old example by #421. Thank you @maapteh :+1:

v3.0.1 (2020-06-09)

  • features:
    • Support the plug-in for pre-process and post-process.
    • Change command line options and Support config file.
    • Use the TypeScript AST for intermediate format.

older versions history



dtsgenerator is licensed under the MIT license.

Copyright © 2016-2020, Hiroki Horiuchi