如何在管道上生成API变化的报告?

发布于 2025-02-09 09:43:16 字数 472 浏览 1 评论 0原文

我已经使用 Swagger-diff

我可以使用makefile或脚本在本地计算机中自动化它,但是如果我想在gitlab管道中实现它,当有人在API端点上推动更改时,我该如何生成报告

java -jar bin/swagger-diff.jar -old https://url/v1/swagger.json -new https://url2/v2/swagger.json -v 2.0 -output-mode html > changes.html

请注意:所有项目代码也都被容器化。

I have manually generated the report of my API changes using swagger-diff

I can automate it in a local machine using makefile or script but what about if I wanted to implement it in the Gitlab pipeline, how can I generate the report in such a way when someone pushes the changes on the API endpoints

java -jar bin/swagger-diff.jar -old https://url/v1/swagger.json -new https://url2/v2/swagger.json -v 2.0 -output-mode html > changes.html

Note that: All the project code is also being containerized.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光是把杀猪刀 2025-02-16 09:43:16

在API路由发生更改时,在管道中配置作业以运行。将输出作为工件保存。如果您还需要发布的差异,则可以在该作业中进行发布,也可以创建依赖的作业,该作业使用工件将差异发布到GitLab页面或外部提供商。

如果您已经在本地自动化了该过程,则大多数工作已经在外壳脚本或类似内容中完成。

例子:
此示例假设您的API路由是在customer/api/autes/内部/api/code中定义的推到开发分支。

ApiDiff:
  stage: build
  image: java:<some-tag>
  script:
    - java -jar bin/swagger-diff.jar -old https://url/v1/swagger.json -new https://url2/v2/swagger.json -v 2.0 -output-mode html > changes.html
  artifacts:
    expire_in: 1 day
    name: api-diff
    when: on_success
    paths: changes.html
  rules:
    - if: "$CI_COMMIT_REF_NAME == 'dev'"
      changes:
        - customer/api/routes/*
        - internal/api/routes/*
    - when: never

然后,如果您想要的话,要发布差异的工作。这也可以在生成差异的同一工作中完成。

PublishDiff:
  stage: deploy
  needs: 
    - job: "ApiDiff"
      optional: false
      artifacts: true
  image: someimage:latest
  script:
    - <some script to publish the report>
  rules:
    - if: "$CI_COMMIT_REF_NAME == 'dev'"
      changes:
        - customer/api/routes/*
        - internal/api/routes/*
    - when: never

Configure a job in the pipeline to run when there are changes to your api routes. Save the output as an artifact. If you also need the diff published, you could either do the publishing in that job or create a dependent job which uses the artifact to publish the diff to a Gitlab page or external provider.

If you have automated the process locally, then most of the work is done already if it is in a shell script or something similar.

Example:
This example assumes that your api routes are defined in customer/api/routes/ and internal/api/routes and that you want to generate the diff when a commit or MR is pushed to the dev branch.

ApiDiff:
  stage: build
  image: java:<some-tag>
  script:
    - java -jar bin/swagger-diff.jar -old https://url/v1/swagger.json -new https://url2/v2/swagger.json -v 2.0 -output-mode html > changes.html
  artifacts:
    expire_in: 1 day
    name: api-diff
    when: on_success
    paths: changes.html
  rules:
    - if: "$CI_COMMIT_REF_NAME == 'dev'"
      changes:
        - customer/api/routes/*
        - internal/api/routes/*
    - when: never

And then the job to publish the diff if you want one. This could also be done in the same job that generates the diff.

PublishDiff:
  stage: deploy
  needs: 
    - job: "ApiDiff"
      optional: false
      artifacts: true
  image: someimage:latest
  script:
    - <some script to publish the report>
  rules:
    - if: "$CI_COMMIT_REF_NAME == 'dev'"
      changes:
        - customer/api/routes/*
        - internal/api/routes/*
    - when: never
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文