function a(a,d){return g(a)||f(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(b,c){if(b){if("string"==typeof b)return d(b,c);var a={}.toString.call(b).slice(8,-1);return"Object"===a&&b.constructor&&(a=b.constructor.name),"Map"===a||"Set"===a?Array.from(b):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?d(b,c):void 0}}function d(b,c){(null==c||c>b.length)&&(c=b.length);for(var d=0,f=Array(c);d<c;d++)f[d]=b[d];return f}function f(b,c){var d=null==b?null:"undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(null!=d){var g,h,j,k,l=[],a=!0,m=!1;try{if(j=(d=d.call(b)).next,0===c){if(Object(d)!==d)return;a=!1}else for(;!(a=(g=j.call(d)).done)&&(l.push(g.value),l.length!==c);a=!0);}catch(a){m=!0,h=a}finally{try{if(!a&&null!=d["return"]&&(k=d["return"](),Object(k)!==k))return}finally{if(m)throw h}}return l}}function g(a){if(Array.isArray(a))return a}function h(a){"@babel/helpers - typeof";return h="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},h(a)}function i(b,a){if(!(b instanceof a))throw new TypeError("Cannot call a class as a function")}function j(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,l(c.key),c)}function k(a,b,c){return b&&j(a.prototype,b),c&&j(a,c),Object.defineProperty(a,"prototype",{writable:!1}),a}function l(a){var b=m(a,"string");return"symbol"==h(b)?b:b+""}function m(a,b){if("object"!=h(a)||!a)return a;var c=a[Symbol.toPrimitive];if(void 0!==c){var d=c.call(a,b||"default");if("object"!=h(d))return d;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===b?String:Number)(a)}function n(a,b,c){return b=s(b),p(a,r()?Reflect.construct(b,c||[],s(a).constructor):b.apply(a,c))}function p(a,b){if(b&&("object"==h(b)||"function"==typeof b))return b;if(void 0!==b)throw new TypeError("Derived constructors may only return object or undefined");return q(a)}function q(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function r(){try{var a=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(a){}return(r=function(){return!!a})()}function s(a){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},s(a)}function t(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),b&&u(a,b)}function u(a,b){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(a,b){return a.__proto__=b,a},u(a,b)}import{get as v}from"lodash";import w from"./api-common.ts";var x=function(b){function c(){return i(this,c),n(this,c,arguments)}return t(c,b),k(c,[{key:"isSupported",value:function(a){return!!(a&&"object"===h(a))&&!!a.swagger}},{key:"getEndpoints",value:function(a){if(!a||!this.isSupported(a))return[];var b=[];if(a.endpoint)b=b.concat({url:a.endpoint});else if(a["x-ibm-configuration"]&&a["x-ibm-configuration"].servers&&0<a["x-ibm-configuration"].servers.length)for(var c=0;c<a["x-ibm-configuration"].servers.length;c+=1)b=b.concat({url:a["x-ibm-configuration"].servers[c].url,types:this.getEndpointTypes(a["x-ibm-configuration"].servers[c].type)});else if(a["x-ibm-configuration"]&&a["x-ibm-configuration"]["graphql-server-config"]&&a["x-ibm-configuration"]["graphql-server-config"]["server-url"])b=b.concat({url:a["x-ibm-configuration"]["graphql-server-config"]["server-url"],types:null});else if(a["x-ibm-endpoints"]&&0<a["x-ibm-endpoints"].length)for(var d,e=0;e<a["x-ibm-endpoints"].length;e+=1)d=a["x-ibm-endpoints"][e].endpointUrl,a.basePath&&(d+=a.basePath),b=b.concat({url:d,types:this.getEndpointTypes(a["x-ibm-endpoints"][e].type)});else if(a.swagger){var f="";f=a.host?a.host:window.location.host;var g="://".concat(f);if(a.schemes)for(var h,j=0;j<a.schemes.length;j+=1)h=a.schemes[j]+g,a.basePath&&(h+=a.basePath),b=b.concat({url:h,types:null});else{var k="https".concat(g);a.basePath&&(k+=a.basePath),b=b.concat({url:k,types:null})}}for(var l in b)Object.prototype.hasOwnProperty.call(b,l)&&(b[l].url=this.resolveRelativeUrl(b[l].url));return b}},{key:"getBodyParameter",value:function(a,b,c,d){if(a&&d&&this.isSupported(d)&&d.swagger){var e=this.getParameters(a,b,c,d),f=Object.keys(e).filter(function(a){return"body"===e[a]["in"]});if(0<f.length)return e[f[0]]}}},{key:"getSchemas",value:function(a){return a&&this.isSupported(a)?a.definitions:void 0}},{key:"getSchemasFullPath",value:function(a){return a&&this.isSupported(a)?{definitions:a.definitions}:void 0}},{key:"getSchemasRoot",value:function(a){var b=null;return a.definitions&&(b=a.definitions),b}},{key:"getSecurityDefinitions",value:function(b){var c=this.api.securityDefinitions;if(c){var d=v(this.api,"x-ibm-configuration.oauth-servers");return d&&(c=JSON.parse(JSON.stringify(c)),Object.entries(d).forEach(function(b){var d=a(b,2),e=d[0],f=d[1];c[e]&&(c[e].tokenUrl=f.tokenUrls,c[e].authorizationUrl=f.authorizationUrls,c[e].refreshUrl=f.refreshUrls)})),b&&(c=this.resolveOauthUrls(c,b)),c}}},{key:"getContentTypes",value:function(a,b){if(!a||!b||!this.isSupported(b))return[];var c=[];if(b.swagger&&(a.consumes&&0<a.consumes.length?c=a.consumes:b.consumes&&(c=b.consumes)),c=JSON.parse(JSON.stringify(c)),0===c.length&&b["x-ibm-configuration"]){if(!a.parameters)return c;a.parameters.forEach(function(a){"formData"===a["in"]&&c.push("application/x-www-form-urlencoded"),"body"===a["in"]&&(b["x-ibm-configuration"].enforced?(c.push("application/json"),c.push("application/xml")):c.push("application/json"))})}return c}},{key:"getSecurityFlowConfig",value:function(a,b,c,d){var e=this;if(!a)return null;var f=this.getSecurityFlowConfigDefaults();return Object.keys(a).forEach(function(c){if(e.securityDefinitionFound(b,c)){var g=b[c],h=a[c];f=e.setApikeySecurityTypeConfig(f,g),f=e.setBasicSecurityTypeConfig(f,g),f=e.setOauthSecurityTypeConfig(f,g,h,d)}}),f=this.setRemainingConfig(f,c),f}},{key:"setBasicSecurityTypeConfig",value:function(a,b){return"basic"===b.type&&(a.requiresBasicAuth=!0),a}},{key:"setOauthSecurityTypeConfig",value:function(a,b,c,d){if("oauth2"===b.type){a.requiresOauth=!0,a.requiresClientId=!0,a.oauthFlow=b.flow,("application"===b.flow||"accessCode"===b.flow||"password"===b.flow)&&(a.requiresClientSecret=!0),("implicit"===b.flow||"accessCode"===b.flow)&&(a.requiresRedirectUri=!0);var e=this.getFullOauthUrls(b,d);if(b.authorizationUrl&&(a.oauthAuthUrl=e.authorizationUrl,a.requiresAuthorizationSection=!0),b.tokenUrl&&(a.oauthTokenUrl=e.tokenUrl,a.requiresAuthorizationSection=!0),b.scopes&&0<Object.keys(b.scopes).length&&0<c.length)for(var f in a.oauthScopes=[],b.scopes)0!==f.indexOf("x-")&&-1<c.indexOf(f)&&a.oauthScopes.push(f)}return a}},{key:"getAccepts",value:function(a,b){if(!a||!b||!this.isSupported(b))return[];var c=[];return b.swagger&&(a.produces&&0<a.produces.length?c=a.produces:b.produces&&(c=b.produces)),c=JSON.parse(JSON.stringify(c)),0===c.length&&(b["x-ibm-configuration"]&&b["x-ibm-configuration"].enforced?(c.push("application/json"),c.push("application/xml")):c.push("application/json")),c}}])}(w);export{x as default};