mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-12 15:10:23 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
5859b70eb8
@ -87,10 +87,10 @@ Footer.defaultProps = {
|
||||
linkList: [
|
||||
{
|
||||
itemTitle: '版本: ' + packageJson.version,
|
||||
itemLink: 'http://yapi.qunar.com/releases.html'
|
||||
itemLink: 'https://yapi.ymfe.org/releases.html'
|
||||
}, {
|
||||
itemTitle: '使用文档',
|
||||
itemLink: 'http://yapi.qunar.com'
|
||||
itemLink: 'https://yapi.ymfe.org'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ export default {
|
||||
],
|
||||
IP_REGEXP: /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){3}$/,
|
||||
docHref: {
|
||||
adv_mock_case: 'http://yapi.qunar.com/adv_mock.html#Mock_期望',
|
||||
adv_mock_script: 'http://yapi.qunar.com/adv_mock.html#自定义_Mock_脚本'
|
||||
adv_mock_case: 'https://yapi.ymfe.org/adv_mock.html#Mock_期望',
|
||||
adv_mock_script: 'https://yapi.ymfe.org/adv_mock.html#自定义_Mock_脚本'
|
||||
}
|
||||
}
|
||||
|
@ -890,7 +890,7 @@ class InterfaceEditForm extends Component {
|
||||
{Json5Example}
|
||||
</pre>}>
|
||||
<Icon type="question-circle-o" style={{ color: "#086dbf" }} />
|
||||
</Tooltip> ,具体使用方法请 <span className="href" onClick={() => window.open('http://yapi.qunar.com/mock.html', '_blank')}>查看文档</span>
|
||||
</Tooltip> ,具体使用方法请 <span className="href" onClick={() => window.open('https://yapi.ymfe.org/mock.html', '_blank')}>查看文档</span>
|
||||
,“全局编辑” 或 “退出全屏” 请按 F9
|
||||
</h3>
|
||||
<div id="res_body_json" style={{ minHeight: "300px", display: this.state.jsonType === 'tpl' ? 'block' : 'none' }} ></div>
|
||||
|
@ -1,7 +1,7 @@
|
||||
function _interopDefault(ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
||||
|
||||
var $RefParser = _interopDefault(require('json-schema-ref-parser'));
|
||||
var deref = _interopDefault(require('deref'));
|
||||
var deref = _interopDefault(require('./parse-json-schema'));
|
||||
var tslib_1 = require('tslib');
|
||||
|
||||
// dynamic proxy for custom generators
|
||||
|
72
common/parse-json-schema/index.js
Normal file
72
common/parse-json-schema/index.js
Normal file
@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
var $ = require('./util/helpers');
|
||||
|
||||
$.findByRef = require('./util/find-reference');
|
||||
$.resolveSchema = require('./util/resolve-schema');
|
||||
$.normalizeSchema = require('./util/normalize-schema');
|
||||
|
||||
var instance = module.exports = function(f) {
|
||||
function $ref(fakeroot, schema, refs, ex) {
|
||||
if (typeof fakeroot === 'object') {
|
||||
ex = refs;
|
||||
refs = schema;
|
||||
schema = fakeroot;
|
||||
fakeroot = undefined;
|
||||
}
|
||||
|
||||
if (typeof schema !== 'object') {
|
||||
throw new Error('schema must be an object');
|
||||
}
|
||||
|
||||
if (typeof refs === 'object' && refs !== null) {
|
||||
var aux = refs;
|
||||
|
||||
refs = [];
|
||||
|
||||
for (var k in aux) {
|
||||
aux[k].id = aux[k].id || k;
|
||||
refs.push(aux[k]);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof refs !== 'undefined' && !Array.isArray(refs)) {
|
||||
ex = !!refs;
|
||||
refs = [];
|
||||
}
|
||||
|
||||
function push(ref) {
|
||||
if (typeof ref.id === 'string') {
|
||||
var id = $.resolveURL(fakeroot, ref.id).replace(/\/#?$/, '');
|
||||
|
||||
if (id.indexOf('#') > -1) {
|
||||
var parts = id.split('#');
|
||||
|
||||
if (parts[1].charAt() === '/') {
|
||||
id = parts[0];
|
||||
} else {
|
||||
id = parts[1] || parts[0];
|
||||
}
|
||||
}
|
||||
|
||||
if (!$ref.refs[id]) {
|
||||
$ref.refs[id] = ref;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
(refs || []).concat([schema]).forEach(function(ref) {
|
||||
schema = $.normalizeSchema(fakeroot, ref, push);
|
||||
push(schema);
|
||||
});
|
||||
|
||||
return $.resolveSchema(schema, $ref.refs, ex, f);
|
||||
}
|
||||
|
||||
$ref.refs = {};
|
||||
$ref.util = $;
|
||||
|
||||
return $ref;
|
||||
};
|
||||
|
||||
instance.util = $;
|
33
common/parse-json-schema/util/clone-obj.js
Normal file
33
common/parse-json-schema/util/clone-obj.js
Normal file
@ -0,0 +1,33 @@
|
||||
'use strict';
|
||||
|
||||
var clone = module.exports = function(obj, seen) {
|
||||
seen = seen || [];
|
||||
|
||||
if (seen.indexOf(obj) > -1) {
|
||||
throw new Error('unable dereference circular structures');
|
||||
}
|
||||
|
||||
if (!obj || typeof obj !== 'object') {
|
||||
return obj;
|
||||
}
|
||||
|
||||
seen = seen.concat([obj]);
|
||||
|
||||
var target = Array.isArray(obj) ? [] : {};
|
||||
|
||||
function copy(key, value) {
|
||||
target[key] = clone(value, seen);
|
||||
}
|
||||
|
||||
if (Array.isArray(target)) {
|
||||
obj.forEach(function(value, key) {
|
||||
copy(key, value);
|
||||
});
|
||||
} else if (Object.prototype.toString.call(obj) === '[object Object]') {
|
||||
Object.keys(obj).forEach(function(key) {
|
||||
copy(key, obj[key]);
|
||||
});
|
||||
}
|
||||
|
||||
return target;
|
||||
};
|
56
common/parse-json-schema/util/find-reference.js
Normal file
56
common/parse-json-schema/util/find-reference.js
Normal file
@ -0,0 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
var $ = require('./helpers');
|
||||
|
||||
function get(obj, path) {
|
||||
var hash = path.split('#')[1];
|
||||
|
||||
var parts = hash.split('/').slice(1);
|
||||
|
||||
while (parts.length) {
|
||||
var key = decodeURIComponent(parts.shift()).replace(/~1/g, '/').replace(/~0/g, '~');
|
||||
|
||||
if (typeof obj[key] === 'undefined') {
|
||||
throw new Error('JSON pointer not found: ' + path);
|
||||
}
|
||||
|
||||
obj = obj[key];
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
var find = module.exports = function(id, refs, filter) {
|
||||
|
||||
var target = refs[id] || refs[id.split('#')[1]] || refs[$.getDocumentURI(id)];
|
||||
|
||||
try {
|
||||
if (target) {
|
||||
target = id.indexOf('#/') > -1 ? get(target, id) : target;
|
||||
|
||||
} else {
|
||||
for (var key in refs) {
|
||||
if ($.resolveURL(refs[key].id, id) === refs[key].id) {
|
||||
target = refs[key];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (typeof filter === 'function') {
|
||||
target = filter(id, refs);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
if (!target) {
|
||||
throw new Error('Reference not found: ' + id);
|
||||
}
|
||||
|
||||
|
||||
while (target.$ref) {
|
||||
target = find(target.$ref, refs);
|
||||
}
|
||||
return target;
|
||||
};
|
107
common/parse-json-schema/util/helpers.js
Normal file
107
common/parse-json-schema/util/helpers.js
Normal file
@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
// https://gist.github.com/pjt33/efb2f1134bab986113fd
|
||||
|
||||
function URLUtils(url, baseURL) {
|
||||
// remove leading ./
|
||||
url = url.replace(/^\.\//, '');
|
||||
|
||||
var m = String(url).replace(/^\s+|\s+$/g, '').match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@]*)(?::([^:@]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
|
||||
if (!m) {
|
||||
throw new RangeError();
|
||||
}
|
||||
var href = m[0] || '';
|
||||
var protocol = m[1] || '';
|
||||
var username = m[2] || '';
|
||||
var password = m[3] || '';
|
||||
var host = m[4] || '';
|
||||
var hostname = m[5] || '';
|
||||
var port = m[6] || '';
|
||||
var pathname = m[7] || '';
|
||||
var search = m[8] || '';
|
||||
var hash = m[9] || '';
|
||||
if (baseURL !== undefined) {
|
||||
var base = new URLUtils(baseURL);
|
||||
var flag = protocol === '' && host === '' && username === '';
|
||||
if (flag && pathname === '' && search === '') {
|
||||
search = base.search;
|
||||
}
|
||||
if (flag && pathname.charAt(0) !== '/') {
|
||||
pathname = (pathname !== '' ? (base.pathname.slice(0, base.pathname.lastIndexOf('/') + 1) + pathname) : base.pathname);
|
||||
}
|
||||
// dot segments removal
|
||||
var output = [];
|
||||
|
||||
pathname.replace(/\/?[^\/]+/g, function(p) {
|
||||
if (p === '/..') {
|
||||
output.pop();
|
||||
} else {
|
||||
output.push(p);
|
||||
}
|
||||
});
|
||||
|
||||
pathname = output.join('') || '/';
|
||||
|
||||
if (flag) {
|
||||
port = base.port;
|
||||
hostname = base.hostname;
|
||||
host = base.host;
|
||||
password = base.password;
|
||||
username = base.username;
|
||||
}
|
||||
if (protocol === '') {
|
||||
protocol = base.protocol;
|
||||
}
|
||||
href = protocol + (host !== '' ? '//' : '') + (username !== '' ? username + (password !== '' ? ':' + password : '') + '@' : '') + host + pathname + search + hash;
|
||||
}
|
||||
this.href = href;
|
||||
this.origin = protocol + (host !== '' ? '//' + host : '');
|
||||
this.protocol = protocol;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.host = host;
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.pathname = pathname;
|
||||
this.search = search;
|
||||
this.hash = hash;
|
||||
}
|
||||
|
||||
function isURL(path) {
|
||||
if (typeof path === 'string' && /^\w+:\/\//.test(path)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function parseURI(href, base) {
|
||||
return new URLUtils(href, base);
|
||||
}
|
||||
|
||||
function resolveURL(base, href) {
|
||||
base = base || 'http://json-schema.org/schema#';
|
||||
|
||||
href = parseURI(href, base);
|
||||
base = parseURI(base);
|
||||
|
||||
if (base.hash && !href.hash) {
|
||||
return href.href + base.hash;
|
||||
}
|
||||
|
||||
return href.href;
|
||||
}
|
||||
|
||||
function getDocumentURI(uri) {
|
||||
return typeof uri === 'string' && uri.split('#')[0];
|
||||
}
|
||||
|
||||
function isKeyword(prop) {
|
||||
return prop === 'enum' || prop === 'default' || prop === 'required';
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
isURL: isURL,
|
||||
parseURI: parseURI,
|
||||
isKeyword: isKeyword,
|
||||
resolveURL: resolveURL,
|
||||
getDocumentURI: getDocumentURI
|
||||
};
|
65
common/parse-json-schema/util/normalize-schema.js
Normal file
65
common/parse-json-schema/util/normalize-schema.js
Normal file
@ -0,0 +1,65 @@
|
||||
'use strict';
|
||||
|
||||
var $ = require('./helpers');
|
||||
|
||||
var cloneObj = require('./clone-obj');
|
||||
|
||||
var SCHEMA_URI = [
|
||||
'http://json-schema.org/schema#',
|
||||
'http://json-schema.org/schema',
|
||||
'http://json-schema.org/draft-04/schema#',
|
||||
'http://json-schema.org/draft-04/schema'
|
||||
];
|
||||
|
||||
function expand(obj, parent, callback) {
|
||||
if (obj) {
|
||||
var id = typeof obj.id === 'string' ? obj.id : '#';
|
||||
|
||||
if (!$.isURL(id)) {
|
||||
id = $.resolveURL(parent === id ? null : parent, id);
|
||||
}
|
||||
|
||||
if (typeof obj.$ref === 'string' && !$.isURL(obj.$ref)) {
|
||||
obj.$ref = $.resolveURL(id, obj.$ref);
|
||||
}
|
||||
|
||||
if (typeof obj.id === 'string') {
|
||||
obj.id = parent = id;
|
||||
}
|
||||
}
|
||||
|
||||
for (var key in obj) {
|
||||
var value = obj[key];
|
||||
|
||||
if (typeof value === 'object' && value !== null && !$.isKeyword(key)) {
|
||||
expand(value, parent, callback);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof callback === 'function') {
|
||||
callback(obj);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function(fakeroot, schema, push) {
|
||||
if (typeof fakeroot === 'object') {
|
||||
push = schema;
|
||||
schema = fakeroot;
|
||||
fakeroot = null;
|
||||
}
|
||||
|
||||
var base = fakeroot || '',
|
||||
copy = cloneObj(schema);
|
||||
|
||||
if (copy.$schema && SCHEMA_URI.indexOf(copy.$schema) === -1) {
|
||||
throw new Error('Unsupported schema version (v4 only)');
|
||||
}
|
||||
|
||||
base = $.resolveURL(copy.$schema || SCHEMA_URI[0], base);
|
||||
|
||||
expand(copy, $.resolveURL(copy.id || '#', base), push);
|
||||
|
||||
copy.id = copy.id || base;
|
||||
|
||||
return copy;
|
||||
};
|
53
common/parse-json-schema/util/resolve-schema.js
Normal file
53
common/parse-json-schema/util/resolve-schema.js
Normal file
@ -0,0 +1,53 @@
|
||||
'use strict';
|
||||
|
||||
var $ = require('./helpers');
|
||||
|
||||
var find = require('./find-reference');
|
||||
|
||||
var deepExtend = require('deep-extend');
|
||||
|
||||
function copy(_, obj, refs, parent, resolve, callback) {
|
||||
var target = Array.isArray(obj) ? [] : {};
|
||||
|
||||
if (typeof obj.$ref === 'string') {
|
||||
var id = obj.$ref;
|
||||
var base = $.getDocumentURI(id);
|
||||
var local = id.indexOf('#/') > -1;
|
||||
|
||||
if (local || (resolve && base !== parent)) {
|
||||
var fixed = find(id, refs, callback);
|
||||
|
||||
deepExtend(obj, fixed);
|
||||
|
||||
delete obj.$ref;
|
||||
delete obj.id;
|
||||
}
|
||||
|
||||
if (_[id] > 10) {
|
||||
return obj;
|
||||
}else if(_[id]){
|
||||
_[id] += 1;
|
||||
}else{
|
||||
_[id] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (var prop in obj) {
|
||||
|
||||
if (typeof obj[prop] === 'object' && obj[prop] !== null && !$.isKeyword(prop)) {
|
||||
target[prop] = copy(_, obj[prop], refs, parent, resolve, callback);
|
||||
} else {
|
||||
target[prop] = obj[prop];
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
module.exports = function(obj, refs, resolve, callback) {
|
||||
var fixedId = $.resolveURL(obj.$schema, obj.id),
|
||||
parent = $.getDocumentURI(fixedId);
|
||||
|
||||
return copy({}, obj, refs, parent, resolve, callback);
|
||||
};
|
@ -132,7 +132,7 @@ class exportController extends baseController {
|
||||
<a href="#" style="display: inherit;"><svg class="svg" width="32px" height="32px" viewBox="0 0 64 64" version="1.1"><title>Icon</title><desc>Created with Sketch.</desc><defs><linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1"><stop stop-color="#FFFFFF" offset="0%"></stop><stop stop-color="#F2F2F2" offset="100%"></stop></linearGradient><circle id="path-2" cx="31.9988602" cy="31.9988602" r="2.92886048"></circle><filter x="-85.4%" y="-68.3%" width="270.7%" height="270.7%" filterUnits="objectBoundingBox" id="filter-3"><feOffset dx="0" dy="1" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset><feGaussianBlur stdDeviation="1.5" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.159703351 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix></filter></defs><g id="首页" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="大屏幕"><g id="Icon"><circle id="Oval-1" fill="url(#linearGradient-1)" cx="32" cy="32" r="32"></circle><path d="M36.7078009,31.8054514 L36.7078009,51.7110548 C36.7078009,54.2844537 34.6258634,56.3695395 32.0579205,56.3695395 C29.4899777,56.3695395 27.4099998,54.0704461 27.4099998,51.7941246 L27.4099998,31.8061972 C27.4099998,29.528395 29.4909575,27.218453 32.0589004,27.230043 C34.6268432,27.241633 36.7078009,29.528395 36.7078009,31.8054514 Z" id="blue" fill="#2359F1" fill-rule="nonzero"></path><path d="M45.2586091,17.1026914 C45.2586091,17.1026914 45.5657231,34.0524383 45.2345291,37.01141 C44.9033351,39.9703817 43.1767091,41.6667796 40.6088126,41.6667796 C38.040916,41.6667796 35.9609757,39.3676862 35.9609757,37.0913646 L35.9609757,17.1034372 C35.9609757,14.825635 38.0418959,12.515693 40.6097924,12.527283 C43.177689,12.538873 45.2586091,14.825635 45.2586091,17.1026914 Z" id="green" fill="#57CF27" fill-rule="nonzero" transform="translate(40.674608, 27.097010) rotate(60.000000) translate(-40.674608, -27.097010) "></path><path d="M28.0410158,17.0465598 L28.0410158,36.9521632 C28.0410158,39.525562 25.9591158,41.6106479 23.3912193,41.6106479 C20.8233227,41.6106479 18.7433824,39.3115545 18.7433824,37.035233 L18.7433824,17.0473055 C18.7433824,14.7695034 20.8243026,12.4595614 23.3921991,12.4711513 C25.9600956,12.4827413 28.0410158,14.7695034 28.0410158,17.0465598 Z" id="red" fill="#FF561B" fill-rule="nonzero" transform="translate(23.392199, 27.040878) rotate(-60.000000) translate(-23.392199, -27.040878) "></path><g id="inner-round"><use fill="black" fill-opacity="1" filter="url(#filter-3)" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#path-2"></use><use fill="#F7F7F7" fill-rule="evenodd" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#path-2"></use></g></g></g></g></svg></a>
|
||||
<a href="#"><h1 class="title">YAPI 接口文档</h1></a>
|
||||
<div class="nav">
|
||||
<a href="http://yapi.qunar.com/">YApi</a>
|
||||
<a href="https://yapi.ymfe.org/">YApi</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="g-doc">
|
||||
|
@ -29,6 +29,7 @@
|
||||
"ajv": "^5.5.1",
|
||||
"ajv-i18n": "^2.2.0",
|
||||
"axios": "^0.16.2",
|
||||
"deep-extend": "^0.5.0",
|
||||
"deref": "^0.7.0",
|
||||
"easy-json-schema": "0.0.2-beta",
|
||||
"fs-extra": "^3.0.1",
|
||||
|
Loading…
x
Reference in New Issue
Block a user