Prototype功能预览十一:集成Swagger生成API文档及API测试界面
框架整体介绍:http://blog.****.NET/flyxxxxx/article/category/7055640
对此框架有兴趣或想参与开发的请加QQ群:255195191
在开发接口中,经常需要编写API的文档,文档和代码不同步的问题很常见,客户端和后端对输入参数的验证也可能不一致。
Prototype提供一次编写接口,自动生成json格式文档,生成javascript验证数据,集成Swagger UI用于API功能测试。
以下是典型输入输出:
public class UserQuery extends Business{
@Input(@Prop(desc = "ID"))
private Integer id;
@Output(desc="用户信息",value={@Prop(desc="ID",name="id"),@Prop(desc="账号",name="loginId")})
private User user;
}
下图是集成Swagger之后的接口信息及测试界面:
下面是一个发送邮件的接口,生成的json格式的文档:
{ "path" : "/send", "description" : "发送邮件", "methods" : "POST", "version" : "1.0", "params" : [ { "name" : "sendTime", "required" : false, "minLength" : -1, "maxLength" : -1, "array" : false, "pattern" : "yyyy-MM-dd HH:mm:ss", "hint" : "指定一个时间发送", "type" : "Date", "description" : "发送时间" }, { "name" : "to", "required" : true, "minLength" : 5, "maxLength" : 400000, "array" : false, "hint" : "多个邮件地址以逗号分开", "type" : "String", "description" : "接收人地址" }, { "name" : "subject", "required" : true, "minLength" : 5, "maxLength" : 200, "array" : false, "hint" : "邮件的主题", "type" : "String", "description" : "主题" }, { "name" : "content", "required" : true, "minLength" : 10, "maxLength" : 102400, "array" : false, "hint" : "HTML格式的邮件内容", "type" : "String", "description" : "邮件内容" } ], "results" : [ { "name" : "reason", "array" : false, "type" : "String", "description" : "出错原因" }, { "name" : "result", "array" : false, "type" : "int", "description" : "结果", "hint" : "1为成功,9999为已缓存,小于1为出错,应显示原因" } ] }