GithubHelp home page GithubHelp logo

linecode / dtsgenerator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from horiuchi/dtsgenerator

0.0 1.0 0.0 2.53 MB

TypeScript d.ts file generate from JSON Schema file

JavaScript 0.01% TypeScript 99.97% Shell 0.02%

dtsgenerator's Introduction

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

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

  • 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

ChangeLog

v3.13.0 (2021-08-31)

  • features:
    • Support new $schema types for #507.

v3.12.1 (2021-05-19)

  • fixed:
    • Fix referenced parameters not resolved error by #471. Thank you @jschirrmacher ๐Ÿ‘

v3.12.0 (2021-05-13)

  • features:
    • Support input type file by #496. Thank you @Christian24 ๐Ÿ‘
    • Improve the conversion results of parameters property on OpenAPI by #501.

v3.11.0 (2021-05-11)

  • features:
    • Support vendor media types (allow periods in application/*+json) by #497. Thank you @glen-84 ๐Ÿ‘
  • fixed:
    • Remove to support the readOnly property, because of wrong interpretation by #498. Thank you @hallsbyra ๐Ÿ‘

v3.10.0 (2021-04-26)

  • features:
    • Support freeform objects w/ index signature instead of unknown keyword by #488. Thank you @medfreeman ๐Ÿ‘
    • Support the content property in Parameters by #472. Thank you for report @npdev453 ๐Ÿ‘

v3.9.2 (2021-04-19)

  • fixed:
    • Fix nested oneOf & anyOf keywords by #486. Thank you @medfreeman ๐Ÿ‘

v3.9.1 (2021-04-16)

  • fixed:
    • Update generate function to use recommended immutable approach for typescript transforms by #483. Thank you again @medfreeman ๐Ÿ‘

v3.9.0 (2021-04-13)

  • features:
    • support for additionalItems property by #481. Thank you again @medfreeman ๐Ÿ‘

v3.8.0 (2021-04-08)

  • features:
    • full support for minItems & maxItems properties by #476. Thank you @medfreeman ๐Ÿ‘

v3.7.1 (2021-02-18)

  • fixed:
    • add truthy check for value in mergeSchema by #474. Thank you @ricokahler ๐Ÿ‘

v3.7.0 (2021-01-05)

  • features:
    • Add the void type support by #468. Thank you for your propose @henhal by #445 ๐Ÿ‘

v3.6.0 (2020-12-25)

  • features:
    • Improve the type result of oneOf/anyOf property by #467. Thank you for your report @crizo23 by #452 ๐Ÿ‘
    • Improve the internal eslint configuration by #466. Thank you @Goldziher ๐Ÿ‘

v3.5.0 (2020-12-21)

  • features:
    • Add to export ts object for to use the same version TypeScript in all plugins by #465.

v3.4.1 (2020-12-16)

  • fixed:
    • Fix using package without esModuleInterop setting on tsconfig by #460. Thank you @wszydlak ๐Ÿ‘
    • Update TypeScript v4 by #462. Thank you @wszydlak ๐Ÿ‘
    • Add to support the null type enum value by #464. Thank you for your report @Goldziher ๐Ÿ‘

v3.4.0 (2020-12-15)

  • features:
    • Add support for multipart media type by #455. Thank you @wszydlak ๐Ÿ‘
    • Add support for passing config object with NodeJS API usage by #456. Thank you @wszydlak ๐Ÿ‘

v3.3.1 (2020-10-05)

  • fixed:
    • Elements get type "any" instead of the correct one by #448. Thank you for your report @nachtigall-83 ๐Ÿ‘

v3.3.0 (2020-07-29)

  • features:
    • Support the patternProperties by #436. Thank you @nfroidure ๐Ÿ‘
  • fixed:
    • Definition generated improperly when multiple instances of a resource are inherited by #279. Thank you @btg5679 ๐Ÿ‘
    • 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 ๐Ÿ‘

v3.1.1 (2020-06-23)

  • fixed:
    • Cannot load config file of relative path by #428. Thank you @DamianOsipiuk ๐Ÿ‘

v3.1.0 (2020-06-22)

  • features:
    • Add support for nullable anyOf in OpenApi v3 by #426. Thank you @joost-kersjes-webpower ๐Ÿ‘

v3.0.3 (2020-06-15)

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

v3.0.2 (2020-06-11)

  • fixed:
    • Remove old example by #421. Thank you @maapteh ๐Ÿ‘

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

ChangeLogs

License

dtsgenerator is licensed under the MIT license.

Copyright ยฉ 2016-2020, Hiroki Horiuchi

dtsgenerator's People

Contributors

anttiviljami avatar brian-kavanagh avatar davidbiesack avatar dependabot[bot] avatar dmiorandi avatar gasi avatar glen-84 avatar gongt avatar greenkeeper[bot] avatar greenkeeperio-bot avatar heapx avatar horiuchi avatar jdthorpe avatar laurelnaiad avatar lupus92 avatar maapteh avatar medfreeman avatar nfroidure avatar philliphoff avatar polomani avatar qwerty2501 avatar ricokahler avatar sakari avatar silesky avatar skuligowski avatar steelydylan avatar vincentlin02 avatar wszydlak avatar zregvart avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.