框架整體介紹:http://blog.csdn.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爲出錯,應顯示原因" } ] }