TypeScript d.ts file generator for JSON Schema file
npm install dtsgeneratorTypeScript d.ts file generator from JSON Schema file or OpenAPI(Swagger) spec file.







- Install
- Usage
- Migration from v2
- Plug-in
- Development
- ChangeLog
- License
npm install -g dtsgenerator
- Releases
``sh
$ dtsgen --help
Usage: dtsgenerator [options]
Options:
-V, --version output the version number
-c, --config
--url
--stdin read stdin with other files or urls.
-o, --out
-t, --target
'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.
`js
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 /
});
`
If you need a proxy to fetch the schema, please set the following environment variables.
`bash`
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
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.--config
- Add the option. Mainly for setting up the Plug-in.
- And add more options.
- TypeScript AST is now used internally to generate type definitions.
- Search by npm:
- Find by the @dtsgenerator repositories:
- @dtsgenerator/replace-namespace : This plug-in is instead the --namespace option on old version.@dtsgenerator/decorate-typename
- : This plug-in can decorate the output type name.@dtsgenerator/single-quote
- : This plug-in replace the quote mark to single.
1. Scaffold by the command:
- npm init @dtsgenerator plugin-nameplugin-name/index.ts
1. Edit npm test
1. Do test:
- npm run build
1. Build it:
- npm publish
1. Publish to npm:
-
Output debug message by debug library.
DEBUG=dtsgen dtsgen schema/news.json
- The home of JSON Schema
- The OpenAPI Specification
- 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
- fixed:
- Support a negative number by #566. Thank you @maximebiloe :+1:
- 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.
- features:
- Support 'application/json' with parameter media type for #551. Thank you @denizkenan :+1:
- features:
- Return exit code 1 when error occurs by #549. Thank you @lhotamir :+1:
- fixed:
- Fix to remove deprecated decorators parameters for #547. Thank you @mcollina :+1:
- features:
- Support 'image/*' media types for #539. Thank you @Geloosa :+1:
dtsgenerator` is licensed under the MIT license.
Copyright © 2016-2020, Hiroki Horiuchi