- Swagger UI是一款RESTFUL接口的文档在线自动生成+功能测试功能软件。demo参见:http://petstore.swagger.wordnik.com/#!/pet
-
功能
自动的在代码中分析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的中文版了。
演示地址:
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文件,格式参照官网要求