@elysiajs/openapi

中文文档
1.4.17发布于 2026/11/04MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 206万

Elysia plugin to add OpenAPI documentation

原始使用文档
文档目录16 节
  1. Installation
  2. Example
  3. enabled
  4. openapiVersion
  5. documentation
  6. exclude
  7. exclude.methods
  8. exclude.paths
  9. exclude.staticFile
  10. exclude.tags
  11. path
  12. provider
  13. references
  14. scalar
  15. specPath
  16. swagger

@elysia/openapi

Elysia plugin to add OpenAPI documentation.

Installation

bun add @elysia/openapi

Example

import { Elysia, t } from 'elysia'
import { openapi } from '@elysia/openapi'

const app = new Elysia()
    .use(openapi())
    .get('/', () => 'hi', {
        response: t.String({ description: 'sample description' })
    })
    .post(
        '/json/:id',
        ({ body, params: { id }, query: { name } }) => ({
            ...body,
            id,
            name
        }),
        {
            params: t.Object({
                id: t.String()
            }),
            query: t.Object({
                name: t.String()
            }),
            body: t.Object({
                username: t.String(),
                password: t.String()
            }),
            response: t.Object(
                {
                    username: t.String(),
                    password: t.String(),
                    id: t.String(),
                    name: t.String()
                },
                { description: 'sample description' }
            )
        }
    )
    .listen(3000)

Then go to http://localhost:3000/openapi.

config

enabled

@default true Enable/Disable the plugin

openapiVersion

@default '3.1.2'

OpenAPI document version to emit. Supports OpenAPI 3.0.x and 3.1.x.

documentation

OpenAPI documentation information

@see https://spec.openapis.org/oas/latest.html

exclude

Configuration to exclude paths or methods from documentation

exclude.methods

List of methods to exclude from documentation

exclude.paths

List of paths to exclude from documentation

exclude.staticFile

@default true

Exclude static file routes from documentation

exclude.tags

List of tags to exclude from documentation

path

@default '/openapi'

The endpoint to expose OpenAPI documentation frontend

provider

@default 'scalar'

OpenAPI documentation frontend between:

references

Additional OpenAPI reference for each endpoint

scalar

Scalar configuration, refers to Scalar config

specPath

@default '/${path}/json'

The endpoint to expose OpenAPI specification in JSON format

swagger

Swagger config, refers to Swagger config

See documentation for more details.

版本与发布记录

@elysiajs/openapi 共发布 33 个版本,首次发布于 2025/09/03;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.4.17latest2026/11/049 天前
1.4.162026/09/022 个月前
2.0.0-exp.0experimental2026/06/294 个月前
1.4.152026/04/246 个月前
1.4.142026/01/219 个月前
1.4.132025/12/2710 个月前

关于 @elysiajs/openapi 的常见问题

@elysiajs/openapi 是什么?

Elysia plugin to add OpenAPI documentation

如何安装 @elysiajs/openapi?

在项目目录运行 npm install @elysiajs/openapi,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:elysia(>= 1.4.0)、typescript(>= 5.0.0)、@sinclair/typebox(>= 0.34.0 < 1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@elysiajs/openapi 支持 TypeScript 吗?

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

@elysiajs/openapi 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@elysiajs/openapi 可以商用吗?

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

@elysiajs/openapi 的下载量有多少?

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

@elysiajs/openapi 还在维护吗?

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