npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@anttiviljami/dtsgenerator

v3.20.0

Published

TypeScript d.ts file generator for JSON Schema file

Downloads

75,713

Readme

dtsgenerator

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 Stake to support us MIT license

Table of Contents

Install

npm install -g dtsgenerator

Usage

CLI

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

Options:
  -V, --version           output the version number
  -c, --config <file>     set configuration file path.
  --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

Examples:
  $ 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

For the configuration file, please refer to the file in the config_sample directory.

NodeJS API

const { default: dtsgenerator, parseSchema } = require('dtsgenerator');

dtsgenerator({
    contents: [parseSchema({/* JsonSchema object */})],
    config: {/* Config object */},
}).then(content => {
    /* Do someting with parsed content */
}).catch(err => {
    /* Handle errors */
});

Use HTTP/HTTPS Proxy

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 breaking 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.

Plug-in

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

Development

Debug

Output debug message by debug library.

DEBUG=dtsgen dtsgen schema/news.json

Links about JSON Schema and Swagger

Supported spec and features

ChangeLog

v3.19.1 (2023-08-25)

  • features:
    • Update plugins for new TypeScript AST.
    • Changed supported Node.js version to 16 or later. Also, we have confirmed that it works with Node.js v20.

v3.18.0 (2023-03-02)

  • features:
    • Support 'application/json' with parameter media type for #551. Thank you @denizkenan :+1:

v3.17.0 (2023-02-21)

  • features:
    • Return exit code 1 when error occurs by #549. Thank you @lhotamir :+1:

v3.16.2 (2022-12-20)

  • fixed:
    • Fix to remove deprecated decorators parameters for #547. Thank you @mcollina :+1:

v3.16.0 (2022-06-10)

  • features:
    • Support 'image/*' media types for #539. Thank you @Geloosa :+1:

older versions history

ChangeLogs

License

dtsgenerator is licensed under the MIT license.

Copyright © 2016-2020, Hiroki Horiuchi