UNPKG

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.1 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.generateOperationContent=n,exports.getGeneratedOptionsForOperation=l;var a=require("@readme/httpsnippet"),b=c(require("./templates/websocket-node.hbs"));function c(a){return a&&a.__esModule?a:{default:a}}function d(a,b){return j(a)||i(a,b)||g(a,b)||f()}function f(){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 g(b,c){if(b){if("string"==typeof b)return h(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)?h(b,c):void 0}}function h(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 i(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 j(a){if(Array.isArray(a))return a}function k(a){"@babel/helpers - typeof";return k="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},k(a)}function l(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 m(c,e,f,g,h,j,l,m,n,o,p,q){var r;if(j||(j="REPLACE_THIS_KEY"),l||(l="REPLACE_THIS_KEY"),o||(e&&f&&c.paths&&c.paths[e]&&c.paths[e][f]&&c.paths[e][f].servers?o=c.paths[e][f].servers[0].url:e&&c.paths&&c.paths[e]&&c.paths[e].servers?o=c.paths[e].servers[0].url:c.endpoint?o=c.endpoint:c["x-ibm-configuration"]&&c["x-ibm-configuration"].servers&&c["x-ibm-configuration"].servers[0]&&c["x-ibm-configuration"].servers[0].url?o=c["x-ibm-configuration"].servers[0].url:c["x-ibm-endpoints"]&&c["x-ibm-endpoints"][0]&&c["x-ibm-endpoints"][0].endpointUrl?(o=c["x-ibm-endpoints"][0].endpointUrl,o+=c.basePath?c.basePath:""):c.openapi&&c.servers&&c.servers[0]&&c.servers[0].url?o=c.servers[0].url:(o="://".concat(c.host),o=c.schemes?c.schemes[0]+o:"https".concat(o),o+=c.basePath?c.basePath:"")),"object"===k(o)){var s;for(var t in o)s=o[t];o=s}o=null===(r=o)||void 0===r?void 0:r.replace(/\/$/,"");var u,v=[],w=[],x=null;p||(p={}),h&&h.requiresClientId&&("query"===h.clientIdLocation?h.clientIdName?w.push({name:h.clientIdName,value:j}):w.push({name:"client_id",value:j}):"header"===h.clientIdLocation&&(h.clientIdName?v.push({name:h.clientIdName,value:j}):v.push({name:"X-IBM-Client-Id",value:j}))),h&&h.requiresClientSecret&&("query"===h.clientSecretLocation?h.clientSecretName?w.push({name:h.clientSecretName,value:l}):w.push({name:"client_secret",value:l}):"header"===h.clientSecretLocation&&(h.clientSecretName?v.push({name:h.clientSecretName,value:l}):v.push({name:"X-IBM-Client-Secret",value:l}))),h&&h.requiresBasicAuth&&(p.basicAuth?v.push({name:"Authorization",value:"Basic ".concat(p.basicAuth)}):v.push({name:"Authorization",value:"Basic REPLACE_BASIC_AUTH"})),h&&h.requiresOauth&&(p.oauthToken?v.push({name:"Authorization",value:"Bearer ".concat(p.oauthToken)}):v.push({name:"Authorization",value:"Bearer REPLACE_BEARER_TOKEN"})),h&&h.requiresHttpBearerToken&&(h.httpBearerToken?v.push({name:"Authorization",value:"Bearer ".concat(h.httpBearerToken)}):v.push({name:"Authorization",value:"Bearer REPLACE_BEARER_TOKEN"})),h&&h.requiresDigestAuth&&(h.httpDigestToken?v.push({name:"Authorization",value:"Digest ".concat(h.httpDigestToken)}):v.push({name:"Authorization",value:"Digest username=\"USERNAME_VALUE\", realm=\"REALM_URL\", nonce=\"NONCE_VALUE\", opaque=\"OPAQUE_VALUE\", response=\"HASHED_CREDS\""})),h&&h.requiresHobaAuth&&(h.httpHobaToken?v.push({name:"Authorization",value:"HOBA ".concat(h.httpHobaToken)}):v.push({name:"Authorization",value:"HOBA result=\"SIGNATURE_VALUE\""})),h&&h.requiresScramShaAuth&&(h.httpScramShaToken?v.push({name:"Authorization",value:"SCRAM-SHA-256 ".concat(h.httpScramShaToken)}):v.push({name:"Authorization",value:"SCRAM-SHA-256 sid=\"SID_VALUE\", data=\"ENCRYPTED_CREDS\""})),h&&h.requiresVapidAuth&&(h.httpVapidToken?v.push({name:"Authorization",value:"vapid ".concat(h.httpVapidToken)}):v.push({name:"Authorization",value:"vapid t=\"JSON_WEB_TOKEN\", k=\"JSON_WEB_KEY\""})),h&&h.requiresNegotiateAuth&&(h.httpNegotiateToken?v.push({name:"Authorization",value:"Negotiate ".concat(h.httpNegotiateToken)}):v.push({name:"Authorization",value:"Negotiate \"GSSAPI_MESSAGE_TEXT\""})),h&&h.requiresOAuthAuth&&(h.httpOAuthToken?v.push({name:"Authorization",value:"OAuth ".concat(h.httpOAuthToken)}):v.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\""})),h&&h.requiresMutualAuth&&(h.httpMutualToken?v.push({name:"Authorization",value:"Mutual ".concat(h.httpMutualToken)}):v.push({name:"Authorization",value:"Mutual version=\"VERSION_TOKEN\", sid=\"SESSION_ID\", nc=\"NONCE_VALUE\", vkc=\"AUTH_VERIFICATION_VALUE\""}));var y=q.getDefaultContentTypeHeader(g,c),z=q.getDefaultAcceptHeader(g,c);z=h.accept?h.accept:z,y=h.contenttype?h.contenttype:y;var A=q.getServerVariables(c,o,{path:e,method:f});A&&Object.keys(A).forEach(function(a){o=o.replace("{".concat(a,"}"),"REPLACE_".concat(a.toUpperCase(),"_VARIABLE"))});var B=q.getParameters(g,e,y,c),C=h.parametersArray;C||(C=[]);var D=C.filter(function(a){return"path"===a["in"]});0<D.length&&D.forEach(function(a){var b="REPLACE_".concat(a.name.toUpperCase());p[a.name]&&(b=p[a.name]),a["default"]?b=a["default"].toString():a["x-example"]&&(b=a["x-example"].toString()),e=e.replace("{".concat(a.name,"}"),b)});var E={},F=C.filter(function(a){return"query"===a["in"]});if(0<F.length&&F.forEach(function(a){var b,c="REPLACE_THIS_VALUE";if(p[a.name]&&(c=p[a.name]),a["default"]?c=a["default"].toString():a["x-example"]&&(c=a["x-example"].toString()),B[a.name]){var d,e;b=null!==(d=B[a.name].type)&&void 0!==d?d:null===(e=B[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()),E[a.name]=c),w.push({name:a.name,value:c})}),h.externalApiKeys&&0!==Object.keys(h.externalApiKeys).length)for(var G in h.externalApiKeys){var H=h.externalApiKeys[G],I="REPLACE_THIS_VALUE";p[H.name]&&(I=p[H.name]),"query"===H["in"]?w.push({name:H.name,value:I}):"header"===H["in"]&&v.push({name:H.name,value:I})}var J=o+e;if(h.soapAction){var K="/".concat(g.operationId);-1!==J.indexOf(K,J.length-K.length)&&(J=J.substring(0,J.length-K.length))}h.soapAction&&v.push({name:"SOAPAction",value:h.soapAction});var L=C.filter(function(a){return"header"===a["in"]});0<L.length&&L.forEach(function(a){var b="REPLACE_THIS_VALUE";p[a.name]&&(b=p[a.name]),a["default"]?b=a["default"].toString():a["x-example"]&&(b=a["x-example"].toString()),v.push({name:a.name,value:b}),"sec-websocket-protocol"===a.name.toLowerCase()&&(u="REPLACE_SEC-WEBSOCKET-PROTOCOL")});var M=C.filter(function(a){return"cookie"===a["in"]}),N=[];0<M.length&&(M.forEach(function(a){var b="REPLACE_THIS_VALUE";p[a.name]&&(b=p[a.name]),a["default"]?b=a["default"].toString():a["x-example"]&&(b=a["x-example"].toString()),N.push("".concat(a.name,"=").concat(b))}),v.push({name:"Cookie",value:N.join(";")}));var O=q.getParameters(g,e,y,c),P=Object.values(O).filter(function(a){return"body"===a["in"]}),Q=Object.values(O).filter(function(a){return"formData"===a["in"]}),R=[],S=[];0<P.length?(x="REPLACE_BODY",p[P[0].name]&&(x=p[P[0].name])):0<Q.length&&(Q.forEach(function(a){var b="REPLACE_THIS_VALUE";p[a.name]&&(b=p[a.name]),R.push("".concat(a.name,": ").concat(b)),S.push({name:a.name,value:b})}),x=R.join("\n")),y&&x&&v.push({name:"content-type",value:y}),z&&v.push({name:"accept",value:z});var T={method:f.toUpperCase(),url:J,headers:v,queryString:w};x&&(T.postData={mimeType:y,text:x},0<Q.length&&(T.postData.params=S));var U={},V=0;if(c.host){var W=c.host.match(/(\$\([^)]*\))/g);if(W){for(var X=T.url,Y=W.length,Z=0;Z<Y;Z+=1){V+=1;var $="azazaz090909-".concat(V);U[$]=W[Z],X=X.replace(W[Z],$)}T.url=X}}var _,aa=function(a){var b=a;if(0<V)for(var c in U){var d=U[c];b=b.replace(c,d)}return b};if(/(wss?):\/\//.test(T.url))T.protocols=u,_={nodeContent:(0,b["default"])(T)};else{var ba=new a.HTTPSnippet(T);m||(m=["node","ruby","python","php","java","go","swift","c","csharp"]),_={},m.forEach(function(a){"curl"===a?_.curlContent=aa(ba.convert("shell","curl")):"httpie"===a?_.curlContent=aa(ba.convert("shell","httpie")):"wget"===a?_.curlContent=aa(ba.convert("shell","wget")):"java"===a?_.javaContent=aa(ba.convert("java","okhttp")):"node"===a?_.nodeContent=aa(ba.convert("node","request")):_["".concat(a,"Content")]=aa(ba.convert(a))})}return Object.entries(E).forEach(function(a){var b=d(a,2),c=b[0],e=b[1];Object.entries(_).forEach(function(a){var b=d(a,1),f=b[0];_[f]=_[f].replace("".concat(c,"=").concat(e),e)})}),_}function n(a){var b=m(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}