@clementoh/better-openapi-viewer-ui

中文文档
0.1.8发布于 2026/05/12MITTypeScriptES Module近 30 天下载 5747

React UI for Better OpenAPI Viewer.

原始使用文档
文档目录4 节
  1. Discovery
  2. Try It Out
  3. Authorization
  4. Theme

@clementoh/better-openapi-viewer-ui

React UI for Better OpenAPI Viewer.

Discovery

The viewer renders accessible endpoint navigation with operation counts, text search, and filters for HTTP method, tag, auth requirement, deprecated status, and documented content types when those values are available from the normalized OpenAPI document. It also renders component schemas and Swagger definitions in a Models section using the core schema tree helpers.

Expanded operations show structured request body media types, schema property trees, documented examples, response status class labels, response descriptions, response content examples, external docs links, and callback/webhook summaries when present. Common Markdown-style description text is rendered safely as React text and elements without adding a Markdown dependency.

Try It Out

Expanded operations include a globally controllable, opt-in Try It Out panel. Users can choose a server, fill server variables, select a request content type, edit parameter values, use generated controls for JSON object request body fields, upload files for documented multipart/form-data binary fields, inspect and copy the generated URL, body, and snippet, send or cancel the request with fetch and AbortController, review response status, duration, headers, and body, copy the response body, and reset inputs back to documented examples/defaults.

Before sending, the UI reports missing required parameters, missing required request bodies or multipart fields, and invalid JSON request bodies.

The snippet selector currently exposes curl, backed by the core curl snippet generator.

Authorization

The viewer detects supported OpenAPI and Swagger security schemes from components.securitySchemes and securityDefinitions. A global Authorize panel lets users enter Basic auth, Bearer tokens, apiKey credentials for header, query, or cookie locations, and access-token style values for OAuth/OpenID schemes where the core request builder can apply bearer-style credentials. OAuth flows and OpenID Connect discovery URLs are displayed when documented. Credentials can be cleared per scheme or globally.

Pass persistAuthorization to store entered credentials for the current API document in localStorage.

Pass preauthorizedCredentials or config.preauthorizedCredentials to seed the Authorize panel, for example:

<BetterOpenApiViewer
  document={document}
  preauthorizedCredentials={{
    bearerAuth: 'token',
    basicAuth: { username: 'demo', password: 'secret' },
  }}
/>

Theme

The viewer includes accessible light and dark theme controls on the root UI and exposes the selected value with a data-theme attribute for host applications to style.

版本与发布记录

@clementoh/better-openapi-viewer-ui 共发布 8 个版本,首次发布于 2026/05/07;过去 12 个月发布了 8 个版本。

版本发布日期距今
0.1.8latest2026/05/125 个月前
0.1.72026/05/125 个月前
0.1.62026/05/076 个月前
0.1.52026/05/076 个月前
0.1.42026/05/076 个月前
0.1.32026/05/076 个月前

关于 @clementoh/better-openapi-viewer-ui 的常见问题

@clementoh/better-openapi-viewer-ui 是什么?

React UI for Better OpenAPI Viewer.

如何安装 @clementoh/better-openapi-viewer-ui?

在项目目录运行 npm install @clementoh/better-openapi-viewer-ui,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^19.2.6)、react-dom(^19.2.6)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@clementoh/better-openapi-viewer-ui 支持 TypeScript 吗?

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

@clementoh/better-openapi-viewer-ui 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@clementoh/better-openapi-viewer-ui 可以商用吗?

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

@clementoh/better-openapi-viewer-ui 的下载量有多少?

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

@clementoh/better-openapi-viewer-ui 还在维护吗?

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