@driimus/nx-plugin-openapi

中文文档
3.1.5发布于 2026/10/27MITTypeScriptCommonJS构建来源已验证近 30 天下载 1.8万

用于管理 OpenAPI 光谱生成的库的 NX 插件

中文使用文档
文档目录10 节
  1. 这是什么?
  2. 如何安装
  3. 先决条件
  4. 使用量
  5. 为 API spec 文件创建 lib
  6. 为自动生成的文档创建 lib
  7. 为自动生成的客户端源创建 lib
  8. 生成或更新来源
  9. 发电机
  10. 鸣谢

Nx 的 OpenAPI 插件

NPM Version License

将您的 API 光谱文件保存在 libs 中,以及自动生成源和文档中 .

这是什么?

它是用于在库中组织OpenAPI spec文件的插件. 然后,您可以拥有其它用于API SDK的库,服务器根,或者文档,所有自定义文件自动生成的.

如何安装

nx add @driimus/nx-plugin-openapi

先决条件

来源通过 openapi-generator-cli,所以你需要Java 8或多克安装.

使用量

为 API spec 文件创建 lib

nx generate @driimus/nx-plugin-openapi:api-spec
✔ What name would you like to use? · api-spec
✔ Do you want me to also create a sample spec file for you? (y/N) · true
UPDATE package.json
UPDATE workspace.json
UPDATE nx.json
CREATE libs/my-service-api-spec/src/my-service-api-spec.openapi.yml

为自动生成的文档创建 lib

nx generate @driimus/nx-plugin-openapi:api-lib
✔ What name would you like to use? · api-docs
✔ Which OpenAPITool generator would you like to use? (https://github.com/OpenAPITools/openapi-generator) · html
✔ Is the API spec file published online? (y/N) · false
✔ If it's online, what's the URL where I can get the API spec file from? ·
✔ If it's online, which authorization headers do you need to add? ·
✔ If it's local, what's the name of the lib containing the API spec file? · api-spec
✔ If it's local, what's the path of the API spec file starting from the lib root? · src/api-spec.openapi.yml
✔ Do you want to specify any additional properties for the generator? key1=value1,key2=value2 (https://openapi-generator.tech/docs/generators) ·
✔ Do you want to specify any global properties for the generator? key1=value1,key2=value2 (https://openapi-generator.tech/docs/globals) ·

UPDATE workspace.json
UPDATE nx.json
CREATE libs/api-docs/README.md
UPDATE tsconfig.base.json

为自动生成的客户端源创建 lib

nx generate @driimus/nx-plugin-openapi:api-lib
✔ What name would you like to use? · api-fetch
✔ Which OpenAPITool generator would you like to use? (https://github.com/OpenAPITools/openapi-generator) · typescript-fetch

✔ Is the API spec file published online? (y/N) · false
✔ If it's online, what's the URL where I can get the API spec file from? ·
✔ If it's online, which authorization headers do you need to add? ·
✔ If it's local, what's the name of the lib containing the API spec file? · api-spec
✔ If it's local, what's the path of the API spec file starting from the lib root? · src/api-spec.openapi.yml
✔ Do you want to specify any additional properties for the generator? key1=value1,key2=value2 (https://openapi-generator.tech/docs/generators) · typescriptThreePlus=true,supportsES6=true
✔ Do you want to specify any global properties for the generator? key1=value1,key2=value2 (https://openapi-generator.tech/docs/globals) ·

UPDATE workspace.json
UPDATE nx.json
CREATE libs/api-fetch/README.md
UPDATE tsconfig.base.json

生成或更新来源

鉴于以上例子中产生的自由

nx run api-docs:generate-sources

# Then you can simply serve it
npx http-server libs/api-docs/src

# Or you can configure a Nx serve target for it, or do whatever you want
nx run api-fetch:generate-sources

发电机

Nx 的 OpenAPI 插件应该支持您可以使用的任何生成器 openapi-generator-cli。 。 。 .

查找您需要的, 以及每个生成器可用的所有附加属性 : https://openapi-generator.tech/docs/generators 页面存档备份,存于互联网档案馆

鸣谢

多亏了每一个项目 和每一个我从中得到灵感的人,但特别:

版本与发布记录

@driimus/nx-plugin-openapi 共发布 12 个版本,首次发布于 2024/05/12;过去 12 个月发布了 2 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.1.5latest2026/10/2717 天前
3.1.42026/06/174 个月前
3.1.22025/10/241.1 年前
3.1.12025/06/031.4 年前
3.1.02025/03/141.7 年前
3.0.12024/12/021.9 年前

关于 @driimus/nx-plugin-openapi 的常见问题

@driimus/nx-plugin-openapi 是什么?

用于管理 OpenAPI 光谱生成的库的 NX 插件

如何安装 @driimus/nx-plugin-openapi?

在项目目录运行 npm install @driimus/nx-plugin-openapi,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:rimraf(^5.0.7)、cross-spawn(^7.0.3)、@nx/workspace(>= 20 < 25)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@driimus/nx-plugin-openapi 支持 TypeScript 吗?

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

@driimus/nx-plugin-openapi 支持 ESM 还是 CommonJS?

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

@driimus/nx-plugin-openapi 可以商用吗?

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

@driimus/nx-plugin-openapi 的下载量有多少?

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

@driimus/nx-plugin-openapi 还在维护吗?

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