swagger 服务搭建

初始环境

  • 大于 Node 6.x
  • 大于 NPM 3.x
  • 需要把以下两个包放部署在http服务下
    swagger-editor ( API 编辑 )
    swagger-ui ( API 查看 )

swagger-editor ( API 编辑 )

git clone https://github.com/swagger-api/swagger-editor.git
cd swagger-editor
npm install
npm run build
npm start
访问 编辑页面

http://localhost:8080/swagger-editor/index.html

swagger-ui ( API 查看 )

git clone https://github.com/swagger-api/swagger-ui.git
cd swagger-editor
npm install
npm run build
npm start
访问 查看页面

http://localhost:8080/swagger-ui/dist/index.html
默认会引用 http://petstore.swagger.io/v2/swagger.json 这个api,有两种可以修改默认访问的方法:

  • 直接修改 swagger-ui/dist/index.html 文件中的 url 的值
var swaggerUi = new SwaggerUi({
  url: 'http://petstore.swagger.io/v2/swagger.json', // url of specification
  dom_id: 'swagger-ui-container' //id of element where to render swagger-ui
});
swaggerUi.load();
原文地址:https://www.cnblogs.com/skating/p/7865784.html