mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-15 05:10:47 +08:00
opti: npm publish
This commit is contained in:
parent
12ebed908f
commit
6952631a5a
6
.npmignore
Normal file
6
.npmignore
Normal file
@ -0,0 +1,6 @@
|
||||
/docs
|
||||
/test
|
||||
/static/doc
|
||||
/iconfont
|
||||
/ydoc.js
|
||||
/ydocfile.js
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -1,72 +0,0 @@
|
||||
'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 = $;
|
@ -1,33 +0,0 @@
|
||||
'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;
|
||||
};
|
@ -1,56 +0,0 @@
|
||||
'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;
|
||||
};
|
@ -1,107 +0,0 @@
|
||||
'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
|
||||
};
|
@ -1,65 +0,0 @@
|
||||
'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;
|
||||
};
|
@ -1,53 +0,0 @@
|
||||
'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);
|
||||
};
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "yapi",
|
||||
"name": "yapi-verndor",
|
||||
"version": "1.4.1",
|
||||
"description": "YAPI",
|
||||
"main": "index.js",
|
||||
"main": "server/app.js",
|
||||
"scripts": {
|
||||
"dev-copy-icon": "cp -r static/iconfont ./",
|
||||
"dev-server": " nodemon server/app.js dev -L",
|
||||
@ -168,7 +168,7 @@
|
||||
"maxSubjectLength": 100,
|
||||
"subjectPattern": ".+",
|
||||
"subjectPatternErrorMsg": "请输入message信息!",
|
||||
"helpMessage": "Commit message 格式错误, \n请查看规范: http://wiki.corp.qunar.com/pages/viewpage.action?pageId=159698767"
|
||||
"helpMessage": "Commit message 格式错误, http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html"
|
||||
}
|
||||
},
|
||||
"engines": {
|
||||
|
Loading…
Reference in New Issue
Block a user