MCPcopy
hub / github.com/YMFE/yapi / up

Method up

server/controllers/interface.js:627–786  ·  view source on GitHub ↗

* 编辑接口 * @interface /interface/up * @method POST * @category interface * @foldnumber 10 * @param {Number} id 接口id,不能为空 * @param {String} [path] 接口请求路径 * @param {String} [method] 请求方式 * @param {Array} [req_headers] 请求的header信息 * @param {String} [req_headers[].name]

(ctx)

Source from the content-addressed store, hash-verified

625 * @example ./api/interface/up.json
626 */
627 async up(ctx) {
628 let params = ctx.params;
629
630 if (!_.isUndefined(params.method)) {
631 params.method = params.method || 'GET';
632 params.method = params.method.toUpperCase();
633 }
634
635 let id = params.id;
636 params.message = params.message || '';
637 params.message = params.message.replace(/\n/g, '<br>');
638 // params.res_body_is_json_schema = _.isUndefined (params.res_body_is_json_schema) ? true : params.res_body_is_json_schema;
639 // params.req_body_is_json_schema = _.isUndefined(params.req_body_is_json_schema) ? true : params.req_body_is_json_schema;
640
641 handleHeaders(params)
642
643 let interfaceData = await this.Model.get(id);
644 if (!interfaceData) {
645 return (ctx.body = yapi.commons.resReturn(null, 400, '不存在的接口'));
646 }
647 if (!this.$tokenAuth) {
648 let auth = await this.checkAuth(interfaceData.project_id, 'project', 'edit');
649 if (!auth) {
650 return (ctx.body = yapi.commons.resReturn(null, 400, '没有权限'));
651 }
652 }
653
654 let data = Object.assign(
655 {
656 up_time: yapi.commons.time()
657 },
658 params
659 );
660
661 if (params.path) {
662 let http_path;
663 http_path = url.parse(params.path, true);
664
665 if (!yapi.commons.verifyPath(http_path.pathname)) {
666 return (ctx.body = yapi.commons.resReturn(
667 null,
668 400,
669 'path第一位必需为 /, 只允许由 字母数字-/_:.! 组成'
670 ));
671 }
672 params.query_path = {};
673 params.query_path.path = http_path.pathname;
674 params.query_path.params = [];
675 Object.keys(http_path.query).forEach(item => {
676 params.query_path.params.push({
677 name: item,
678 value: http_path.query[item]
679 });
680 });
681 data.query_path = params.query_path;
682 }
683
684 if (

Callers 4

saveMethod · 0.95
addMethod · 0.45
delMethod · 0.45
upCatMethod · 0.45

Calls 8

diffHTMLMethod · 0.95
handleHeadersFunction · 0.85
getUsernameMethod · 0.80
getBaseInfoMethod · 0.80
getMethod · 0.45
checkAuthMethod · 0.45
checkRepeatMethod · 0.45
getUidMethod · 0.45

Tested by

no test coverage detected