"swagger接口服务是我本机,如果我下班关机回家,对方如何进行联调?"
如果你有类似的疑问,这个项目可以帮助你。
出于稳定性考虑,在提测前不允许发布到测试环境,开发阶段如何保障swagger接口的稳定性?
- 搭建swagger-ui服务
- 接口owner将swagger json文件上传至静态目录发布。swagger-ui内部包含nginx服务。
在安装了docker的机器,通过run.sh
可以执行镜像build及容器运行。
Dockerfile
from swaggerapi/swagger-ui
ENV API_URL=http://localhost:8080/demo_api_1.json
#ENV API_URLS="[{url: 'demo_api_1.json', name : '接口一'}, {url: 'demo_api_2.json', name : '接口二'}]"
COPY ./api/*.json /usr/share/nginx/html/
static目录下是接口json文件 通过 http://localhost:8080/v2/api-docs 获取json文件,命名后push到git项目api目录下
浏览器访问swagger-ui服务,并在窗口输入json文件访问路径 https://localhost:8080/demo_api_2.json ,然后就可以看到swagger接口定义。
- 不能根据代码动态更新,需要owner手动push接口json文件。
- 需要手动输入json访问url。
- 无法执行try it out
关于缺陷2可以考虑使用API_URLS
环境变量实现,但是设置后,不能自定义输入jsonUrl
from swaggerapi/swagger-ui
ENV API_URLS="[{url: 'http://localhost:8080/demo_api_1.json', name : '接口一'}, {url: 'http://localhost:8080/demo_api_2.json', name : '接口二'}]"
COPY ./api/*.json /usr/share/nginx/html/
效果图如下