You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅为OpenAPI Components Schemas文件生成HTML文档?

仅为OpenAPI Schema生成HTML文档的工具方案

当前文件结构:

├── code samples
│   └── C#
│       └── postundefined
│   └── PHP
│       └── postundefined
├── components
│   └── headers
│       └── ExpiresAfter.yaml
│   └── responses
│       └── Problem.yaml
│   └── schemas
│       └── Email.yaml
│       └── Problem.yaml
│       └── Schema.yaml
│       └── User.yaml
├── paths
│       └── echo.yaml
│       └── pathItem.yaml
│       └── pathItemWithExamples.yaml
│       └── users@{username}.yaml
└── openapi.yaml

我需要只给components/schemas/下的Email.yaml、User.yaml、Schema.yaml这些Schema文件生成HTML文档,用Redocly的redocly build-docs openapi.yaml命令只能生成包含REST端点的文档,没有Schema相关内容,请问有可用工具实现需求吗?


可行解决方案

1. 用Redocly自定义生成(最贴合现有工具链)

不用换工具,直接创建一个仅包含目标Schema的临时OpenAPI配置文件,比如命名为schema-only.yaml,内容如下:

openapi: 3.0.3
info:
  title: 专属Schema文档
  version: 1.0.0
components:
  schemas:
    Email:
      $ref: './components/schemas/Email.yaml'
    User:
      $ref: './components/schemas/User.yaml'
    Schema:
      $ref: './components/schemas/Schema.yaml'

然后执行命令:

redocly build-docs schema-only.yaml -o schema-docs.html

生成的schema-docs.html就只会展示你指定的三个Schema的详细结构、字段说明等内容。

2. 使用Spectacle工具

这是一款轻量的OpenAPI文档渲染工具,同样支持基于上述临时文件生成纯Schema文档:

  • 先全局安装:
npm install -g spectacle-docs
  • 执行生成命令:
spectacle schema-only.yaml -t schema-docs.html

3. 借助Swagger UI

Swagger UI也能展示单独的Schema内容:

  • 复用上面的schema-only.yaml文件;
  • 如果本地部署Swagger UI,修改其index.html里的url参数指向这个临时文件,之后打包静态资源就能得到纯Schema的HTML文档;
  • 也可以用Swagger UI在线编辑器加载该文件,然后导出HTML版本。

内容的提问来源于stack exchange,提问作者BhanuKiran

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 23:25:56