UNPKG

oas

Version:

Comprehensive tooling for working with OpenAPI definitions

89 lines (73 loc) 4 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/extensions.ts var CODE_SAMPLES = "code-samples"; var EXPLORER_ENABLED = "explorer-enabled"; var HEADERS = "headers"; var METRICS_ENABLED = "metrics-enabled"; var OAUTH_OPTIONS = "oauth-options"; var PARAMETER_ORDERING = "parameter-ordering"; var PROXY_ENABLED = "proxy-enabled"; var SAMPLES_LANGUAGES = "samples-languages"; var SIMPLE_MODE = "simple-mode"; var DISABLE_TAG_SORTING = "disable-tag-sorting"; var extensionDefaults = { [CODE_SAMPLES]: void 0, [DISABLE_TAG_SORTING]: false, [EXPLORER_ENABLED]: true, [HEADERS]: void 0, [METRICS_ENABLED]: true, [OAUTH_OPTIONS]: {}, [PARAMETER_ORDERING]: ["path", "query", "body", "cookie", "form", "header"], [PROXY_ENABLED]: true, [SAMPLES_LANGUAGES]: ["shell", "node", "ruby", "php", "python", "java", "csharp"], [SIMPLE_MODE]: true }; function hasRootExtension(extension, api) { return Boolean(api && extension in api); } function getExtension(extension, api, operation) { if (operation) { if (operation.hasExtension("x-readme")) { const data = operation.getExtension("x-readme"); if (data && typeof data === "object" && extension in data) { return data[extension]; } } if (operation.hasExtension(`x-${extension}`)) { return operation.getExtension(`x-${extension}`); } else if (operation.hasExtension(extension)) { return operation.getExtension(extension); } } if (extension === CODE_SAMPLES) { return extensionDefaults[extension]; } if (hasRootExtension("x-readme", api)) { const data = _optionalChain([api, 'optionalAccess', _ => _["x-readme"]]); if (data && typeof data === "object" && extension in data) { return data[extension]; } } if (hasRootExtension(`x-${extension}`, api)) { return _optionalChain([api, 'optionalAccess', _2 => _2[`x-${extension}`]]); } else if (hasRootExtension(extension, api)) { return _optionalChain([api, 'optionalAccess', _3 => _3[extension]]); } if (extension in extensionDefaults) { return extensionDefaults[extension]; } return void 0; } function validateParameterOrdering(ordering, extension) { const defaultValue = extensionDefaults[PARAMETER_ORDERING]; const requiredLength = defaultValue.length; const defaultsHuman = `${defaultValue.slice(0, -1).join(", ")}, and ${defaultValue.slice(-1)}`; if (ordering.length !== requiredLength) { throw new TypeError(`"${extension}" must contain ${requiredLength} items comprised of: ${defaultsHuman}`); } const intersection = ordering.filter((value) => defaultValue.includes(value.toLowerCase())); if (intersection.length !== requiredLength) { throw new TypeError(`"${extension}" must contain ${requiredLength} items comprised of: ${defaultsHuman}`); } } exports.CODE_SAMPLES = CODE_SAMPLES; exports.EXPLORER_ENABLED = EXPLORER_ENABLED; exports.HEADERS = HEADERS; exports.METRICS_ENABLED = METRICS_ENABLED; exports.OAUTH_OPTIONS = OAUTH_OPTIONS; exports.PARAMETER_ORDERING = PARAMETER_ORDERING; exports.PROXY_ENABLED = PROXY_ENABLED; exports.SAMPLES_LANGUAGES = SAMPLES_LANGUAGES; exports.SIMPLE_MODE = SIMPLE_MODE; exports.DISABLE_TAG_SORTING = DISABLE_TAG_SORTING; exports.extensionDefaults = extensionDefaults; exports.hasRootExtension = hasRootExtension; exports.getExtension = getExtension; exports.validateParameterOrdering = validateParameterOrdering; //# sourceMappingURL=chunk-XS7VDTTT.cjs.map