UNPKG

avantation

Version:

Build OpenAPI3.0 specification from HAR

60 lines (59 loc) 2.05 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Util = void 0; const tslib_1 = require("tslib"); const json_js_1 = tslib_1.__importDefault(require("./json.js")); var Util; (function (Util) { function generateSchema(input) { let schema = json_js_1.default(input); delete schema['$schema']; return schema; } Util.generateSchema = generateSchema; function arrayMaxDepth(input, depthLimit) { input != null && Object.keys(input).forEach(function (key) { if (input[key] instanceof Array) { input[key] = input[key].slice(0, depthLimit || 3); return; } if (typeof input[key] == 'object' && input[key] !== null) { arrayMaxDepth(input[key], depthLimit); } }); } Util.arrayMaxDepth = arrayMaxDepth; function buildWildCardRegex(wildCardString) { return new RegExp(`^${wildCardString.split('*').join('.*')}`); } Util.buildWildCardRegex = buildWildCardRegex; function inferHost(entries) { let inferred_host = ""; let inferred_host_count = 0; const host_frequency = new Map(); for (const entry of entries) { const host = new URL(entry.request.url).host; let frequency = 0; if (host_frequency.has(host)) { let f = host_frequency.get(host); if (f === undefined) { frequency = 1; } else { frequency = f + 1; } } else { frequency = 1; } host_frequency.set(host, frequency); if (frequency > inferred_host_count) { inferred_host_count = frequency; inferred_host = host; } } return inferred_host; } Util.inferHost = inferHost; })(Util = exports.Util || (exports.Util = {}));