@anttiviljami/dtsgenerator

中文文档
3.20.0发布于 2024/06/12MITTypeScriptCommonJS近 30 天下载 22.9万

JSON Schema 文件的 TypeScript d.ts 文件生成器

中文使用文档
文档目录22 节
  1. 目录
  2. 安装
  3. 使用量
  4. 国 际
  5. 节点JS API
  6. 使用 HTTP/ HTTPS 代理服务器
  7. 从v2迁移
  8. 插头
  9. 如何找到插头
  10. 如何创建插件
  11. 发展
  12. 调试
  13. 关于JSON Schema和斯瓦格的链接
  14. 支持的规格和特性
  15. 更改日志
  16. 第3.19.1号决定 (2023-08-25) (中文(简体) )
  17. v3.18.0 (韩语) (2023-03-02) (中文(中国大陆) )
  18. 页:1 (2023-02-21) (中文(简体) )
  19. 页:1 (2022-12-20) (中文(简体) )
  20. 页:1 (2022-06-10) (中文(简体) )
  21. 旧版本历史
  22. 许可证

dtsgenerator 变相器

TypeScript d.ts 文件生成器来自 JSON Schema 文件或 OpenAPI (Swagger) spec文件.

nodejs version npm version Build Status Coverage Status npm download count Stake to support us MIT license

目录

安装

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现在内部用于生成类型定义.

插头

如何找到插头

如何创建插件

  1. 指挥部的脚手架:
    • npm init @dtsgenerator **plugin-name**
  2. 编辑 **plugin-name**/index.ts
  3. 进行测试 :
    • npm test
  4. 构建它:
    • npm run build
  5. 发布到 npm :
    • npm publish

发展

调试

输出调试消息 调试 图书馆.

DEBUG=dtsgen dtsgen schema/news.json

支持的规格和特性

更改日志

第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, 贺柳奇弘树

版本与发布记录

@anttiviljami/dtsgenerator 共发布 11 个版本,首次发布于 2019/05/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.20.0latest2024/06/122 年前
3.19.32024/01/272 年前
3.19.22024/01/272 年前
3.19.12023/11/092 年前
3.12.22021/11/074 年前
3.12.12021/11/074 年前

关于 @anttiviljami/dtsgenerator 的常见问题

@anttiviljami/dtsgenerator 是什么?

JSON Schema 文件的 TypeScript d.ts 文件生成器

如何安装 @anttiviljami/dtsgenerator?

在项目目录运行 npm install @anttiviljami/dtsgenerator,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 dtsgen,可以用 npx dtsgen 直接运行。

@anttiviljami/dtsgenerator 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@anttiviljami/dtsgenerator 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@anttiviljami/dtsgenerator 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >= 18.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@anttiviljami/dtsgenerator 可以商用吗?

@anttiviljami/dtsgenerator 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@anttiviljami/dtsgenerator 的下载量有多少?

根据 npm 官方下载统计,@anttiviljami/dtsgenerator 在 2026/10/06 – 2026/11/04 这 30 天内被下载 228,501 次,日均约 7,617 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@anttiviljami/dtsgenerator 还在维护吗?

最新版本 3.20.0 发布于 2024/06/12(2 年前);至今共发布 11 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/05/05。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。