功能
自动的在代码中分析REST接口,生成REST接口描述JSON。这个JSON又可以被客户端生成文档,以及测试用的WEB页。
例如:我有这么一个接口:
@RequestMapping(value="/{name}", method = RequestMethod.GET)@ResponseBodypublic 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的前端,读取上述描述后,可以产生这么一套网页: