Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev

This commit is contained in:
zwjamnsss 2017-09-08 11:36:47 +08:00
commit ff915df4d1
11 changed files with 57 additions and 41 deletions

View File

@ -1,5 +1,6 @@
import React from 'react'
import moment from 'moment'
import React from 'react';
import moment from 'moment';
import constants from './constants/variable';
exports.formatTime = (timestamp) => {
@ -86,7 +87,7 @@ exports.handlePath = (path) => {
return path;
}
// 名称限制 20 字符
// 名称限制 constants.NAME_LIMIT 字符
exports.nameLengthLimit = (type) => {
// 返回字符串长度汉字计数为2
const strLength = (str) => {
@ -101,10 +102,10 @@ exports.nameLengthLimit = (type) => {
required: true,
validator(rule, value, callback) {
const len = value ? strLength(value) : 0;
if (len > 20) {
callback('请输入' + type + '名称,长度不超过20字符(中文算作2字符)!');
if (len > constants.NAME_LIMIT) {
callback('请输入' + type + '名称,长度不超过' + constants.NAME_LIMIT + '字符(中文算作2字符)!');
} else if (len === 0) {
callback('请输入' + type + '名称,长度不超过20字符(中文算作2字符)!');
callback('请输入' + type + '名称,长度不超过' + constants.NAME_LIMIT + '字符(中文算作2字符)!');
} else {
return callback();
}

View File

@ -65,13 +65,13 @@ function run(options) {
var curData = mockEditor.curData;
try {
curData.text = json;
var obj = json5.parse(json);
var obj = json5.parse(json);
curData.format = true;
curData.jsonData = obj;
curData.mockData = Mock.mock(MockExtra(obj, {}));
curData.mockText = JSON.stringify(curData.mockData, null, " ");
} catch (e) {
curData.format = e.message;
}
}
@ -114,7 +114,10 @@ function run(options) {
rhymeCompleter = {
identifierRegexps: [/[@]/],
getCompletions: function (editor, session, pos, prefix, callback) {
if (prefix.length === 0) { callback(null, []); return }
if (prefix.length === 0) {
callback(null, []);
return;
}
callback(null, wordList.map(function (ea) {
return { name: ea.mock, value: ea.mock, score: ea.mock, meta: ea.name }
}));
@ -153,4 +156,4 @@ function run(options) {
}
})
*/
module.exports = run;
module.exports = run;

View File

@ -23,9 +23,10 @@ class followController extends baseController {
*/
async list(ctx) {
let uid = this.getUid(),
page = ctx.request.query.page || 1,
limit = ctx.request.query.limit || 10;
let uid = this.getUid();
// 关注列表暂时不分页 page & limit 为分页配置
// page = ctx.request.query.page || 1,
// limit = ctx.request.query.limit || 10;
if (!uid) {
return ctx.body = yapi.commons.resReturn(null, 400, '用户id不能为空');
@ -49,7 +50,7 @@ class followController extends baseController {
* @method POST
* @category follow
* @foldnumber 10
* @param {Number} projectid
* @param {Number} projectid
* @returns {Object}
* @example /follow/del
*/

View File

@ -44,8 +44,8 @@ class interfaceController extends baseController {
* @param {String} [req_body_other] 非form类型的请求参数可保存到此字段
* @param {String} [res_body_type] 相应信息的数据格式["json", "text", "xml"]三种
* @param {String} [res_body] 响应信息可填写任意字符串如果res_body_type是json,则会调用mock功能
* @param {String} [desc] 接口描述
* @returns {Object}
* @param {String} [desc] 接口描述
* @returns {Object}
* @example ./api/interface/add.json
*/
async add(ctx) {
@ -153,7 +153,7 @@ class interfaceController extends baseController {
// this.sendNotice(params.project_id, {
// title: `${username} 新增了接口 ${data.title}`,
// content: `<div><h3>${username}新增了接口(${data.title})</h3>
// <p>项目名:${project.name}</p>
// <p>项目名:${project.name}</p>
// <p>修改用户: "${username}"</p>
// <p>接口名: <a href="${interfaceUrl}">${data.title}</a></p>
// <p>接口路径: [${data.method}]${data.path}</p></div>`
@ -173,7 +173,7 @@ class interfaceController extends baseController {
* @category interface
* @foldnumber 10
* @param {Number} id 接口id不能为空
* @returns {Object}
* @returns {Object}
* @example ./api/interface/get.json
*/
async get(ctx) {
@ -198,7 +198,7 @@ class interfaceController extends baseController {
* @category interface
* @foldnumber 10
* @param {Number} project_id 项目id不能为空
* @returns {Object}
* @returns {Object}
* @example ./api/interface/list.json
*/
async list(ctx) {
@ -275,8 +275,8 @@ class interfaceController extends baseController {
* @param {String} [req_body_other] 非form类型的请求参数可保存到此字段
* @param {String} [res_body_type] 相应信息的数据格式["json", "text", "xml"]三种
* @param {String} [res_body] 响应信息可填写任意字符串如果res_body_type是json,则会调用mock功能
* @param {String} [desc] 接口描述
* @returns {Object}
* @param {String} [desc] 接口描述
* @returns {Object}
* @example ./api/interface/up.json
*/
@ -432,7 +432,7 @@ class interfaceController extends baseController {
* @category interface
* @foldnumber 10
* @param {Number} id 接口id不能为空
* @returns {Object}
* @returns {Object}
* @example ./api/interface/del.json
*/
@ -478,7 +478,8 @@ class interfaceController extends baseController {
try {
let id = parseInt(ctx.query.id, 10), result, userInst, userinfo, data;
if (!id) return ctx.websocket.send("id 参数有误");
result = await this.Model.get(id), userinfo;
await this.Model.get(id);
result = userinfo;
if (result.edit_uid !== 0 && result.edit_uid !== this.getUid()) {
userInst = yapi.getInst(userModel);
userinfo = await userInst.findById(result.edit_uid);
@ -603,7 +604,8 @@ class interfaceController extends baseController {
typeid: catData.project_id
});
let result = await this.catModel.del(id);
// no used variable 'result'
// let result = await this.catModel.del(id);
let r = await this.Model.delByCatid(id);
return ctx.body = yapi.commons.resReturn(r);
} catch (e) {
@ -619,7 +621,7 @@ class interfaceController extends baseController {
* @category interface
* @foldnumber 10
* @param {Number} project_id 项目id不能为空
* @returns {Object}
* @returns {Object}
* @example ./api/interface/getCatMenu
*/
@ -659,4 +661,4 @@ class interfaceController extends baseController {
}
module.exports = interfaceController;
module.exports = interfaceController;

View File

@ -116,6 +116,11 @@ class interfaceColController extends baseController{
result[index] = result[index].toObject();
let interfaceData = await this.interfaceModel.getBaseinfo(result[index].interface_id);
if(!interfaceData){
await this.caseModel.del(result[index]._id);
result[index] = undefined;
continue;
}
let projectData = await this.projectModel.getBaseInfo(interfaceData.project_id);
result[index].path = projectData.basepath + interfaceData.path;
result[index].method = interfaceData.method;
@ -295,8 +300,11 @@ class interfaceColController extends baseController{
}
result = result.toObject();
let data = await this.interfaceModel.get(result.interface_id);
if(!data){
return ctx.body = yapi.commons.resReturn(null, 400, '找不到对应的接口,请联系管理员')
}
data = data.toObject();
let projectData = await this.projectModel.getBaseInfo(data.project_id);
let projectData = await this.projectModel.getBaseInfo(data.project_id);
result.path = projectData.basepath + data.path;
result.method = data.method;
result.req_body_type = data.req_body_type;

View File

@ -22,8 +22,9 @@ function matchApi(apiPath, apiRule) {
}
module.exports = async (ctx, next) => {
let hostname = ctx.hostname;
let config = yapi.WEBCONFIG;
// no used variable 'hostname' & 'config'
// let hostname = ctx.hostname;
// let config = yapi.WEBCONFIG;
let path = ctx.path;
@ -52,7 +53,7 @@ module.exports = async (ctx, next) => {
return ctx.body = yapi.commons.resReturn(null, 400, '不存在的项目');
}
let interfaceData, newData, newpath;
let interfaceData, newpath;
let interfaceInst = yapi.getInst(interfaceModel);
try {

View File

@ -55,7 +55,7 @@ class interfaceModel extends baseModel {
enum: ['json', 'text', 'xml', 'raw']
},
res_body: String
};
};
}
save(data) {
@ -72,7 +72,7 @@ class interfaceModel extends baseModel {
getBaseinfo(id){
return this.model.findOne({
_id: id,
_id: id
}).select('path method uid title project_id cat_id status').exec()
}
@ -151,7 +151,7 @@ class interfaceModel extends baseModel {
upEditUid(id, uid){
return this.model.update({
_id: id
},
},
{edit_uid: uid},
{runValidators: true });
}

View File

@ -21,7 +21,7 @@ function bindHook(name, listener){
}else{
hooks[name].listener = listener;
}
}
function emitHook(name){
@ -29,7 +29,7 @@ function emitHook(name){
if(name in hooks === false){
throw new Error('不存在的hookname');
}
if(hooks[name] && typeof hooks[name] === 'object'){
if(hooks[name].type === 'single' && typeof hooks[name].listener === 'function'){
return hooks[name].listener.apply(yapi, Array.prototype.slice.call(arguments, 1));
@ -50,11 +50,11 @@ module.exports = function(){
if(yapi.WEBCONFIG.plugins && Array.isArray(yapi.WEBCONFIG.plugins)){
yapi.WEBCONFIG.plugins.forEach(plugin=>{
if(!yapi.commons.fileExist(yapi.path.join(plugin_path, 'yapi-plugin-' + plugin + '/server.js'))){
throw new Error(`config.json配置了插件${plugin},但plugins目录没有找到此插件请安装此插件?`);
console.error(`config.json配置了插件${plugin},但plugins目录没有找到此插件请安装此插件?`);
process.exit();
}
let pluginModule = require(yapi.path.join(plugin_path, 'yapi-plugin-' + plugin + '/server.js'));
pluginModule.apply(yapi)
})
}
}
}

Binary file not shown.

View File

@ -14,7 +14,7 @@ var compressPlugin = new CompressionPlugin({
algorithm: "gzip",
test: /\.(js|css)$/,
threshold: 10240,
minRatio: 0.8,
minRatio: 0.8
});
function fileExist (filePath){
@ -50,7 +50,7 @@ function handleCommonsChunk(webpackConfig) {
'moment'
],
lib2: [
lib2: [
'brace',
'mockjs',
'json5'
@ -122,7 +122,7 @@ module.exports = {
exports: [
'./index.js'
],
modifyWebpackConfig: function (baseConfig) {
modifyWebpackConfig: function (baseConfig) {
var ENV_PARAMS = {};
switch (this.env) {
@ -194,4 +194,4 @@ module.exports = {
},
hooks: {},
commands: []
};
};