automation - Github Actions - 比较并找出两个 OAS V3 文件之间的差异
问题描述
假设您有两个 OpenApi Specification (OAS) V3 文件:
- original-spec.yaml :原始规范
- modified-spec.yaml :修改后的(带有增强/重大更改/等)
(两个文件的示例可在https://gist.github.com/jy95/d7b53648eb756547eb67fd0db962f68d上找到)
我想找到一个可以生成人类可读报告的 CLI 工具
(例如,我可以使用PR Comment from File
将其上传到 PR 评论中)
我的要求如下:
- 没有技术限制
(您可以自由使用任何编程语言库,只要它有效,包括在需要时使用 OAS 到 Swagger v2 转换器) - 人类可读/可理解
(应该清楚,以免不了解 OAS 的人迷路) - 维护(不是强制性的,但更好)
目前我在网上找到了这些项目:
- 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
谢谢您的帮助
解决方案
我刚刚在 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
}
}
}
}
推荐阅读
- python - 从整个数据集中绘制特定月份?
- windows - Gradle 不会运行我想要的 shell 命令行
- android - FrameLayout 未正确约束。它的底部隐藏在 BottomNavigationView
- javascript - 在 Svelte 中使用 Await 进行转换
- vue.js - 是特殊属性 vs v-if / v-show
- c# - 如何将 TreeViewItem 中文本框的最大宽度调整到容器的边缘
- javascript - 如何使用 HTML 和 CSS 修复图像上的覆盖
- angularjs - Apollo Angular Graphql,如何使用多个端点?
- algorithm - Pramp - 奖励预算削减解决方案
- spring - ReactiveSpringSecurity 角色映射