"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.rewriteOpenApi=i;function a(a,d){return f(a)||e(a,d)||c(a,d)||b()}function b(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function c(a,b){if(a){if("string"==typeof a)return d(a,b);var c=Object.prototype.toString.call(a).slice(8,-1);return"Object"===c&&a.constructor&&(c=a.constructor.name),"Map"===c||"Set"===c?Array.from(a):"Arguments"===c||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(c)?d(a,b):void 0}}function d(a,b){(null==b||b>a.length)&&(b=a.length);for(var c=0,d=Array(b);c<b;c++)d[c]=a[c];return d}function e(a,b){var c=null==a?null:"undefined"!=typeof Symbol&&a[Symbol.iterator]||a["@@iterator"];if(null!=c){var d,e,f=[],g=!0,h=!1;try{for(c=c.call(a);!(g=(d=c.next()).done)&&(f.push(d.value),!(b&&f.length===b));g=!0);}catch(a){h=!0,e=a}finally{try{g||null==c["return"]||c["return"]()}finally{if(h)throw e}}return f}}function f(a){if(Array.isArray(a))return a}var g="https://$(catalog.url)",h="$(catalog.url)";function i(b,c){var d=JSON.parse(JSON.stringify(b));delete d["x-ibm-endpoints"],d["x-ibm-configuration"].servers&&delete d["x-ibm-configuration"].servers;var e=c.endpointUrl.split("://"),f=a(e,2),i=f[0],j=f[1],k="",l="";return j&&(0<=j.indexOf("/")?(k=j.substring(0,j.indexOf("/")),l=j.substring(j.indexOf("/"))):k=j,d.schemes=[i],d.host=k,d.basePath=l+d.basePath),d.securityDefinitions&&Object.keys(d.securityDefinitions).filter(function(a){return"oauth2"===d.securityDefinitions[a].type}).forEach(function(a){var b=d.securityDefinitions[a];b.authorizationUrl&&0<=b.authorizationUrl.indexOf(g)?b.authorizationUrl=b.authorizationUrl.replace(g,c.endpointUrl):b.authorizationUrl&&0<=b.authorizationUrl.indexOf(h)&&(b.authorizationUrl=b.authorizationUrl.replace(h,c.endpointUrl)),b.tokenUrl&&0<=b.tokenUrl.indexOf(g)?b.tokenUrl=b.tokenUrl.replace(g,c.endpointUrl):b.tokenUrl&&0<=b.tokenUrl.indexOf(h)&&(b.tokenUrl=b.tokenUrl.replace(h,c.endpointUrl))}),d}