Linux Swagger工具集成到CI/CD流程
一 总体思路与准备
二 在主流CI中的落地示例
Jenkins Pipeline(通用范式)
swagger-cli validate api/openapi.yaml(或 openapi-generator validate -i api/openapi.yaml)。java -jar openapi-generator-cli.jar generate -i api/openapi.yaml -g html2 -o dist/docs。docker run --rm -p 8080:8080 -v $PWD/api:/tmp swaggerapi/swagger-ui 并在构建日志中输出访问地址。dist/docs 通过 rsync/scp 或 Nginx 托管到目标路径。GitLab CI(.gitlab-ci.yml 片段)
build → test → contract → docs → deploy-docs。openapi.yaml 进行基于规范的自动化测试;schemathesis run api/openapi.yaml --base-url=$TEST_BASE_URL;openapi-generator generate -i api/openapi.yaml -g html2 -o public/docs;rsync 到 Nginx 目录或通过 Pages 发布(若使用 GitLab Pages)。三 与服务端框架的协同
curl http://localhost:8080/v3/api-docs > target/openapi.json。org.springdoc:springdoc-openapi-ui:1.6.14(版本可按需调整)。四 质量门禁与最佳实践
$ref)与 YAML/JSON 格式问题;