接口文档神器--apiui的使用
程序员文章站
2022-06-28 13:33:52
接口开发,最麻烦的就是写文档了,曾经我也因为写接口文档苦不堪言;自从使用了apiui接口文档神器,工作效率和文档清晰得到了不止一个档次的提升。 下面介绍一下这个神器的使用: 把文件下载下来,放在网站根目录; 链接:https://pan.baidu.com/s/1DaT_rUANaSoHVhy8Bj ......
接口开发,最麻烦的就是写文档了,曾经我也因为写接口文档苦不堪言;自从使用了apiui接口文档神器,工作效率和文档清晰得到了不止一个档次的提升。
下面介绍一下这个神器的使用:
把文件下载下来,放在网站根目录;
链接:https://pan.baidu.com/s/1dat_ruanasohvhy8bjtqrw 密码:atgu
更改index.html文件的三个参数;
然后打开api.json文件,添加对应的接口模块;
1 { 2 "apiversion":"0.2", 3 "swaggerversion":"1.1", 4 "apis":[ 5 { 6 "path":"/fellow.{format}", 7 "description":"会员详情" 8 }, 9 { 10 "path":"/red_packet.{format}", 11 "description":"红包" 12 } 13 14 ] 15 }
apis下面一组数据对应就是一个模块;
path参数是模块名,description参数是模块别名,一个模块对应api文件夹下的一个json文件;
然后就编辑api下面的json文件,
1 { 2 "apiversion":"0.2", 3 "swaggerversion":"1.1", 4 "resourcepath":"/", 5 "apis":[ 6 { 7 "path":"/fellow_info", 8 "operations":[ 9 { 10 "description":"", 11 "updatetime":"2018/4/12 22:17", 12 "httpmethod":"get", 13 "summary":"会员资料", 14 "apistatus":2, 15 "reviser":"完成", 16 "responseclass":"void", 17 "nickname":"test0", 18 "revisionhighlight":true, 19 "fielddesc":{ 20 "result@string":"请求返回的状态1成功0失败", 21 "message@string":"提示信息", 22 "data@string":"返回的数据", 23 "nickname@string":"昵称", 24 "sex@string":"性别", 25 "tel@string":"手机号", 26 "label@string":"标签", 27 "remark@string":"备注", 28 "industry@string":"行业", 29 "company@string":"所在公司", 30 "position@string":"职位", 31 "region@string":"地区", 32 "email@string":"邮箱", 33 "qq_account@string":"qq号", 34 "wx_account@string":"微信号", 35 "identity@string":"身份" 36 37 }, 38 "parameters":[ 39 40 { 41 "description":"用户id", 42 "paramtype":"body", 43 "required":true, 44 "allowmultiple":false, 45 "datatype":"uid" 46 } 47 ] 48 } 49 ] 50 }, 51 { 52 "path":"/upd_fellow_info", 53 "operations":[ 54 { 55 "description":"", 56 "updatetime":"2018/4/12 22:17", 57 "httpmethod":"get", 58 "summary":"编辑会员资料", 59 "apistatus":2, 60 "reviser":"完成", 61 "responseclass":"void", 62 "nickname":"test1", 63 "revisionhighlight":true, 64 "fielddesc":{ 65 "result@string":"请求返回的状态1成功0失败", 66 "message@string":"提示信息", 67 "data@string":"返回的数据" 68 69 }, 70 "parameters":[ 71 72 { 73 "description":"用户id", 74 "paramtype":"body", 75 "required":true, 76 "allowmultiple":false, 77 "datatype":"uid", 78 "defaultvalue":"81" 79 }, 80 { 81 "description":"代理商id", 82 "paramtype":"body", 83 "required":true, 84 "allowmultiple":false, 85 "datatype":"aid", 86 "defaultvalue":"164" 87 }, 88 { 89 "description":"姓名", 90 "paramtype":"body", 91 "required":false, 92 "allowmultiple":false, 93 "datatype":"nickname", 94 "defaultvalue":"邓丽君" 95 }, 96 { 97 "description":"性别(填男,女,未知)", 98 "paramtype":"body", 99 "required":false, 100 "allowmultiple":false, 101 "datatype":"sex", 102 "defaultvalue":"女" 103 }, 104 { 105 "description":"手机号", 106 "paramtype":"body", 107 "required":false, 108 "allowmultiple":false, 109 "datatype":"tel", 110 "defaultvalue":"13800138000" 111 }, 112 { 113 "description":"标签,(传标签名,多个标签时候用,分开)", 114 "paramtype":"body", 115 "required":false, 116 "allowmultiple":false, 117 "datatype":"label", 118 "defaultvalue":"经理,2月生日" 119 }, 120 { 121 "description":"备注", 122 "paramtype":"body", 123 "required":false, 124 "allowmultiple":false, 125 "datatype":"remark", 126 "defaultvalue":"她是好人我是好人这是备注" 127 }, 128 { 129 "description":"行业(传行业id)", 130 "paramtype":"body", 131 "required":false, 132 "allowmultiple":false, 133 "datatype":"industry", 134 "defaultvalue":"4" 135 }, 136 { 137 "description":"公司", 138 "paramtype":"body", 139 "required":false, 140 "allowmultiple":false, 141 "datatype":"company", 142 "defaultvalue":"嘻哈唱片有限公司" 143 }, 144 { 145 "description":"职位", 146 "paramtype":"body", 147 "required":false, 148 "allowmultiple":false, 149 "datatype":"position", 150 "defaultvalue":"演员" 151 }, 152 { 153 "description":"地区", 154 "paramtype":"body", 155 "required":false, 156 "allowmultiple":false, 157 "datatype":"region", 158 "defaultvalue":"香港某条街" 159 }, 160 { 161 "description":"邮箱", 162 "paramtype":"body", 163 "required":false, 164 "allowmultiple":false, 165 "datatype":"email", 166 "defaultvalue":"6969888@qq.com" 167 }, 168 { 169 "description":"qq号", 170 "paramtype":"body", 171 "required":false, 172 "allowmultiple":false, 173 "datatype":"qq_account", 174 "defaultvalue":"6969888" 175 }, 176 { 177 "description":"微信号", 178 "paramtype":"body", 179 "required":false, 180 "allowmultiple":false, 181 "datatype":"wx_account", 182 "defaultvalue":"dlj_6969888" 183 } 184 185 ] 186 } 187 ] 188 } 189 190 191 192 ] 193 }
参数apis下面一组数据,就对应一个接口,对应的重要参数如下:
path:接口名,
updatetime:更新时间,
httpmethod:请求方式,
summary:接口功能解释,
nickname:接口别名(同一个模块不可以重名),
fielddesc:接口返回的数据,一行数据表示一个字段,举例:"result@string":"请求返回的状态1成功0失败",表示返回字段result 数据类型是string,字段说明是‘请求返回的状态1成功0失败’;
parameters:请求接口所需要的参数,一组数据表示一个参数,
description:字段说明,
required:字段是否必填,true是必填参数,false是选填参数
datatype:字段名称,
defaultvalue:参数的默认值,
大功告成:访问index.html文件;
请求一下接口:
希望对您有帮助,谢谢!