apiconnect-explorer
Version:
- [Getting Started](#getting-started) - [Configuration](#configuration) * [Required](#required) * [Optional](#optional) - [Usage in React](#usage-in-react) - [Usage outside of React](#usage-outside-of-react) - [Detailed description of options](#detail
1 lines • 10 kB
JavaScript
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)}import{HTTPSnippet as i}from"@readme/httpsnippet";import j from"./templates/websocket-node.hbs";export function getGeneratedOptionsForOperation(a,b,c,d,e,f,g,h){var i=h.getDefaultContentTypeHeader(b,g);a.contenttype&&(i=a.contenttype);var j=h.getParameters(b,c,i,g);j=h.removeReservedParameters(j),a.parametersArray=[],Object.keys(j).forEach(function(b){a.parametersArray.push(j[b])});var k=b.security||g.security,l=h.getSecurityDefinitions();if(k&&l){var m=k[a.selectedSecurityOption],n=h.getSecurityFlowConfig(m,l,null,a.endpoint);a=Object.assign(a,n)}return b["x-ibm-soap"]&&b["x-ibm-soap"]["soap-action"]&&(a.soapAction=b["x-ibm-soap"]["soap-action"]),{api:g,operation:b,path:c,verb:d,config:a,clientId:"clientId",clientSecret:"clientSecret",languages:e,endpoint:a.endpoint,maxDepth:f,apiHandler:h}}function k(b,c,d,e,f,g,k,l,m,n,o,p){var q;if(g||(g="REPLACE_THIS_KEY"),k||(k="REPLACE_THIS_KEY"),n||(c&&d&&b.paths&&b.paths[c]&&b.paths[c][d]&&b.paths[c][d].servers?n=b.paths[c][d].servers[0].url:c&&b.paths&&b.paths[c]&&b.paths[c].servers?n=b.paths[c].servers[0].url:b.endpoint?n=b.endpoint:b["x-ibm-configuration"]&&b["x-ibm-configuration"].servers&&b["x-ibm-configuration"].servers[0]&&b["x-ibm-configuration"].servers[0].url?n=b["x-ibm-configuration"].servers[0].url:b["x-ibm-endpoints"]&&b["x-ibm-endpoints"][0]&&b["x-ibm-endpoints"][0].endpointUrl?(n=b["x-ibm-endpoints"][0].endpointUrl,n+=b.basePath?b.basePath:""):b.openapi&&b.servers&&b.servers[0]&&b.servers[0].url?n=b.servers[0].url:(n="://".concat(b.host),n=b.schemes?b.schemes[0]+n:"https".concat(n),n+=b.basePath?b.basePath:"")),"object"===h(n)){var r;for(var s in n)r=n[s];n=r}n=null===(q=n)||void 0===q?void 0:q.replace(/\/$/,"");var t,u=[],v=[],w=null;o||(o={}),f&&f.requiresClientId&&("query"===f.clientIdLocation?f.clientIdName?v.push({name:f.clientIdName,value:g}):v.push({name:"client_id",value:g}):"header"===f.clientIdLocation&&(f.clientIdName?u.push({name:f.clientIdName,value:g}):u.push({name:"X-IBM-Client-Id",value:g}))),f&&f.requiresClientSecret&&("query"===f.clientSecretLocation?f.clientSecretName?v.push({name:f.clientSecretName,value:k}):v.push({name:"client_secret",value:k}):"header"===f.clientSecretLocation&&(f.clientSecretName?u.push({name:f.clientSecretName,value:k}):u.push({name:"X-IBM-Client-Secret",value:k}))),f&&f.requiresBasicAuth&&(o.basicAuth?u.push({name:"Authorization",value:"Basic ".concat(o.basicAuth)}):u.push({name:"Authorization",value:"Basic REPLACE_BASIC_AUTH"})),f&&f.requiresOauth&&(o.oauthToken?u.push({name:"Authorization",value:"Bearer ".concat(o.oauthToken)}):u.push({name:"Authorization",value:"Bearer REPLACE_BEARER_TOKEN"})),f&&f.requiresHttpBearerToken&&(f.httpBearerToken?u.push({name:"Authorization",value:"Bearer ".concat(f.httpBearerToken)}):u.push({name:"Authorization",value:"Bearer REPLACE_BEARER_TOKEN"})),f&&f.requiresDigestAuth&&(f.httpDigestToken?u.push({name:"Authorization",value:"Digest ".concat(f.httpDigestToken)}):u.push({name:"Authorization",value:"Digest username=\"USERNAME_VALUE\", realm=\"REALM_URL\", nonce=\"NONCE_VALUE\", opaque=\"OPAQUE_VALUE\", response=\"HASHED_CREDS\""})),f&&f.requiresHobaAuth&&(f.httpHobaToken?u.push({name:"Authorization",value:"HOBA ".concat(f.httpHobaToken)}):u.push({name:"Authorization",value:"HOBA result=\"SIGNATURE_VALUE\""})),f&&f.requiresScramShaAuth&&(f.httpScramShaToken?u.push({name:"Authorization",value:"SCRAM-SHA-256 ".concat(f.httpScramShaToken)}):u.push({name:"Authorization",value:"SCRAM-SHA-256 sid=\"SID_VALUE\", data=\"ENCRYPTED_CREDS\""})),f&&f.requiresVapidAuth&&(f.httpVapidToken?u.push({name:"Authorization",value:"vapid ".concat(f.httpVapidToken)}):u.push({name:"Authorization",value:"vapid t=\"JSON_WEB_TOKEN\", k=\"JSON_WEB_KEY\""})),f&&f.requiresNegotiateAuth&&(f.httpNegotiateToken?u.push({name:"Authorization",value:"Negotiate ".concat(f.httpNegotiateToken)}):u.push({name:"Authorization",value:"Negotiate \"GSSAPI_MESSAGE_TEXT\""})),f&&f.requiresOAuthAuth&&(f.httpOAuthToken?u.push({name:"Authorization",value:"OAuth ".concat(f.httpOAuthToken)}):u.push({name:"Authorization",value:"OAuth realm=\"REALM_URL\", oauth_consumer_key=\"ACCESS_KEY\", oauth_token=\"TOKEN_STRING\", oauth_nonce=\"UNIQUELY GENERATED RANDOM STRING\", oauth_signature=\"SIGNATURE\", oauth_signature_method=\"HMAC-SHA256\", oauth_timestamp=\"EPOCH_SECONDS\", oauth_version=\"1.0\""})),f&&f.requiresMutualAuth&&(f.httpMutualToken?u.push({name:"Authorization",value:"Mutual ".concat(f.httpMutualToken)}):u.push({name:"Authorization",value:"Mutual version=\"VERSION_TOKEN\", sid=\"SESSION_ID\", nc=\"NONCE_VALUE\", vkc=\"AUTH_VERIFICATION_VALUE\""}));var x=p.getDefaultContentTypeHeader(e,b),y=p.getDefaultAcceptHeader(e,b);y=f.accept?f.accept:y,x=f.contenttype?f.contenttype:x;var z=p.getServerVariables(b,n,{path:c,method:d});z&&Object.keys(z).forEach(function(a){n=n.replace("{".concat(a,"}"),"REPLACE_".concat(a.toUpperCase(),"_VARIABLE"))});var A=p.getParameters(e,c,x,b),B=f.parametersArray;B||(B=[]);var C=B.filter(function(a){return"path"===a["in"]});0<C.length&&C.forEach(function(a){var b="REPLACE_".concat(a.name.toUpperCase());o[a.name]&&(b=o[a.name]),a["default"]?b=a["default"].toString():a["x-example"]&&(b=a["x-example"].toString()),c=c.replace("{".concat(a.name,"}"),b)});var D={},E=B.filter(function(a){return"query"===a["in"]});if(0<E.length&&E.forEach(function(a){var b,c="REPLACE_THIS_VALUE";if(o[a.name]&&(c=o[a.name]),a["default"]?c=a["default"].toString():a["x-example"]&&(c=a["x-example"].toString()),A[a.name]){var d,e;b=null!==(d=A[a.name].type)&&void 0!==d?d:null===(e=A[a.name])||void 0===e||null===(e=e.schema)||void 0===e?void 0:e.type}("object"===b||"array"===b)&&(c="REPLACE_".concat(a.name.toUpperCase()),D[a.name]=c),v.push({name:a.name,value:c})}),f.externalApiKeys&&0!==Object.keys(f.externalApiKeys).length)for(var F in f.externalApiKeys){var G=f.externalApiKeys[F],H="REPLACE_THIS_VALUE";o[G.name]&&(H=o[G.name]),"query"===G["in"]?v.push({name:G.name,value:H}):"header"===G["in"]&&u.push({name:G.name,value:H})}var I=n+c;if(f.soapAction){var J="/".concat(e.operationId);-1!==I.indexOf(J,I.length-J.length)&&(I=I.substring(0,I.length-J.length))}f.soapAction&&u.push({name:"SOAPAction",value:f.soapAction});var K=B.filter(function(a){return"header"===a["in"]});0<K.length&&K.forEach(function(a){var b="REPLACE_THIS_VALUE";o[a.name]&&(b=o[a.name]),a["default"]?b=a["default"].toString():a["x-example"]&&(b=a["x-example"].toString()),u.push({name:a.name,value:b}),"sec-websocket-protocol"===a.name.toLowerCase()&&(t="REPLACE_SEC-WEBSOCKET-PROTOCOL")});var L=B.filter(function(a){return"cookie"===a["in"]}),M=[];0<L.length&&(L.forEach(function(a){var b="REPLACE_THIS_VALUE";o[a.name]&&(b=o[a.name]),a["default"]?b=a["default"].toString():a["x-example"]&&(b=a["x-example"].toString()),M.push("".concat(a.name,"=").concat(b))}),u.push({name:"Cookie",value:M.join(";")}));var N=p.getParameters(e,c,x,b),O=Object.values(N).filter(function(a){return"body"===a["in"]}),P=Object.values(N).filter(function(a){return"formData"===a["in"]}),Q=[],R=[];0<O.length?(w="REPLACE_BODY",o[O[0].name]&&(w=o[O[0].name])):0<P.length&&(P.forEach(function(a){var b="REPLACE_THIS_VALUE";o[a.name]&&(b=o[a.name]),Q.push("".concat(a.name,": ").concat(b)),R.push({name:a.name,value:b})}),w=Q.join("\n")),x&&w&&u.push({name:"content-type",value:x}),y&&u.push({name:"accept",value:y});var S={method:d.toUpperCase(),url:I,headers:u,queryString:v};w&&(S.postData={mimeType:x,text:w},0<P.length&&(S.postData.params=R));var T={},U=0;if(b.host){var V=b.host.match(/(\$\([^)]*\))/g);if(V){for(var W=S.url,X=V.length,Y=0;Y<X;Y+=1){U+=1;var Z="azazaz090909-".concat(U);T[Z]=V[Y],W=W.replace(V[Y],Z)}S.url=W}}var $,_=function(a){var b=a;if(0<U)for(var c in T){var d=T[c];b=b.replace(c,d)}return b};if(/(wss?):\/\//.test(S.url))S.protocols=t,$={nodeContent:j(S)};else{var aa=new i(S);l||(l=["node","ruby","python","php","java","go","swift","c","csharp"]),$={},l.forEach(function(a){"curl"===a?$.curlContent=_(aa.convert("shell","curl")):"httpie"===a?$.curlContent=_(aa.convert("shell","httpie")):"wget"===a?$.curlContent=_(aa.convert("shell","wget")):"java"===a?$.javaContent=_(aa.convert("java","okhttp")):"node"===a?$.nodeContent=_(aa.convert("node","request")):$["".concat(a,"Content")]=_(aa.convert(a))})}return Object.entries(D).forEach(function(b){var c=a(b,2),d=c[0],e=c[1];Object.entries($).forEach(function(b){var c=a(b,1),f=c[0];$[f]=$[f].replace("".concat(d,"=").concat(e),e)})}),$}export function generateOperationContent(a){var b=k(a.api,a.path,a.verb,a.operation,a.config,a.clientId,a.clientSecret,a.languages,null,a.endpoint,a.values,a.apiHandler),c={path:a.path,type:a.type,method:a.verb,snippets:b,example:""};return c}