# @harnessio/oats-cli 中文文档

规范地址：https://npmcn.com/package/%40harnessio/oats-cli/

版本：4\.0\.0
npm 元数据更新时间：2026-11-16T17:37:09.148Z
中文译文更新时间：2026-11-17T10:14:29.948Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40harnessio/oats-cli
原文对照：https://npmcn.com/package/%40harnessio/oats-cli/?lang=original
项目主页：https://github.com/harness/oats#readme
源码仓库：https://github.com/harness/oats

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

- 包体积（解压后）：119 kB，69 个文件
- 模块格式：ES Module
- TypeScript 类型：未声明
- Node.js 要求：\>=16\.0\.0
- 运行依赖：13 个
- peer 依赖：typescript ^4\.0\.0
- 首次发布：2022-10-20T06:42:37.449Z
- 最新版本发布：2025-04-17T19:17:30.317Z
- 近 30 天下载量：126820（2026-10-18 至 2026-11-16，npm 官方下载统计）
- 已发布版本数：22（近 12 个月 0 个）

## 中文简介

![@harnessio/oats-cli](https://img.shields.io/npm/v/@harnessio/oats-cli.svg?style=flat-square)

## 安装

```sh
npm install @harnessio/oats-cli
```

也可以使用：`pnpm add @harnessio/oats-cli`、`yarn add @harnessio/oats-cli`、`bun add @harnessio/oats-cli`

## README

# 国 际

![@harnessio/oats-cli](https://img.shields.io/npm/v/@harnessio/oats-cli.svg?style=flat-square)

用于将 OpenAPI(原为 Swagger) 定义转换为 TypeScript 的命令行工具 .

## 安装

利用国家预防机制:

```
npm i -D @harnessio/oats-cli
```

使用 Yarn :

```
yarn add -D @harnessio/oats-cli
```

您可以使用 `npx` (与 `npm`) (中文(简体) ). 举个例子 `npx oats import --config oats.config.ts`。 。 。 .

## 使用量

```
Usage: oats <cmd> [args]

Commands:
  oats import  Import OpenAPI specification and output TypeScript code

Options:
  --version  Show version number                                       [boolean]
  --help     Show help                                                 [boolean]

```

### 可用命令

### 导入

```
oats import

Import OpenAPI specification and output TypeScript code

Options:
      --version      Show version number                               [boolean]
      --help         Show help                                         [boolean]
      --file         Path to OpenAPI spec file. Can be either a JSON or YAML fil
                     e.                                                 [string]
      --url          URL to remote OpenAPI spec file.                   [string]
  -o, --output       Location for the output.                           [string]
  -c, --config       Location for the config file.
                                            [string] [default: "oats.config.ts"]
      --clean        Remove the output directory before generating service.
                                                      [boolean] [default: false]
      --service      Pick the services to generate from a config file. All the s
                     ervices will generated by default.    [array] [default: []]
      --genOnlyUsed  By default, all types defined in spec are generated. Pass
                     this flag to, only generate types, which are referenced in
                     paths.
                                                      [boolean] [default: false]
      --verbose      Shows verbose output                              [boolean]
```

## 配置

配置也可以使用配置文件向cli提供. 默认情况下, cli 将寻找 `oats.config.ts` 当前目录中的文件。 这可以改变 使用 `--config` 旗帜。 建议使用 TypeScript 文件进行配置 .

```ts
// oats.config.ts
import { defineConfig } from '@harnessio/oats-cli/config';

export default defineConfig({
  /**
   * The plugins defined here will be used for all the services.
   * You can also override the plugins at individual service level.
   */
  plugins: [],
  /**
   * Config for the services to generated.
   * Its a map of string and config
   */
  services: {
    // Name for the service.
    // You can use this name to pick a service while using the --service flag
    myservice: {
      /**
       * Path where the output should be written to.
       * This is a required field.
       */
      output: './path/to/output/folder',
      /**
       * Path from where the OpenAPI spec is to be read.
       * Either path or url must be defined.
       */
      file: string,
      /**
       * URL from where the OpenAPI spec is to be read.
       * Either path or url must be defined.
       */
      url: string,
      /**
       * By default, all types defined in spec are generated.
       * Pass this flag, to only generate types, which are referenced in paths.
       */
      genOnlyUsed: boolean,
      /**
       * A function, which can be used to pre-process the imported spec.
       *
       * The function will receive the spec as an argument and it needs to
       * return the spec after the processing.
       */
      transformer: (spec) => spec;
      /**
       * Plugins to be overriden for this particular service.
       * The plugins will be replaced and not merged.
       */
      plugins: Plugin[];
    },
  },
});
```

# 许可证

麻省理工学院.

## 常见问题

### 如何安装 @harnessio/oats-cli？

在项目目录运行 npm install @harnessio/oats-cli，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：typescript（^4\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。它还提供命令行工具 oats，可以用 npx oats 直接运行。

### @harnessio/oats-cli 支持 TypeScript 吗？

该包的 package\.json 没有声明类型入口。需要类型提示时，可以在 npm 上查找社区维护的 @types/harnessio\_\_oats-cli 是否存在。

### @harnessio/oats-cli 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @harnessio/oats-cli 需要什么版本的 Node\.js？

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

### @harnessio/oats-cli 可以商用吗？

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

### @harnessio/oats-cli 的下载量有多少？

根据 npm 官方下载统计，@harnessio/oats-cli 在 2026/10/18 – 2026/11/16 这 30 天内被下载 126,820 次，日均约 4,227 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @harnessio/oats-cli 还在维护吗？

最新版本 4\.0\.0 发布于 2025/04/18（1\.6 年前）；至今共发布 22 个版本，其中过去 12 个月发布了 0 个；首次发布于 2022/10/20。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

