swagger-ui教程-构建api接口文档工具

  1. Swagger UI是一款RESTFUL接口的文档在线自动生成+功能测试功能软件。demo参见:http://petstore.swagger.wordnik.com/#!/pet
  2. 功能

    自动的在代码中分析REST接口,生成REST接口描述JSON。这个JSON又可以被客户端生成文档,以及测试用的WEB页。
    例如:

    • 我有这么一个接口:

      @RequestMapping(value="/{name}", method = RequestMethod.GET)
      @ResponseBody
      public Movie getMovie(@PathVariable String name) 
    • swagger加入以后,会自动生成这样的描述:

      {
          "apiVersion": "1.0",
          "swaggerVersion": "1.0",
          "basePath": "http://localhost:8080",
          "resourcePath": "/movie",
          "apis": [
              {
                  "path": "/movie/{name}",
                  "description": "",
                  "operations": [
                      {
                          "httpMethod": "GET",
                          "summary": "get Movie",
                          "notes": "",
                          "deprecated": false,
                          "responseClass": "Movie",
                          "nickname": "getMovie",
                          "parameters": [
                              {
                                  "name": "name",
                                  "description": "name",
                                  "notes": "",
                                  "paramType": "path",
                                  "defaultValue": "",
                                  "required": false,
                                  "allowMultiple": false,
                                  "dataType": "String"
                              }
                          ]
                      }
                  ]
              }
          ],
          "models": {
              "Movie": {
                  "properties": {
                      "name": {
                          "type": "string"
                      },
                      "year": {
                          "type": "string"
                      }
                  },
                  "type": "Movie"
              }
          }
      }
    • 然后swagger-ui作为纯HTML+JS的前端,读取上述描述后,可以产生这么一套网页: swagger-ui

  3. 有网友改造的swagger-ui的中文版了。

演示地址: 
swagger-ui中文版地址:http://helei112g.github.io/swagger-ui/

下载地址: https://github.com/helei112g/swagger-ui 

或者 data.json 可以参考:http://hi.haojima.net/SwaggerUI/#!/HomeAPI/GetJobBasicInfo_get_0

data.json 可以自动生成也可以手动在线编辑,官方地址:http://editor.swagger.io/#/    三方编辑地址:http://www.sosoapi.com/

个人使用说明:

1:下载  http://swagger.io/swagger-ui/

2: 找到 swagger-ui-master\dist\index 文件,文本编辑--找打【url = "http://petstore.swagger.io/v2/swagger.json"】 换成自己的json文件,格式参照官网要求

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值