首页 > 解决方案 > Github Actions - 比较并找出两个 OAS V3 文件之间的差异

问题描述

假设您有两个 OpenApi Specification (OAS) V3 文件:

我想找到一个可以生成人类可读报告的 CLI 工具
(例如,我可以使用PR Comment from File 将其上传到 PR 评论中)

我的要求如下:

目前我在网上找到了这些项目:
- openapi-diff
- quen2404/openapi-diff
- Azure/openapi-diff
- ...

(其他无疑存在:我留给你找一些/或帮我挑选一个足够好的......)

这是帮助您启动的 Github 工作流程的开始:

name: API Breaking Changes
# Everyone is happy with breaking changes ^^
on:
  pull_request:

jobs:
  build-report:
    needs: build-oas-artefacts
    runs-on: ubuntu-latest
    steps:
      - name: Download OAS file from SOURCE branch
        uses: actions/download-artifact@v1
        with:
          name: original-spec.yaml
      - name: Download OAS file from TARGET branch
        uses: actions/download-artifact@v1
        with:
          name: modified-spec.yaml

谢谢您的帮助

标签: automationdiffopenapigithub-actionshuman-readable

解决方案


我刚刚在 golang 中编写了这个 OAS diff 工具:https ://github.com/Tufin/oasdiff

它像这样输出json:

{
 "spec": {
  "paths": {
   "modified": {
    "/": {
     "operations": {
      "modified": {
       "POST": {
        "servers": {
         "added": [
          "https://app.amberflo.io/ingest-endpoint"
         ],
         "deleted": [
          "https://app.amberflo.io/ingest"
         ]
        }
       }
      }
     },
     "servers": {
      "added": [
       "https://app.amberflo.io/ingest-endpoint"
      ],
      "deleted": [
       "https://app.amberflo.io/ingest"
      ]
     }
    }
   }
  },
  "servers": {
   "added": [
    "https://app.amberflo.io/ingest-endpoint"
   ],
   "deleted": [
    "https://app.amberflo.io/ingest"
   ]
  }
 },
 "summary": {
  "diff": true,
  "components": {
   "paths": {
    "modified": 1
   },
   "servers": {
    "added": 1,
    "deleted": 1
   }
  }
 }
}

推荐阅读