# @anttiviljami/dtsgenerator 中文文档

规范地址：https://npmcn.com/package/%40anttiviljami/dtsgenerator/

版本：3\.20\.0
npm 元数据更新时间：2024-06-12T09:31:43.765Z
中文译文更新时间：2026-11-06T07:13:28.275Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40anttiviljami/dtsgenerator
原文对照：https://npmcn.com/package/%40anttiviljami/dtsgenerator/?lang=original
项目主页：https://github.com/horiuchi/dtsgenerator
源码仓库：https://github.com/horiuchi/dtsgenerator

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：383 kB，73 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>= 18\.0
- 运行依赖：9 个
- 首次发布：2019-05-05T10:25:42.022Z
- 最新版本发布：2024-06-12T09:31:43.601Z
- 近 30 天下载量：228501（2026-10-06 至 2026-11-04，npm 官方下载统计）
- 已发布版本数：11（近 12 个月 0 个）

## 中文简介

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

## 安装

```sh
npm install @anttiviljami/dtsgenerator
```

也可以使用：`pnpm add @anttiviljami/dtsgenerator`、`yarn add @anttiviljami/dtsgenerator`、`bun add @anttiviljami/dtsgenerator`

## README

# dtsgenerator 变相器

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

[![nodejs version](https://img.shields.io/node/v/dtsgenerator.svg)](https://npmcn.com/package/%40anttiviljami/dtsgenerator/#) [![npm version](https://badge.fury.io/js/dtsgenerator.svg)](https://www.npmjs.com/package/dtsgenerator) [![Build Status](https://github.com/horiuchi/dtsgenerator/actions/workflows/workflow-ci.yaml/badge.svg)](https://github.com/horiuchi/dtsgenerator/actions/workflows/workflow-ci.yaml) [![Coverage Status](https://coveralls.io/repos/github/horiuchi/dtsgenerator/badge.svg?branch=master)](https://coveralls.io/github/horiuchi/dtsgenerator?branch=master) [![npm download count](https://img.shields.io/npm/dt/dtsgenerator.svg)](https://www.npmjs.com/package/dtsgenerator) [![Stake to support us](https://badge.devprotocol.xyz/0x68c824db5A1634940BB838468Ff2aee2bDa5794B/descriptive)](https://stakes.social/0x68c824db5A1634940BB838468Ff2aee2bDa5794B) [![MIT license](https://img.shields.io/npm/l/dtsgenerator.svg)](https://npmcn.com/package/%40anttiviljami/dtsgenerator/#)

## 目录

-   [安装](https://npmcn.com/package/%40anttiviljami/dtsgenerator/#readme-install)
-   [使用量](https://npmcn.com/package/%40anttiviljami/dtsgenerator/#readme-usage)
-   [从v2迁移](https://npmcn.com/package/%40anttiviljami/dtsgenerator/#readme-migration-from-v2)
-   [插头](https://npmcn.com/package/%40anttiviljami/dtsgenerator/#readme-plug-in)
-   [发展](https://npmcn.com/package/%40anttiviljami/dtsgenerator/#readme-development)
-   [更改日志](https://npmcn.com/package/%40anttiviljami/dtsgenerator/#readme-changelog)
-   [许可证](https://npmcn.com/package/%40anttiviljami/dtsgenerator/#readme-license)

## 安装

```
npm install -g dtsgenerator
```

-   [释放](https://github.com/horiuchi/dtsgenerator/releases)

## 使用量

### 国 际

```sh
$ 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)](https://github.com/horiuchi/dtsgenerator/tree/master/config_sample/) 目录.

### 节点JS API

```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 */
});
```

### 使用 HTTP/ HTTPS 代理服务器

如果您需要代理来获取方案, 请设置以下环境变量 .

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

## 从v2迁移

Dtsgenerator v3 已经从 v2 中做了以下断开更改 .

-   支持插件特性 。 详见"插入"一节.
-   更改命令行选项 .
    -   删除 `--namespace` 选项。 使用 `@dtsgenerator/replace-namespace` 换成插头.
    -   添加数据 `--config` 选项。 主要用于设置"插管".
    -   并增加更多选项.
-   TypeScript AST现在内部用于生成类型定义.

## 插头

### 如何找到插头

-   由 npm 搜索 : [https://www.npmjs.com/search?q=dtsgenerator%20plugin 互联网档案馆的存檔,存档日期2013-12-12](https://www.npmjs.com/search?q=dtsgenerator%20plugin)
-   由 @dtsgenerator 仓库查找 : [https://github.com/dtsgenerator (中文(简体) )](https://github.com/dtsgenerator)
    -   `@dtsgenerator/replace-namespace` : 这个插件是 `--namespace` 选项.
    -   `@dtsgenerator/decorate-typename` :这个插件可以装饰输出类型名称.
    -   `@dtsgenerator/single-quote` :此插件将引号替换为单个.

### 如何创建插件

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

## 发展

### 调试

输出调试消息 [调试](https://www.npmjs.com/package/debug) 图书馆.

```
DEBUG=dtsgen dtsgen schema/news.json
```

### 关于JSON Schema和斯瓦格的链接

-   [JSON Schema的故乡](http://json-schema.org/)
-   [OpenAPI 规格](https://github.com/OAI/OpenAPI-Specification)

### 支持的规格和特性

-   杰森·斯克马
    
    -   草案04及之前
    -   草案07及之前
-   打开API
    
    -   OpenAPI 规格版本 2. 0
    -   OpenAPI 规格版本 3. 0
-   [这些光谱中支持的特性](https://github.com/horiuchi/dtsgenerator/blob/master/SupportedFeatures.md)
    

## 更改日志

### [第3.19.1号决定](https://github.com/horiuchi/dtsgenerator/releases/tag/v3.19.1) (2023-08-25) (中文(简体) )

-   特性 :
    -   更新新类型脚本 AST 的插件 .
    -   被支持的Node.js版本更改为16或更后. 此外,我们确认它与Node.js v20.

### [v3.18.0 (韩语)](https://github.com/horiuchi/dtsgenerator/releases/tag/v3.18.0) (2023-03-02) (中文(中国大陆) )

-   特性 :
    -   支持 # 551 的参数介质类型“ 应用程序/ json ” 。 谢谢@denizkenan:+1:

### [页:1](https://github.com/horiuchi/dtsgenerator/releases/tag/v3.17.0) (2023-02-21) (中文(简体) )

-   特性 :
    -   当出错发生于#549时返回出站码 1. 谢谢

### [页:1](https://github.com/horiuchi/dtsgenerator/releases/tag/v3.16.2) (2022-12-20) (中文(简体) )

-   已固定 :
    -   修复去除已贬值的547号装饰器参数. 谢谢@mcollina:+1:

### [页:1](https://github.com/horiuchi/dtsgenerator/releases/tag/v3.16.0) (2022-06-10) (中文(简体) )

-   特性 :
    -   支持# 539 的“ 图像/ \* ” 介质类型 。 谢谢 @Geloosa:+1:

### 旧版本历史

[更改日志](https://github.com/horiuchi/dtsgenerator/blob/master/CHANGELOG.md)

## 许可证

`dtsgenerator` 根据麻省理工学院的许可.

版权所有 2016-2020, [贺柳奇弘树](mailto:horiuchi.g@gmail.com)

## 常见问题

### @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 和提交记录判断。

