@driimus/nx-plugin-openapi

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

NX Plugin for managing libraries generated from OpenAPI specs

原始使用文档
文档目录10 节
  1. 🧐 What is it?
  2. 💡 How to install
  3. Prerequisites
  4. 🧰 Usage
  5. Create a lib for an API spec file
  6. Create a lib for auto-generated docs
  7. Create a lib for auto-generated client sources
  8. Generate or update sources
  9. ✍️ Generators
  10. 🙏 Acknowledgements

OpenAPI Plugin for Nx

NPM Version License

Keep your API spec files in libs, and auto-generate sources and docs.

🧐 What is it?

It's a plugin for organizing OpenAPI spec files in libraries. You can then have other libraries for API SDKs, server stubs, or documentation, all auto-generated from the spec files.

💡 How to install

nx add @driimus/nx-plugin-openapi

Prerequisites

Sources get auto-generated via openapi-generator-cli, so you'll need Java 8 or Docker installed.

🧰 Usage

Create a lib for an API spec file

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

Create a lib for auto-generated docs

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

Create a lib for auto-generated client sources

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

Generate or update sources

Given the libs created in the examples above, then:

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

✍️ Generators

This OpenAPI plugin for Nx should support any generator you can use with openapi-generator-cli.

Find the ones you need, together with all the additional properties available for each generator, here: https://openapi-generator.tech/docs/generators

🙏 Acknowledgements

Many thanks to every project and every person I took inspiration from, but especially:

版本与发布记录

@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 是什么?

NX Plugin for managing libraries generated from OpenAPI specs

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