# @driimus/nx-plugin-openapi 中文文档

规范地址：https://npmcn.com/package/%40driimus/nx-plugin-openapi/

版本：3\.1\.5
npm 元数据更新时间：2026-10-27T09:36:08.871Z
中文译文更新时间：2026-11-12T20:04:55.845Z
软件包许可：MIT

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

原始 npm 页面：https://www.npmjs.com/package/%40driimus/nx-plugin-openapi
原文对照：https://npmcn.com/package/%40driimus/nx-plugin-openapi/?lang=original
项目主页：https://github.com/driimus/nx-plugins/blob/main/packages/nx-plugin-openapi#readme
源码仓库：https://github.com/driimus/nx-plugins

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

- 包体积（解压后）：57.9 kB，36 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：rimraf ^5\.0\.7，cross-spawn ^7\.0\.3，@nx/workspace \>= 20 \< 25
- 首次发布：2024-05-12T12:51:59.805Z
- 最新版本发布：2026-10-27T09:36:08.289Z
- 近 30 天下载量：18149（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：12（近 12 个月 2 个）

## 中文简介

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

## 安装

```sh
npm install @driimus/nx-plugin-openapi
```

也可以使用：`pnpm add @driimus/nx-plugin-openapi`、`yarn add @driimus/nx-plugin-openapi`、`bun add @driimus/nx-plugin-openapi`

## README

# Nx 的 OpenAPI 插件

[![NPM Version](https://img.shields.io/npm/v/%40driimus%2Fnx-plugin-openapi?style=flat)](https://npmjs.com/package/@driimus/nx-plugin-openapi) ![License](https://img.shields.io/npm/l/@driimus/nx-plugin-openapi)

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

## 这是什么?

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

## 如何安装

```sh
nx add @driimus/nx-plugin-openapi
```

### 先决条件

来源通过 [`openapi-generator-cli`](https://github.com/OpenAPITools/openapi-generator-cli),所以你需要Java 8或多克安装.

## 使用量

### 为 API spec 文件创建 lib

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

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

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

### 生成或更新来源

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

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

```sh
nx run api-fetch:generate-sources
```

## 发电机

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

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

## 鸣谢

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

-   [@vsavkin (英语)](https://github.com/vsavkin) 页:1 [@nrwl/反应](https://github.com/nrwl/nx/tree/master/packages/react)
-   [@ ericwooley (英语)](https://github.com/ericwooley) 页:1 [他自己的 @ ericwooley/ opanapi- sdk](https://github.com/ericwooley/openapi-sdk)
-   [@ tinesoft (英语)](https://github.com/tinesoft) 激励我使用 Nx 插件开发 以旋转, 发行他们的 [@nxrocks/nx-spring-boot (英语)](https://github.com/tinesoft/nxrocks)

## 常见问题

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

