@diplodoc/openapi-extension

中文文档
5.3.2发布于 2026/11/11TypeScriptCommonJS构建来源已验证近 30 天下载 2522

OpenAPI extension for Diplodoc transformer and builder

原始使用文档
文档目录9 节
  1. Features
  2. Installation
  3. Usage
  4. Transform plugin ( openapi-sandbox blocks)
  5. Includer (OpenAPI → Markdown)
  6. Runtime (browser UI)
  7. Development
  8. Documentation
  9. License

english | русский


NPM version Quality Gate Status Coverage Maintainability Rating Reliability Rating Security Rating

@diplodoc/openapi-extension

OpenAPI extension for the Diplodoc platform. Provides:

  • A MarkdownIt transform plugin for openapi-sandbox fenced blocks.
  • An includer that turns OpenAPI specs into a set of Markdown pages.
  • A browser runtime (React UI) to render the interactive OpenAPI sandbox.

Features

  • YFM syntax support
  • Schema rendering: oneOf / allOf, enums, cyclic references
  • Sandbox UI: interactive request/response UI rendered in browser
  • Includer pipeline: generates Markdown files from OpenAPI definitions

Installation

npm install @diplodoc/openapi-extension

Usage

Transform plugin (openapi-sandbox blocks)

Add the plugin to the transformer:

import transform from '@diplodoc/transform';
import {transform as openapiSandbox} from '@diplodoc/openapi-extension';

const markdown = `
\`\`\`openapi-sandbox
method: post
path: /test
server: http://localhost:8080
\`\`\`
`;

const {result} = await transform(markdown, {
  plugins: [openapiSandbox()],
});

The plugin converts openapi-sandbox fences into DOM nodes that the runtime can hydrate in browser.

Includer (OpenAPI → Markdown)

The includer entry point is exported as @diplodoc/openapi-extension/includer. It is used by the docs build pipeline to:

  • Validate OpenAPI specs
  • Resolve and normalize references
  • Generate Markdown pages for endpoints and schema sections

The sandbox option accepts host and customHost. YFM preset variables in host are resolved while the pages are generated. Set customHost: true to show a host input in each sandbox; its last submitted value is stored per project, specification revision and operation. Submitting an empty value restores the configured host.

sandbox:
  host: "{{apiHost}}"
  customHost: true

Preset variables in conditions

The noindex, filter, and hidden options accept Liquid expressions in their endpoint and tag fields. Endpoint or tag properties are available directly; preset variables are available under vars. Do not wrap these expressions in {{ }}.

# presets.yaml
default:
  noIndexOperations: [deletePet]
# toc.yaml
items:
  - name: API
    include:
      path: api
      mode: link
      includers:
        - name: openapi
          input: petstore.yaml
          noindex:
            endpoint: vars.noIndexOperations contains operationId

This generates the deletePet endpoint page with noIndex: true in its frontmatter; other endpoint pages remain indexable. The page is still generated and included in the TOC. A tag condition can use tag: vars.noIndexTags contains name instead. Matching tags also receive noIndex: true on their generated landing pages. An endpoint-only condition does not change indexing of its tag's landing page.

Variables are resolved for the TOC containing the include, using its directory and ancestor presets.yaml files, rather than the specification or generated output directory. --vars-preset selects a preset that overrides default within each file; closer preset files take precedence over ancestor files. --vars overrides preset values. Arrays, booleans, numbers, and nested objects are supported as well as strings. An empty noIndexOperations array matches no endpoints.

Programmatic callers of includer(run, params, tocPath) must initialize their variable service before invoking the includer. The CLI does this before processing TOCs.

For details about the processing stages, see:

  • adr/ADR-002-openapi-processing-pipeline.md

Runtime (browser UI)

The runtime is exported as @diplodoc/openapi-extension/runtime. It renders the interactive UI into .yfm-openapi-sandbox-js placeholders produced by the transform plugin.

Import runtime entry and styles in your bundle:

import '@diplodoc/openapi-extension/runtime';
import '@diplodoc/openapi-extension/runtime/styles';

Development

npm install
npm run typecheck
npm test
npm run lint
npm run build

Documentation

  • ADRs: adr/
  • Agent notes: AGENTS.md

License

See LICENSE.

版本与发布记录

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

版本发布日期距今
5.3.2latest2026/11/111 天前
5.3.12026/11/066 天前
5.3.02026/11/039 天前
5.2.72026/10/021 个月前
5.2.62026/09/301 个月前
5.2.52026/09/301 个月前

其他发布通道:beta → 2.0.0-beta.0。

关于 @diplodoc/openapi-extension 的常见问题

@diplodoc/openapi-extension 是什么?

OpenAPI extension for Diplodoc transformer and builder

如何安装 @diplodoc/openapi-extension?

在项目目录运行 npm install @diplodoc/openapi-extension,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0)、react-dom(^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0)、markdown-it(^13.0.0)、@gravity-ui/uikit(^7.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@diplodoc/openapi-extension 支持 TypeScript 吗?

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

@diplodoc/openapi-extension 支持 ESM 还是 CommonJS?

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

@diplodoc/openapi-extension 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@diplodoc/openapi-extension 可以商用吗?

@diplodoc/openapi-extension 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@diplodoc/openapi-extension 的下载量有多少?

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

@diplodoc/openapi-extension 还在维护吗?

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