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

dtsintergen

v2.3.2

Published

TypeScript d.ts file generator for JSON Schema files, with generation of intersection types. Fork of horiuchi/dtsgenerator.

Downloads

3

Readme

dtsintergen

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

This is a FORK of horiuchi/dtsgenerator. When the intersection flag is set, this fork generates an alternate rendering of the d.ts files using Typescript's Intersection Types. You must use the -i flag to enable intersection. See test/intersection_test.ts.

See the most recent commits on master branch for diff between dtsgenerator and dtsintergen. The version number of dtsintergen will correspond to the version of dtsgenerator from which it is based, down to the minor version. I.e. 2.3.x of dtsintergen corresponds to 2.3.x of dtsgenerator. The patch numbers (x) in the preceding example, are not in sync.

nodejs version npm version build status Coverage Status Greenkeeper badge npm download count MIT license

Table of Contents

Install

npm install -g dtsintergen

Usage

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

Options:

  -V, --version                output the version number
  --url <url>                  input json schema from the url. (default: )
  --stdin                      read stdin with other files or urls.
  -o, --out <file>             output d.ts filename.
  -n, --namespace <namespace>  use root namespace instead of definitions or components.schema from OpenAPI, or -n "" to suppress namespaces.
  -i, --intersection           output intersection types for `allOf` schema.
  -h, --help                   output usage information

  Examples:

    $ dtsintergen --help
    $ dtsintergen --out types.d.ts schema/**/*.schema.json
    $ dtsintergen -i --out types.d.ts schema/**/*.schema.json # <=== !!! enables intersection types !!!
    $ cat schema1.json | dtsintergen
    $ dtsintergen -o swaggerSchema.d.ts --url https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v2.0/schema.json
    $ dtsintergen -o petstore.d.ts -n PetStore --url https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v2.0/yaml/petstore.yaml

Advance Usage

For customize the output type name.

Install for library

npm install -S dtsgen-intersection

Usage for library

For example, it want to add the I prefix to the interface name. This is not usual example...

https://github.com/horiuchi/dtsgenerator/blob/master/example/add-prefix/index.ts

import dtsGenerator, { DefaultTypeNameConvertor, SchemaId } from 'dtsintergen';
import * as fs from 'fs';

const filePath = '../../test/snapshots/json-schema-draft-04/schema/schema.json';

function typeNameConvertor(id: SchemaId): string[] {
    const names = DefaultTypeNameConvertor(id);
    if (names.length > 0) {
        const lastIndex = names.length - 1;
        names[lastIndex] = 'I' + names[lastIndex];
    }
    return names;
}

async function main(): Promise<void> {
    const content = JSON.parse( fs.readFileSync(filePath, 'utf-8') );
    const result = await dtsGenerator({
        contents: [content],
        typeNameConvertor,
    });
    console.log(result);
}
main();

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

v2.3.1 (2019-09-02)

  • features:
    • Support the dynamic JSON media type #363. Thank you @buelsenfrucht :+1:
    • Add to support the number type enum values #365. Thank you @vincentlin02 :+1:

v2.3.0 (2019-08-23)

  • features:
    • Improve the tuple type output by TypeScript v3 syntax, and Support maxItems property #339. Thank you @keean :+1:

v2.2.0 (2019-08-06)

  • fixed
    • Fix: "_" character at the end of generated type #358. Thank you @KostblLb :+1:

v2.1.0 (2019-07-18)

  • features:
    • Add to support objected example #356. Thank you for reporting the issue #348 by @fantapop :+1:
    • Add to support the application/x-www-form-urlencoded branch on OpenAPI. #357

v2.0.8 (2019-06-25)

  • fixed
    • Fix: OneOf + type "object" produces empty interface #351. Thank you @polomani :+1:

v2.0.7 (2019-05-07)

  • fixed
    • Fix: typename when the path is nested #334. Thank you @steelydylan :+1:
    • Fix: Support ref objects for OAS3 requestBodies + responses #343. Thank you @anttiviljami :+1:

v2.0.6 (2019-02-14)

  • fixed
    • Fix "Error: The $ref target is not exists" on valid OpenAPI 3 spec #322. Thank you @f1cognite :+1:

v2.0.5 (2019-01-28)

  • features
    • Add to support the nullable property on OpenAPI by #319. Thank you @sakari :+1: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#data-types

v2.0.4 (2019-01-07)

  • fixed
    • Fix missing schema due to yaml references #318. Thank you @sakari :+1:

v2.0.1 (2018-12-21)

  • fixed
    • A property name cannot contain a "/" #315. Thank you @Reggino :+1:
    • update .npmignore

v2.0.0 (2018-10-22)

  • features
    • Add to support emit the Request/Response object schema of OpenAPI by #304.

older versions history

ChangeLogs

License

dtsgenerator is licensed under the MIT license.

Copyright © 2016-2019, Hiroki Horiuchi

dtsintergen is licensed under the MIT license.

Copyright © 2017-2019, Daphne Maddox