@harnessio/oats-cli

中文文档
4.0.0发布于 2025/04/18MITES Module近 30 天下载 12.7万

@harnessio/oats-cli

中文使用文档
文档目录5 节
  1. 安装
  2. 使用量
  3. 可用命令
  4. 导入
  5. 配置

国 际

@harnessio/oats-cli

用于将 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 文件进行配置 .

// 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 共发布 22 个版本,首次发布于 2022/10/20;过去 12 个月发布了 0 个版本。

版本发布日期距今
4.0.0latest2025/04/181.6 年前
4.0.0-beta.12025/04/171.6 年前
3.0.02024/12/131.9 年前
2.3.12024/10/152 年前
2.3.02023/11/222 年前
2.2.02023/11/173 年前

关于 @harnessio/oats-cli 的常见问题

如何安装 @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 和提交记录判断。