使用 widdershins + pandoc 通过 GitHub Actions 将 OpenAPI 规范转换为 PDF 文档。
Convert OpenAPI specifications to PDF documentation using widdershins and pandoc via GitHub Actions.
- 🔄 自动转换 OpenAPI 规范为 PDF 文档 / Automatically convert OpenAPI specs to PDF
- 📁 支持多个 OpenAPI 文件 / Support multiple OpenAPI files
- ⚙️ 可配置的转换选项 / Configurable conversion options
- 📦 生成可下载的 artifact / Generate downloadable artifacts
- 🔧 可作为可重用的 GitHub Action / Reusable as a GitHub Action
-
添加 OpenAPI 文件: 将您的 OpenAPI 规范文件(
.yaml,.yml, 或.json)放入/api目录 -
配置转换选项:
widdershins.conf: Widdershins 转换配置pandoc.conf: Pandoc PDF 生成配置
-
触发转换: 推送代码或创建标签时,GitHub Actions 将自动运行转换流程
-
下载 PDF: 在 Actions 页面的 Artifacts 中下载生成的 PDF 文档
在您的工作流中使用此 Action:
name: Generate API Documentation
on:
push:
branches:
- main
jobs:
generate-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Convert OpenAPI to PDF
uses: Ellean/openapi-pdf-action@main
with:
api-dir: 'api'
widdershins-config: 'widdershins.conf'
pandoc-config: 'pandoc.conf'
output-file: 'api-documentation.pdf'
- name: Upload PDF
uses: actions/upload-artifact@v4
with:
name: api-docs
path: output/*.pdfwiddershins.conf 文件控制 OpenAPI 到 Markdown 的转换选项:
{
"language_tabs": [
{ "shell": "Shell" },
{ "javascript": "JavaScript" },
{ "python": "Python" }
],
"codeSamples": true,
"theme": "darkula",
"search": true
}pandoc.conf 文件控制 Markdown 到 PDF 的转换选项:
{
"pdf-engine": "xelatex",
"variable": [
"geometry:margin=1in",
"documentclass:article",
"fontsize:11pt"
],
"table-of-contents": true,
"toc-depth": 3,
"number-sections": true,
"highlight-style": "tango"
}| 参数 / Input | 描述 / Description | 必需 / Required | 默认值 / Default |
|---|---|---|---|
api-dir |
OpenAPI 文件目录 / Directory with OpenAPI files | No | api |
widdershins-config |
Widdershins 配置文件 / Widdershins config file | No | widdershins.conf |
pandoc-config |
Pandoc 配置文件 / Pandoc config file | No | pandoc.conf |
output-file |
输出 PDF 文件名 / Output PDF filename | No | api-documentation.pdf |
| 输出 / Output | 描述 / Description |
|---|---|
pdf-path |
生成的 PDF 文件路径 / Path to generated PDF |
.
├── api/ # OpenAPI 规范文件 / OpenAPI specification files
│ └── example.yaml
├── widdershins.conf # Widdershins 配置 / Widdershins configuration
├── pandoc.conf # Pandoc 配置 / Pandoc configuration
├── .github/
│ └── workflows/
│ └── convert.yml # 转换工作流 / Conversion workflow
└── action.yml # Action 定义 / Action definition