UNPKG

openapi-to-postmanv2

Version:

Convert a given OpenAPI specification to Postman Collection v2.0

1,715 lines (1,408 loc) 749 kB
/* eslint-disable */ /*! * json-schema-faker library v0.5.0-rc15 * http://json-schema-faker.js.org * * Copyright (c) 2014-2018 Alvaro Cabrera & Tomasz Ducin * Released under the MIT license * * Date: 2018-04-09 17:23:23.954Z */ var _ = require('lodash'), validateSchema = require('../lib/ajValidation/ajvValidation').validateSchema, { handleExclusiveMaximum, handleExclusiveMinimum } = require('./../lib/common/schemaUtilsCommon'), hash = require('object-hash'); (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : (global.JSONSchemaFaker = factory()); }(this, (function () { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]]; return t; } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [0, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __exportStar(m, exports) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } function __await(v) { return this instanceof __await ? (this.v = v, this) : new __await(v); } function __asyncGenerator(thisArg, _arguments, generator) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var g = generator.apply(thisArg, _arguments || []), i, q = []; return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i; function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; } function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } } function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); } function fulfill(value) { resume("next", value); } function reject(value) { resume("throw", value); } function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); } } function __asyncDelegator(o) { var i, p; return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i; function verb(n, f) { if (o[n]) i[n] = function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; }; } } function __asyncValues(o) { if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined."); var m = o[Symbol.asyncIterator]; return m ? m.call(o) : typeof __values === "function" ? __values(o) : o[Symbol.iterator](); } function __makeTemplateObject(cooked, raw) { if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; } return cooked; } var tslib_es6 = /*#__PURE__*/Object.freeze({ __extends: __extends, __assign: __assign, __rest: __rest, __decorate: __decorate, __param: __param, __metadata: __metadata, __awaiter: __awaiter, __generator: __generator, __exportStar: __exportStar, __values: __values, __read: __read, __spread: __spread, __await: __await, __asyncGenerator: __asyncGenerator, __asyncDelegator: __asyncDelegator, __asyncValues: __asyncValues, __makeTemplateObject: __makeTemplateObject }); var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function commonjsRequire () { throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs'); } function createCommonjsModule(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; } var types = { ROOT : 0, GROUP : 1, POSITION : 2, SET : 3, RANGE : 4, REPETITION : 5, REFERENCE : 6, CHAR : 7, }; var INTS = function() { return [{ type: types.RANGE , from: 48, to: 57 }]; }; var WORDS = function() { return [ { type: types.CHAR, value: 95 }, { type: types.RANGE, from: 97, to: 122 }, { type: types.RANGE, from: 65, to: 90 } ].concat(INTS()); }; var WHITESPACE = function() { return [ { type: types.CHAR, value: 9 }, { type: types.CHAR, value: 10 }, { type: types.CHAR, value: 11 }, { type: types.CHAR, value: 12 }, { type: types.CHAR, value: 13 }, { type: types.CHAR, value: 32 }, { type: types.CHAR, value: 160 }, { type: types.CHAR, value: 5760 }, { type: types.CHAR, value: 6158 }, { type: types.CHAR, value: 8192 }, { type: types.CHAR, value: 8193 }, { type: types.CHAR, value: 8194 }, { type: types.CHAR, value: 8195 }, { type: types.CHAR, value: 8196 }, { type: types.CHAR, value: 8197 }, { type: types.CHAR, value: 8198 }, { type: types.CHAR, value: 8199 }, { type: types.CHAR, value: 8200 }, { type: types.CHAR, value: 8201 }, { type: types.CHAR, value: 8202 }, { type: types.CHAR, value: 8232 }, { type: types.CHAR, value: 8233 }, { type: types.CHAR, value: 8239 }, { type: types.CHAR, value: 8287 }, { type: types.CHAR, value: 12288 }, { type: types.CHAR, value: 65279 } ]; }; var NOTANYCHAR = function() { return [ { type: types.CHAR, value: 10 }, { type: types.CHAR, value: 13 }, { type: types.CHAR, value: 8232 }, { type: types.CHAR, value: 8233 }, ]; }; // Predefined class objects. var words = function() { return { type: types.SET, set: WORDS(), not: false }; }; var notWords = function() { return { type: types.SET, set: WORDS(), not: true }; }; var ints = function() { return { type: types.SET, set: INTS(), not: false }; }; var notInts = function() { return { type: types.SET, set: INTS(), not: true }; }; var whitespace = function() { return { type: types.SET, set: WHITESPACE(), not: false }; }; var notWhitespace = function() { return { type: types.SET, set: WHITESPACE(), not: true }; }; var anyChar = function() { return { type: types.SET, set: NOTANYCHAR(), not: true }; }; var sets = { words: words, notWords: notWords, ints: ints, notInts: notInts, whitespace: whitespace, notWhitespace: notWhitespace, anyChar: anyChar }; var util = createCommonjsModule(function (module, exports) { // All of these are private and only used by randexp. // It's assumed that they will always be called with the correct input. var CTRL = '@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?'; var SLSH = { '0': 0, 't': 9, 'n': 10, 'v': 11, 'f': 12, 'r': 13 }; /** * Finds character representations in str and convert all to * their respective characters * * @param {String} str * @return {String} */ exports.strToChars = function(str) { /* jshint maxlen: false */ var chars_regex = /(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z\[\\\]\^?])|([0tnvfr]))/g; str = str.replace(chars_regex, function(s, b, lbs, a16, b16, c8, dctrl, eslsh) { if (lbs) { return s; } var code = b ? 8 : a16 ? parseInt(a16, 16) : b16 ? parseInt(b16, 16) : c8 ? parseInt(c8, 8) : dctrl ? CTRL.indexOf(dctrl) : SLSH[eslsh]; var c = String.fromCharCode(code); // Escape special regex characters. if (/[\[\]{}\^$.|?*+()]/.test(c)) { c = '\\' + c; } return c; }); return str; }; /** * turns class into tokens * reads str until it encounters a ] not preceeded by a \ * * @param {String} str * @param {String} regexpStr * @return {Array.<Array.<Object>, Number>} */ exports.tokenizeClass = function(str, regexpStr) { /* jshint maxlen: false */ var tokens = []; var regexp = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?(.)/g; var rs, c; while ((rs = regexp.exec(str)) != null) { if (rs[1]) { tokens.push(sets.words()); } else if (rs[2]) { tokens.push(sets.ints()); } else if (rs[3]) { tokens.push(sets.whitespace()); } else if (rs[4]) { tokens.push(sets.notWords()); } else if (rs[5]) { tokens.push(sets.notInts()); } else if (rs[6]) { tokens.push(sets.notWhitespace()); } else if (rs[7]) { tokens.push({ type: types.RANGE, from: (rs[8] || rs[9]).charCodeAt(0), to: rs[10].charCodeAt(0), }); } else if (c = rs[12]) { tokens.push({ type: types.CHAR, value: c.charCodeAt(0), }); } else { return [tokens, regexp.lastIndex]; } } exports.error(regexpStr, 'Unterminated character class'); }; /** * Shortcut to throw errors. * * @param {String} regexp * @param {String} msg */ exports.error = function(regexp, msg) { throw new SyntaxError('Invalid regular expression: /' + regexp + '/: ' + msg); }; }); var util_1 = util.strToChars; var util_2 = util.tokenizeClass; var util_3 = util.error; var wordBoundary = function() { return { type: types.POSITION, value: 'b' }; }; var nonWordBoundary = function() { return { type: types.POSITION, value: 'B' }; }; var begin = function() { return { type: types.POSITION, value: '^' }; }; var end = function() { return { type: types.POSITION, value: '$' }; }; var positions = { wordBoundary: wordBoundary, nonWordBoundary: nonWordBoundary, begin: begin, end: end }; var lib = function(regexpStr) { var i = 0, l, c, start = { type: types.ROOT, stack: []}, // Keep track of last clause/group and stack. lastGroup = start, last = start.stack, groupStack = []; var repeatErr = function(i) { util.error(regexpStr, 'Nothing to repeat at column ' + (i - 1)); }; // Decode a few escaped characters. var str = util.strToChars(regexpStr); l = str.length; // Iterate through each character in string. while (i < l) { c = str[i++]; switch (c) { // Handle escaped characters, inclues a few sets. case '\\': c = str[i++]; switch (c) { case 'b': last.push(positions.wordBoundary()); break; case 'B': last.push(positions.nonWordBoundary()); break; case 'w': last.push(sets.words()); break; case 'W': last.push(sets.notWords()); break; case 'd': last.push(sets.ints()); break; case 'D': last.push(sets.notInts()); break; case 's': last.push(sets.whitespace()); break; case 'S': last.push(sets.notWhitespace()); break; default: // Check if c is integer. // In which case it's a reference. if (/\d/.test(c)) { last.push({ type: types.REFERENCE, value: parseInt(c, 10) }); // Escaped character. } else { last.push({ type: types.CHAR, value: c.charCodeAt(0) }); } } break; // Positionals. case '^': last.push(positions.begin()); break; case '$': last.push(positions.end()); break; // Handle custom sets. case '[': // Check if this class is 'anti' i.e. [^abc]. var not; if (str[i] === '^') { not = true; i++; } else { not = false; } // Get all the characters in class. var classTokens = util.tokenizeClass(str.slice(i), regexpStr); // Increase index by length of class. i += classTokens[1]; last.push({ type: types.SET, set: classTokens[0], not: not, }); break; // Class of any character except \n. case '.': last.push(sets.anyChar()); break; // Push group onto stack. case '(': // Create group. var group = { type: types.GROUP, stack: [], remember: true, }; c = str[i]; // If if this is a special kind of group. if (c === '?') { c = str[i + 1]; i += 2; // Match if followed by. if (c === '=') { group.followedBy = true; // Match if not followed by. } else if (c === '!') { group.notFollowedBy = true; } else if (c !== ':') { util.error(regexpStr, 'Invalid group, character \'' + c + '\' after \'?\' at column ' + (i - 1)); } group.remember = false; } // Insert subgroup into current group stack. last.push(group); // Remember the current group for when the group closes. groupStack.push(lastGroup); // Make this new group the current group. lastGroup = group; last = group.stack; break; // Pop group out of stack. case ')': if (groupStack.length === 0) { util.error(regexpStr, 'Unmatched ) at column ' + (i - 1)); } lastGroup = groupStack.pop(); // Check if this group has a PIPE. // To get back the correct last stack. last = lastGroup.options ? lastGroup.options[lastGroup.options.length - 1] : lastGroup.stack; break; // Use pipe character to give more choices. case '|': // Create array where options are if this is the first PIPE // in this clause. if (!lastGroup.options) { lastGroup.options = [lastGroup.stack]; delete lastGroup.stack; } // Create a new stack and add to options for rest of clause. var stack = []; lastGroup.options.push(stack); last = stack; break; // Repetition. // For every repetition, remove last element from last stack // then insert back a RANGE object. // This design is chosen because there could be more than // one repetition symbols in a regex i.e. `a?+{2,3}`. case '{': var rs = /^(\d+)(,(\d+)?)?\}/.exec(str.slice(i)), min, max; if (rs !== null) { if (last.length === 0) { repeatErr(i); } min = parseInt(rs[1], 10); max = rs[2] ? rs[3] ? parseInt(rs[3], 10) : Infinity : min; i += rs[0].length; last.push({ type: types.REPETITION, min: min, max: max, value: last.pop(), }); } else { last.push({ type: types.CHAR, value: 123, }); } break; case '?': if (last.length === 0) { repeatErr(i); } last.push({ type: types.REPETITION, min: 0, max: 1, value: last.pop(), }); break; case '+': if (last.length === 0) { repeatErr(i); } last.push({ type: types.REPETITION, min: 1, max: Infinity, value: last.pop(), }); break; case '*': if (last.length === 0) { repeatErr(i); } last.push({ type: types.REPETITION, min: 0, max: Infinity, value: last.pop(), }); break; // Default is a character that is not `\[](){}?+*^$`. default: last.push({ type: types.CHAR, value: c.charCodeAt(0), }); } } // Check if any groups have not been closed. if (groupStack.length !== 0) { util.error(regexpStr, 'Unterminated group'); } return start; }; var types_1$1 = types; lib.types = types_1$1; //protected helper class function _SubRange(low, high) { this.low = low; this.high = high; this.length = 1 + high - low; } _SubRange.prototype.overlaps = function (range) { return !(this.high < range.low || this.low > range.high); }; _SubRange.prototype.touches = function (range) { return !(this.high + 1 < range.low || this.low - 1 > range.high); }; //returns inclusive combination of _SubRanges as a _SubRange _SubRange.prototype.add = function (range) { return this.touches(range) && new _SubRange(Math.min(this.low, range.low), Math.max(this.high, range.high)); }; //returns subtraction of _SubRanges as an array of _SubRanges (there's a case where subtraction divides it in 2) _SubRange.prototype.subtract = function (range) { if (!this.overlaps(range)) return false; if (range.low <= this.low && range.high >= this.high) return []; if (range.low > this.low && range.high < this.high) return [new _SubRange(this.low, range.low - 1), new _SubRange(range.high + 1, this.high)]; if (range.low <= this.low) return [new _SubRange(range.high + 1, this.high)]; return [new _SubRange(this.low, range.low - 1)]; }; _SubRange.prototype.toString = function () { if (this.low == this.high) return this.low.toString(); return this.low + '-' + this.high; }; _SubRange.prototype.clone = function () { return new _SubRange(this.low, this.high); }; function DiscontinuousRange(a, b) { if (this instanceof DiscontinuousRange) { this.ranges = []; this.length = 0; if (a !== undefined) this.add(a, b); } else { return new DiscontinuousRange(a, b); } } function _update_length(self) { self.length = self.ranges.reduce(function (previous, range) {return previous + range.length}, 0); } DiscontinuousRange.prototype.add = function (a, b) { var self = this; function _add(subrange) { var new_ranges = []; var i = 0; while (i < self.ranges.length && !subrange.touches(self.ranges[i])) { new_ranges.push(self.ranges[i].clone()); i++; } while (i < self.ranges.length && subrange.touches(self.ranges[i])) { subrange = subrange.add(self.ranges[i]); i++; } new_ranges.push(subrange); while (i < self.ranges.length) { new_ranges.push(self.ranges[i].clone()); i++; } self.ranges = new_ranges; _update_length(self); } if (a instanceof DiscontinuousRange) { a.ranges.forEach(_add); } else { if (a instanceof _SubRange) { _add(a); } else { if (b === undefined) b = a; _add(new _SubRange(a, b)); } } return this; }; DiscontinuousRange.prototype.subtract = function (a, b) { var self = this; function _subtract(subrange) { var new_ranges = []; var i = 0; while (i < self.ranges.length && !subrange.overlaps(self.ranges[i])) { new_ranges.push(self.ranges[i].clone()); i++; } while (i < self.ranges.length && subrange.overlaps(self.ranges[i])) { new_ranges = new_ranges.concat(self.ranges[i].subtract(subrange)); i++; } while (i < self.ranges.length) { new_ranges.push(self.ranges[i].clone()); i++; } self.ranges = new_ranges; _update_length(self); } if (a instanceof DiscontinuousRange) { a.ranges.forEach(_subtract); } else { if (a instanceof _SubRange) { _subtract(a); } else { if (b === undefined) b = a; _subtract(new _SubRange(a, b)); } } return this; }; DiscontinuousRange.prototype.index = function (index) { var i = 0; while (i < this.ranges.length && this.ranges[i].length <= index) { index -= this.ranges[i].length; i++; } if (i >= this.ranges.length) return null; return this.ranges[i].low + index; }; DiscontinuousRange.prototype.toString = function () { return '[ ' + this.ranges.join(', ') + ' ]' }; DiscontinuousRange.prototype.clone = function () { return new DiscontinuousRange(this); }; var discontinuousRange = DiscontinuousRange; var randexp = createCommonjsModule(function (module) { var types = lib.types; /** * If code is alphabetic, converts to other case. * If not alphabetic, returns back code. * * @param {Number} code * @return {Number} */ function toOtherCase(code) { return code + (97 <= code && code <= 122 ? -32 : 65 <= code && code <= 90 ? 32 : 0); } /** * Randomly returns a true or false value. * * @return {Boolean} */ function randBool() { return !this.randInt(0, 1); } /** * Randomly selects and returns a value from the array. * * @param {Array.<Object>} arr * @return {Object} */ function randSelect(arr) { if (arr instanceof discontinuousRange) { return arr.index(this.randInt(0, arr.length - 1)); } return arr[this.randInt(0, arr.length - 1)]; } /** * expands a token to a DiscontinuousRange of characters which has a * length and an index function (for random selecting) * * @param {Object} token * @return {DiscontinuousRange} */ function expand(token) { if (token.type === lib.types.CHAR) { return new discontinuousRange(token.value); } else if (token.type === lib.types.RANGE) { return new discontinuousRange(token.from, token.to); } else { var drange = new discontinuousRange(); for (var i = 0; i < token.set.length; i++) { var subrange = expand.call(this, token.set[i]); drange.add(subrange); if (this.ignoreCase) { for (var j = 0; j < subrange.length; j++) { var code = subrange.index(j); var otherCaseCode = toOtherCase(code); if (code !== otherCaseCode) { drange.add(otherCaseCode); } } } } if (token.not) { return this.defaultRange.clone().subtract(drange); } else { return drange; } } } /** * Checks if some custom properties have been set for this regexp. * * @param {RandExp} randexp * @param {RegExp} regexp */ function checkCustom(randexp, regexp) { if (typeof regexp.max === 'number') { randexp.max = regexp.max; } if (regexp.defaultRange instanceof discontinuousRange) { randexp.defaultRange = regexp.defaultRange; } if (typeof regexp.randInt === 'function') { randexp.randInt = regexp.randInt; } } /** * @constructor * @param {RegExp|String} regexp * @param {String} m */ var RandExp = module.exports = function(regexp, m) { this.defaultRange = this.defaultRange.clone(); if (regexp instanceof RegExp) { this.ignoreCase = regexp.ignoreCase; this.multiline = regexp.multiline; checkCustom(this, regexp); regexp = regexp.source; } else if (typeof regexp === 'string') { this.ignoreCase = m && m.indexOf('i') !== -1; this.multiline = m && m.indexOf('m') !== -1; } else { throw new Error('Expected a regexp or string'); } this.tokens = lib(regexp); }; // When a repetitional token has its max set to Infinite, // randexp won't actually generate a random amount between min and Infinite // instead it will see Infinite as min + 100. RandExp.prototype.max = 100; // Generates the random string. RandExp.prototype.gen = function() { return gen.call(this, this.tokens, []); }; // Enables use of randexp with a shorter call. RandExp.randexp = function(regexp, m) { var randexp; if (regexp._randexp === undefined) { randexp = new RandExp(regexp, m); regexp._randexp = randexp; } else { randexp = regexp._randexp; } checkCustom(randexp, regexp); return randexp.gen(); }; // This enables sugary /regexp/.gen syntax. RandExp.sugar = function() { /* jshint freeze:false */ RegExp.prototype.gen = function() { return RandExp.randexp(this); }; }; // This allows expanding to include additional characters // for instance: RandExp.defaultRange.add(0, 65535); RandExp.prototype.defaultRange = new discontinuousRange(32, 126); /** * Randomly generates and returns a number between a and b (inclusive). * * @param {Number} a * @param {Number} b * @return {Number} */ RandExp.prototype.randInt = function(a, b) { return a + Math.floor(Math.random() * (1 + b - a)); }; /** * Generate random string modeled after given tokens. * * @param {Object} token * @param {Array.<String>} groups * @return {String} */ function gen(token, groups) { var stack, str, n, i, l; switch (token.type) { case types.ROOT: case types.GROUP: // Ignore lookaheads for now. if (token.followedBy || token.notFollowedBy) { return ''; } // Insert placeholder until group string is generated. if (token.remember && token.groupNumber === undefined) { token.groupNumber = groups.push(null) - 1; } stack = token.options ? randSelect.call(this, token.options) : token.stack; str = ''; for (i = 0, l = stack.length; i < l; i++) { str += gen.call(this, stack[i], groups); } if (token.remember) { groups[token.groupNumber] = str; } return str; case types.POSITION: // Do nothing for now. return ''; case types.SET: var expandedSet = expand.call(this, token); if (!expandedSet.length) { return ''; } return String.fromCharCode(randSelect.call(this, expandedSet)); case types.REPETITION: // Randomly generate number between min and max. n = this.randInt(token.min, token.max === Infinity ? token.min + this.max : token.max); str = ''; for (i = 0; i < n; i++) { str += gen.call(this, token.value, groups); } return str; case types.REFERENCE: return groups[token.value - 1] || ''; case types.CHAR: var code = this.ignoreCase && randBool.call(this) ? toOtherCase(token.value) : token.value; return String.fromCharCode(code); } } }); // 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'; } var helpers = { isURL: isURL, parseURI: parseURI, isKeyword: isKeyword, resolveURL: resolveURL, getDocumentURI: getDocumentURI }; var findReference = createCommonjsModule(function (module) { 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[helpers.getDocumentURI(id)]; try { if (target) { target = id.indexOf('#/') > -1 ? get(target, id) : target; } else { for (var key in refs) { if (helpers.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; }; }); var deepExtend_1 = createCommonjsModule(function (module) { function isSpecificValue(val) { return ( val instanceof Buffer || val instanceof Date || val instanceof RegExp ) ? true : false; } function cloneSpecificValue(val) { if (val instanceof Buffer) { var x = new Buffer(val.length); val.copy(x); return x; } else if (val instanceof Date) { return new Date(val.getTime()); } else if (val instanceof RegExp) { return new RegExp(val); } else { throw new Error('Unexpected situation'); } } /** * Recursive cloning array. */ function deepCloneArray(arr) { var clone = []; arr.forEach(function (item, index) { if (typeof item === 'object' && item !== null) { if (Array.isArray(item)) { clone[index] = deepCloneArray(item); } else if (isSpecificValue(item)) { clone[index] = cloneSpecificValue(item); } else { clone[index] = deepExtend({}, item); } } else { clone[index] = item; } }); return clone; } /** * Extening object that entered in first argument. * * Returns extended object or false if have no target object or incorrect type. * * If you wish to clone source object (without modify it), just use empty new * object as first argument, like this: * deepExtend({}, yourObj_1, [yourObj_N]); */ var deepExtend = module.exports = function (/*obj_1, [obj_2], [obj_N]*/) { if (arguments.length < 1 || typeof arguments[0] !== 'object') { return false; } if (arguments.length < 2) { return arguments[0]; } var target = arguments[0]; // convert arguments to array and cut off target object var args = Array.prototype.slice.call(arguments, 1); var val, src; args.forEach(function (obj) { // skip argument if isn't an object, is null, or is an array if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) { return; } Object.keys(obj).forEach(function (key) { src = target[key]; // source value val = obj[key]; // new value // recursion prevention if (val === target) { return; /** * if new value isn't object then just overwrite by new value * instead of extending. */ } else if (typeof val !== 'object' || val === null) { target[key] = val; return; // just clone arrays (and recursive clone objects inside) } else if (Array.isArray(val)) { target[key] = deepCloneArray(val); return; // custom cloning and overwrite for specific objects } else if (isSpecificValue(val)) { target[key] = cloneSpecificValue(val); return; // overwrite by new value if source isn't object or array } else if (typeof src !== 'object' || src === null || Array.isArray(src)) { target[key] = deepExtend({}, val); return; // source value and new value is objects both, extending... } else { target[key] = deepExtend(src, val); return; } }); }); return target; }; }); function copy(_, obj, refs, parent, resolve, callback) { var target = Array.isArray(obj) ? [] : {}; if (typeof obj.$ref === 'string') { var id = obj.$ref; var base = helpers.getDocumentURI(id); var local = id.indexOf('#/') > -1; if (local || (resolve && base !== parent)) { var fixed = findReference(id, refs, callback); deepExtend_1(obj, fixed); delete obj.$ref; delete obj.id; } if (_[id]) { return obj; } _[id] = 1; } for (var prop in obj) { if (typeof obj[prop] === 'object' && obj[prop] !== null && !helpers.isKeyword(prop)) { target[prop] = copy(_, obj[prop], refs, parent, resolve, callback); } else { target[prop] = obj[prop]; } } return target; } var resolveSchema = function(obj, refs, resolve, callback) { var fixedId = helpers.resolveURL(obj.$schema, obj.id), parent = helpers.getDocumentURI(fixedId); return copy({}, obj, refs, parent, resolve, callback); }; var cloneObj = createCommonjsModule(function (module) { 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; }; }); var SCHEMA_URI = [ 'http://json-schema.org/schema#', 'http://json-schema.org/draft-04/schema#' ]; function expand(obj, parent, callback) { if (obj) { var id = typeof obj.id === 'string' ? obj.id : '#'; if (!helpers.isURL(id)) { id = helpers.resolveURL(parent === id ? null : parent, id); } if (typeof obj.$ref === 'string' && !helpers.isURL(obj.$ref)) { obj.$ref = helpers.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 && !helpers.isKeyword(key)) { expand(value, parent, callback); } } if (typeof callback === 'function') { callback(obj); } } var normalizeSchema = 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 = helpers.resolveURL(copy.$schema || SCHEMA_URI[0], base); expand(copy, helpers.resolveURL(copy.id || '#', base), push); copy.id = copy.id || base; return copy; }; var lib$1 = createCommonjsModule(function (module) { helpers.findByRef = findReference; helpers.resolveSchema = resolveSchema; helpers.normalizeSchema = normalizeSchema; 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 = helpers.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 = helpers.normalizeSchema(fakeroot, ref, push); push(schema); }); return helpers.resolveSchema(schema, $ref.refs, ex, f); } $ref.refs = {}; $ref.util = helpers; return $ref; }; instance.util = helpers; }); var jsonpath = createCommonjsModule(function (module, exports) { /*! jsonpath 1.0.0 */ (function(f){{module.exports=f();}})(function(){var define;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof commonjsRequire=="function"&&commonjsRequire;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND", f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r);}return n[o].exports}var i=typeof commonjsRequire=="function"&&commonjsRequire;for(var o=0;o<r.length;o++)s(r[o]);return s})({"./aesprim":[function(require,module,exports){ /* Copyright (C) 2013 Ariya Hidayat <ariya.hidayat@gmail.com> Copyright (C) 2013 Thaddee Tyl <thaddee.tyl@gmail.com> Copyright (C) 2013 Mathias Bynens <mathias@qiwi.be> Copyright (C) 2012 Ariya Hidayat <ariya.hidayat@gmail.com> Copyright (C) 2012 Mathias Bynens <mathias@qiwi.be> Copyright (C) 2012 Joost-Wim Boekesteijn <joost-wim@boekesteijn.nl> Copyright (C) 2012 Kris Kowal <kris.kowal@cixar.com> Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com> Copyright (C) 2012 Arpad Borsos <arpad.borsos@googlemail.com> Copyright (C) 2011 Ariya Hidayat <ariya.hidayat@gmail.com> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /*jslint bitwise:true plusplus:true */ /*global esprima:true, define:true, exports:true, window: true, throwErrorTolerant: true, throwError: true, generateStatement: true, peek: true, parseAssignmentExpression: true, parseBlock: true, parseExpression: true, parseFunctionDeclaration: true, parseFunctionExpression: true, parseFunctionSourceElements: true, parseVariableIdentifier: true, parseLeftHandSideExpression: true, parseUnaryExpression: true, parseStatement: true, parseSourceElement: true */ (function (root, factory) { // Universal Module Definition (UMD) to support AMD, CommonJS/Node.js, // Rhino, and plain browser loading. /* istanbul ignore next */ if (typeof define === 'function' && define.amd) { define(['exports'], factory); } else if (typeof exports !== 'undefined') { factory(exports); } else { factory((root.esprima = {})); } }(this, function (exports) { var Token, TokenName, FnExprTokens, Syntax, PropertyKind, Messages, Regex, SyntaxTreeDelegate, source, strict, index, lineNumber, lineStart, length, delegate, lookahead, state, extra; Token = { BooleanLiteral: 1, EOF: 2, Identifier: 3, Keyword: 4, NullLiteral: 5, NumericLiteral: 6, Punctuator: 7, StringLiteral: 8, RegularExpression: 9 }; TokenName = {}; TokenName[Token.BooleanLiteral] = 'Boolean'; TokenName[Token.EOF]