mirror of
https://github.com/YMFE/yapi.git
synced 2025-02-05 13:29:43 +08:00
feat: interface add title field
This commit is contained in:
parent
b4d3b9d699
commit
573fc89b69
@ -3,6 +3,7 @@
|
||||
//header Content-Type:application/json
|
||||
|
||||
{
|
||||
"title": "testapi",
|
||||
"desc": "api",
|
||||
"method": "post",
|
||||
"path": "/testapi",
|
||||
@ -37,6 +38,7 @@
|
||||
"data": {
|
||||
"__v": 0,
|
||||
"_id": 422,
|
||||
"title": "testapi",
|
||||
"project_id": 8,
|
||||
"path": "/testapi",
|
||||
"desc": "api",
|
||||
|
@ -15,6 +15,7 @@ class interfaceController extends baseController{
|
||||
* @category interface
|
||||
* @foldnumber 10
|
||||
* @param {Number} project_id 项目id,不能为空
|
||||
* @param {String} title 接口标题,不能为空
|
||||
* @param {String} path 接口请求路径,不能为空
|
||||
* @param {String} method 请求方式
|
||||
* @param {Array} [req_headers] 请求的header信息
|
||||
@ -65,8 +66,8 @@ class interfaceController extends baseController{
|
||||
up_time: yapi.commons.time()
|
||||
}
|
||||
|
||||
if(data.req_params_type === 'form') data.req_params_form = params.req_params;
|
||||
else data.req_params_other = params.req_params;
|
||||
if(params.req_params_form) data.req_params_form = params.req_params_form;
|
||||
if(params.req_params_other) data.req_params_other = params.req_params_other;
|
||||
|
||||
let result = await this.Model.save(data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
@ -167,13 +168,14 @@ class interfaceController extends baseController{
|
||||
}
|
||||
|
||||
if(params.path) data.path = params.path;
|
||||
if(params.title) data.title = params.title;
|
||||
if(params.desc) data.desc = params.desc;
|
||||
if(params.method) data.method = params.method;
|
||||
|
||||
if(params.req_headers) data.req_headers = params.req_headers;
|
||||
|
||||
if(params.req_params_type === 'form') data.req_params_form = params.req_params;
|
||||
else data.req_params_other = params.req_params;
|
||||
if(params.req_params_form) data.req_params_form = params.req_params_form;
|
||||
if(params.req_params_other) data.req_params_other = params.req_params_other;
|
||||
|
||||
if(params.res_body_type) data.res_body_type = params.res_body_type;
|
||||
if(params.res_body) data.res_body = params.res_body;
|
||||
|
@ -14,6 +14,32 @@ class projectController extends baseController {
|
||||
this.groupModel = yapi.getInst(groupModel);
|
||||
}
|
||||
|
||||
handleBasepath(basepath){
|
||||
if(!basepath) return false;
|
||||
if(basepath[0] !== '/') basepath = '/' + basepath;
|
||||
if(basepath[basepath.length -1] === '/') basepath = basepath.substr(0, basepath.length -1)
|
||||
if(!this.verifyPath(basepath)){
|
||||
return false;
|
||||
}
|
||||
return basepath;
|
||||
}
|
||||
|
||||
verifyPath(path){
|
||||
if(/^[a-zA-Z0-9\-\/_:]+$/.test(basepath)){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
verifyDomain(domain){
|
||||
if(!domain) return false;
|
||||
if(/^[a-zA-Z0-9\-_\.]+[a-zA-Z]{2,6}$/.test(domain)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加项目分组
|
||||
* @interface /project/add
|
||||
@ -52,10 +78,19 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目domain不能为空');
|
||||
}
|
||||
|
||||
if(params.basepath = (this.handleBasepath(params.basepath)) === false){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')
|
||||
}
|
||||
|
||||
if(!this.verifyDomain(params.prd_host)){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误')
|
||||
}
|
||||
|
||||
let checkRepeatDomain = await this.Model.checkDomainRepeat(params.prd_host, params.basepath);
|
||||
if(checkRepeatDomain > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '已存在domain和basepath');
|
||||
}
|
||||
|
||||
|
||||
let data = {
|
||||
name: params.name,
|
||||
@ -306,6 +341,15 @@ class projectController extends baseController {
|
||||
}
|
||||
|
||||
let projectData = await this.Model.get(id);
|
||||
|
||||
if(params.basepath = (this.handleBasepath(params.basepath)) === false){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, 'basepath格式有误')
|
||||
}
|
||||
|
||||
if(!this.verifyDomain(params.prd_host)){
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '线上域名格式有误')
|
||||
}
|
||||
|
||||
if(projectData.name === params.name){
|
||||
delete params.name;
|
||||
}
|
||||
|
@ -8,13 +8,9 @@ class interfaceModel extends baseModel{
|
||||
|
||||
getSchema(){
|
||||
return {
|
||||
title: {type: String, required: true},
|
||||
uid: {type: Number, required: true},
|
||||
path: {type: String, required: true, validate: {
|
||||
validator: (v) => {
|
||||
return v && v[0] !== '/';
|
||||
},
|
||||
message: '接口路径第一位不能是/'
|
||||
}},
|
||||
path: {type: String, required: true},
|
||||
method: {type: String, required: true},
|
||||
project_id: {type: Number, required: true},
|
||||
desc: String,
|
||||
|
@ -12,9 +12,9 @@ class projectModel extends baseModel{
|
||||
name: {type: String, required: true},
|
||||
basepath: {type: String, required: true, validate: {
|
||||
validator: (v) => {
|
||||
return v && v[v.length - 1] === '/'
|
||||
return v && v[0] === '/'
|
||||
},
|
||||
message: 'basepath字符串结尾必须是/'
|
||||
message: 'basepath必须是/开头'
|
||||
}},
|
||||
desc: String,
|
||||
group_id: {type: Number, required: true},
|
||||
|
Loading…
Reference in New Issue
Block a user