dtsgenerator 变相器
TypeScript d.ts 文件生成器来自 JSON Schema 文件或 OpenAPI (Swagger) spec文件.
目录
安装
npm install -g dtsgenerator
使用量
国 际
$ 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
关于配置文件,请参见 配置( s) 目录.
节点JS 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 */
});
使用 HTTP/ HTTPS 代理服务器
如果您需要代理来获取方案, 请设置以下环境变量 .
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
从v2迁移
Dtsgenerator v3 已经从 v2 中做了以下断开更改 .
- 支持插件特性 。 详见"插入"一节.
- 更改命令行选项 .
- 删除
--namespace选项。 使用@dtsgenerator/replace-namespace换成插头. - 添加数据
--config选项。 主要用于设置"插管". - 并增加更多选项.
- 删除
- TypeScript AST现在内部用于生成类型定义.
插头
如何找到插头
- 由 npm 搜索 : https://www.npmjs.com/search?q=dtsgenerator%20plugin 互联网档案馆的存檔,存档日期2013-12-12
- 由 @dtsgenerator 仓库查找 : https://github.com/dtsgenerator (中文(简体) )
@dtsgenerator/replace-namespace: 这个插件是--namespace选项.@dtsgenerator/decorate-typename:这个插件可以装饰输出类型名称.@dtsgenerator/single-quote:此插件将引号替换为单个.
如何创建插件
- 指挥部的脚手架:
npm init @dtsgenerator **plugin-name**
- 编辑
**plugin-name**/index.ts - 进行测试 :
npm test
- 构建它:
npm run build
- 发布到 npm :
npm publish
发展
调试
输出调试消息 调试 图书馆.
DEBUG=dtsgen dtsgen schema/news.json
关于JSON Schema和斯瓦格的链接
支持的规格和特性
-
杰森·斯克马
- 草案04及之前
- 草案07及之前
-
打开API
- OpenAPI 规格版本 2. 0
- OpenAPI 规格版本 3. 0
更改日志
第3.19.1号决定 (2023-08-25) (中文(简体) )
- 特性 :
- 更新新类型脚本 AST 的插件 .
- 被支持的Node.js版本更改为16或更后. 此外,我们确认它与Node.js v20.
v3.18.0 (韩语) (2023-03-02) (中文(中国大陆) )
- 特性 :
- 支持 # 551 的参数介质类型“ 应用程序/ json ” 。 谢谢@denizkenan:+1:
页:1 (2023-02-21) (中文(简体) )
- 特性 :
- 当出错发生于#549时返回出站码 1. 谢谢
页:1 (2022-12-20) (中文(简体) )
- 已固定 :
- 修复去除已贬值的547号装饰器参数. 谢谢@mcollina:+1:
页:1 (2022-06-10) (中文(简体) )
- 特性 :
- 支持# 539 的“ 图像/ * ” 介质类型 。 谢谢 @Geloosa:+1:
旧版本历史
许可证
dtsgenerator 根据麻省理工学院的许可.
版权所有 2016-2020, 贺柳奇弘树