@redocly/reference-docs 2.6.2-beta.circular.1 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/bin/cli/commands/redocly-docs-cli.min.js +39 -41
  2. package/dist/console.redocly-reference-docs.min.js +7 -9
  3. package/dist/oauth2-redirect.js +2 -2
  4. package/dist/redocly-reference-docs.min.js +24 -24
  5. package/lib/components/Endpoint/Path.js +1 -1
  6. package/lib/components/Endpoint/ServerList.js +1 -1
  7. package/lib/components/Endpoint/ServerUrl.js +1 -1
  8. package/lib/components/console/Console.js +1 -1
  9. package/lib/components/shared/HttpVerb.js +1 -1
  10. package/lib/redoc-lib/src/common-elements/fields-layout.js +1 -1
  11. package/lib/redoc-lib/src/common-elements/fields.js +1 -1
  12. package/lib/redoc-lib/src/common-elements/samples.js +1 -1
  13. package/lib/redoc-lib/src/components/Fields/FieldDetails.js +1 -1
  14. package/lib/redoc-lib/src/index.d.ts +1 -1
  15. package/lib/redoc-lib/src/services/OpenAPIParser.js +1 -1
  16. package/lib/redoc-lib/src/services/RedocNormalizedOptions.d.ts +4 -2
  17. package/lib/redoc-lib/src/services/RedocNormalizedOptions.js +1 -1
  18. package/lib/redoc-lib/src/services/models/Schema.d.ts +1 -2
  19. package/lib/redoc-lib/src/services/models/Schema.js +1 -1
  20. package/lib/services/ProStore.d.ts +1 -1
  21. package/lib/services/ProStore.js +1 -1
  22. package/lib/services/code-samples/httpsnippet/targets/csharp/httpclient.js +1 -1
  23. package/lib/services/code-samples/httpsnippet/targets/go/native.js +1 -1
  24. package/lib/services/code-samples/httpsnippet/targets/java/httpclient.js +1 -1
  25. package/lib/services/code-samples/httpsnippet/targets/java8/apachehttp.js +1 -1
  26. package/lib/services/code-samples/httpsnippet/targets/javascript/fetch.js +1 -1
  27. package/lib/services/code-samples/httpsnippet/targets/node/fetch.js +1 -1
  28. package/lib/services/code-samples/httpsnippet/targets/php/curl.js +1 -1
  29. package/lib/services/code-samples/httpsnippet/targets/python/requests.js +1 -1
  30. package/lib/services/code-samples/httpsnippet/targets/ruby/native.js +1 -1
  31. package/lib/services/extendTheme.js +1 -1
  32. package/lib-esm/components/Endpoint/Path.js +1 -1
  33. package/lib-esm/components/Endpoint/ServerList.js +1 -1
  34. package/lib-esm/components/Endpoint/ServerUrl.js +1 -1
  35. package/lib-esm/components/console/Console.js +1 -1
  36. package/lib-esm/components/shared/HttpVerb.js +1 -1
  37. package/lib-esm/redoc-lib/src/common-elements/fields-layout.js +1 -1
  38. package/lib-esm/redoc-lib/src/common-elements/fields.js +1 -1
  39. package/lib-esm/redoc-lib/src/common-elements/samples.js +1 -1
  40. package/lib-esm/redoc-lib/src/components/Fields/FieldDetails.js +1 -1
  41. package/lib-esm/redoc-lib/src/index.d.ts +1 -1
  42. package/lib-esm/redoc-lib/src/services/OpenAPIParser.js +1 -1
  43. package/lib-esm/redoc-lib/src/services/RedocNormalizedOptions.d.ts +4 -2
  44. package/lib-esm/redoc-lib/src/services/RedocNormalizedOptions.js +1 -1
  45. package/lib-esm/redoc-lib/src/services/models/Schema.d.ts +1 -2
  46. package/lib-esm/redoc-lib/src/services/models/Schema.js +1 -1
  47. package/lib-esm/services/ProStore.d.ts +1 -1
  48. package/lib-esm/services/ProStore.js +1 -1
  49. package/lib-esm/services/code-samples/httpsnippet/targets/csharp/httpclient.js +1 -1
  50. package/lib-esm/services/code-samples/httpsnippet/targets/go/native.js +1 -1
  51. package/lib-esm/services/code-samples/httpsnippet/targets/java/httpclient.js +1 -1
  52. package/lib-esm/services/code-samples/httpsnippet/targets/java8/apachehttp.js +1 -1
  53. package/lib-esm/services/code-samples/httpsnippet/targets/javascript/fetch.js +1 -1
  54. package/lib-esm/services/code-samples/httpsnippet/targets/node/fetch.js +1 -1
  55. package/lib-esm/services/code-samples/httpsnippet/targets/php/curl.js +1 -1
  56. package/lib-esm/services/code-samples/httpsnippet/targets/python/requests.js +1 -1
  57. package/lib-esm/services/code-samples/httpsnippet/targets/ruby/native.js +1 -1
  58. package/lib-esm/services/extendTheme.js +1 -1
  59. package/package.json +1 -1
  60. package/CHANGELOG.md +0 -33
@@ -1,2 +1,2 @@
1
- "use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ProStore=exports.NestingGroup=void 0;var tslib_1=require("tslib"),mobx_1=require("mobx"),openapi_core_1=require("@redocly/openapi-core"),lodash_1=require("lodash"),redoc_lib_1=require("../redoc-lib"),history_1=require("./history"),ProMenu_1=require("./ProMenu"),SearchStore_1=require("./SearchStore"),extendTheme_1=require("./extendTheme"),pluggable_1=require("../components/pluggable"),MultipleSpecsStore_1=require("./MultipleSpecsStore"),VersionedSpecStore_1=require("./VersionedSpecStore"),check_1=(0,tslib_1.__importDefault)(require("./check")),utils_1=require("./utils"),utils_2=require("../utils"),store_types_1=require("./store-types"),global="undefined"==typeof window?{__REDOCLY_SEARCH_URL:void 0}:window,NestingGroup=function(){function e(e,t,i,o){var n=this;Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"absoluteIdx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"description",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"linkable",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"items",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"externalDocs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"active",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"expanded",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"depth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"level",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),(0,mobx_1.makeObservable)(this),this.id="section/"+e,this.type="nesting-group",this.name=i||"",this.level=1,this.depth=1,this.description="",this.parent=void 0,this.expanded=!1,this.items=t,this.linkable=!!o,t.forEach((function(e){return e.parent=n})),increaseDepthDeep(t)}return Object.defineProperty(e.prototype,"activate",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.active=!0}}),Object.defineProperty(e.prototype,"expand",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.expanded=!0,this.parent&&this.parent.expand()}}),Object.defineProperty(e.prototype,"collapse",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.expanded=!1}}),Object.defineProperty(e.prototype,"deactivate",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.active=!1}}),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"active",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"expanded",void 0),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"activate",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"expand",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"collapse",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"deactivate",null),e}();function increaseDepthDeep(e){Array.isArray(e)&&e.forEach((function(e){e.depth++,e.parent&&"group"===e.parent.type&&(e.depth=e.parent.depth),increaseDepthDeep(e.items)}))}exports.NestingGroup=NestingGroup;var ProStore=function(){function e(e,t,i,o){var n=this;void 0===i&&(i={}),void 0===o&&(o=!0),Object.defineProperty(this,"rawOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"menu",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"definition",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"marker",{enumerable:!0,configurable:!0,writable:!0,value:new redoc_lib_1.MarkerService}),Object.defineProperty(this,"scroll",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"disposer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"search",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tryItOperation",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"showRightPanel",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"layout",{enumerable:!0,configurable:!0,writable:!0,value:store_types_1.LayoutVariant.THREE_PANEL}),Object.defineProperty(this,"activeSampleLanguage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isLoading",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"l",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"activateSampleLanguage",{enumerable:!0,configurable:!0,writable:!0,value:(0,lodash_1.debounce)((function(e){return n.setActiveSampleLanguage(e)}),500)}),(0,mobx_1.makeObservable)(this),this.initProOptions(i),redoc_lib_1.IS_BROWSER&&(this.l=(0,check_1.default)(i.licenseKey),this.l.then((function(e){e.valid&&e.allowed&&!e.expired||e.local||(n.menu.items=[],n.menu.flatItems=n.menu.flatItems.slice(0,1),n.menu.renderItems=[])})));var r=Array.isArray(e),a=e&&Array.isArray(e.versions),s=this.options.disableSidebar?new history_1.FakeHistoryService(this.options):"browser"===this.options.routingStrategy?new history_1.PushStateHistoryService(this.options,r||a):new history_1.ProHashHistoryService(this.options,r||a);this.definition=r?new MultipleSpecsStore_1.MultipleSpecsStore(e,this.options):a?new VersionedSpecStore_1.VersionedSpecStore(e,this.options,s.currentId.split("/")[0]):new redoc_lib_1.SpecStore(e,t,this.options),i.downloadSpecUrl&&(this.definition.info.downloadLink=i.downloadSpecUrl,this.definition.info.downloadFileName=""),this.scroll=new redoc_lib_1.ScrollService(this.options),this.options.disableSidebar||ProMenu_1.ProMenu.updateOnHistory(s.currentId,this.scroll),this.menu=new ProMenu_1.ProMenu(this.definition,this.scroll,this.options,s),this.menu.initOnHistory(),this.options.disableSearch||this.initSearch(this.options,o),this.disposer=(0,mobx_1.observe)(this.menu,"none"===this.options.pagination?"activeItemIdx":"activeRenderItemIdx",(function(e){setTimeout((function(){return n.updateMarkOnMenu(e.newValue)}))})),(0,utils_2.setGlobalStore)(this)}return Object.defineProperty(e.prototype,"initProOptions",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t,i,o,n,r;e=deepClone(e),this.rawOptions=(0,extendTheme_1.extendTheme)(e),this.options=new redoc_lib_1.RedocNormalizedOptions(this.rawOptions,DEFAULT_OPTIONS),this.options.showConsole=null===(t=this.rawOptions.showConsole)||void 0===t||t,this.options.hideRightPanel=null!==(i=this.rawOptions.hideRightPanel)&&void 0!==i&&i,this.showRightPanel=!this.options.hideRightPanel,this.options.showRightPanelToggle=null===(o=this.rawOptions.showRightPanelToggle)||void 0===o||o,this.options.showChangeLayoutButton=null===(n=this.rawOptions.showChangeLayoutButton)||void 0===n||n,this.options.layout=this.rawOptions.layout||store_types_1.LayoutVariant.THREE_PANEL,this.options.defaultSampleLanguage=this.rawOptions.defaultSampleLanguage||"",this.options.deepLinkSeparator=this.rawOptions.deepLinkSeparator||"/",this.options.deepLinkPrefix=this.rawOptions.deepLinkPrefix||"!",this.options.disableDeepLinks=this.rawOptions.disableDeepLinks||!1,this.options.sideNavStyle=this.rawOptions.sideNavStyle||"summary-only",this.options.whiteLabel=!!this.rawOptions.whiteLabel,this.options.hideLogo=!!this.rawOptions.hideLogo,this.options.hideInfoSection=!!this.rawOptions.hideInfoSection,this.options.oAuth2RedirectURI=this.rawOptions.oAuth2RedirectURI||null,this.options.oAuth2RedirectURI=this.rawOptions.oAuth2RedirectURI||null,this.options.events=this.rawOptions.events||{},this.options.corsProxyUrl=this.rawOptions.corsProxyUrl?addTrailingSlash(this.rawOptions.corsProxyUrl):null,this.options.authCorsProxyUrl=this.rawOptions.authCorsProxyUrl?addTrailingSlash(this.rawOptions.authCorsProxyUrl):null,this.options.theme.scrollYOffset=this.options.scrollYOffset,this.options.linkForId=this.rawOptions.linkForId||null,this.options.generateDeepLink=this.rawOptions.generateDeepLink||null,this.options.onDeepLinkClick=this.rawOptions.onDeepLinkClick||null,this.options.requestInterceptor=this.rawOptions.requestInterceptor||null,this.options.sidebarLinks=this.rawOptions.sidebarLinks||{};var a="object"==typeof this.rawOptions.layout?this.rawOptions.layout:null;if(this.options.pagination=this.rawOptions.pagination||"none",this.options.routingStrategy="none"===this.options.pagination?"hash":"browser",!(null===(r=this.rawOptions)||void 0===r?void 0:r.pagination)&&(null==a?void 0:a.scope))switch(console.warn('"layout.scope" and "routingStrategy" settings are deprecated. Please, use "pagination" instead.'),null==a?void 0:a.scope){case"all":this.options.pagination="none",this.options.routingStrategy="hash";break;case"section":this.options.pagination="section",this.options.routingStrategy="browser";break;case"item":this.options.pagination="item",this.options.routingStrategy="browser";break;default:this.options.pagination="none",this.options.routingStrategy="hash"}this.options.markdownItemsPagination="none",!1!==this.rawOptions.showNextButton&&(this.options.showNextButton=!0),this.options.disableSidebar=!!e.disableSidebar,this.options.disableSidebar&&(this.options.theme.sidebar.width="0px"),this.options.skipBundleAndConvert=!!e.skipBundleAndConvert,this.options.routingBasePath=e.routingBasePath&&(0,utils_1.normalizePath)(e.routingBasePath)||"",this.options.searchAutoExpand=!1!==e.searchAutoExpand,this.options.searchMode=e.searchMode||"default",this.options.ctrlFHijack=void 0===e.ctrlFHijack||e.ctrlFHijack,this.options.disablePaginationLoadingAnimation=!!e.disablePaginationLoadingAnimation||"none"===this.options.pagination,this.options.showConsole,this.options.generateCodeSamples=e.generateCodeSamples||{languages:[]},this.options.searchMaxDepth=this.rawOptions.searchMaxDepth||SearchStore_1.SEARCH_MAX_DEPTH}}),Object.defineProperty(e.prototype,"initSearch",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var i=this;global.__REDOCLY_SEARCH_URL?this.search=new SearchStore_1.RemoteSearch(global.__REDOCLY_SEARCH_URL):this.search=new SearchStore_1.DeepSearchStore(e),t&&setTimeout((function(){var e;return null===(e=i.search)||void 0===e?void 0:e.indexItems(i.menu.items)}),50),this.definition instanceof VersionedSpecStore_1.VersionedSpecStore&&(0,mobx_1.observe)(this.definition,"activeVersionIdx",(function(t){var o,n,r=i.definition;null===(o=i.search)||void 0===o||o.dispose(),i.search=new SearchStore_1.DeepSearchStore(e);var a=r.versions[t.newValue]._searchIndexName;if(redoc_lib_1.IS_BROWSER&&a){var s=r.versions[t.newValue]._searchIndexName,l=new URL(window.location.href);l.pathname=joinURLs(i.options.routingBasePath,s),null===(n=i.search)||void 0===n||n.fromExternalJS(l.toString(),__redoc_state.searchIndexExport),i.observeAllAndRemark()}else setTimeout((function(){var e;null===(e=i.search)||void 0===e||e.indexItems(i.menu.items)}),0)})),redoc_lib_1.IS_BROWSER&&this.observeAllAndRemark()}}),Object.defineProperty(e.prototype,"onDidMount",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.menu.updateOnHistory(),this.updateMarkOnMenu(this.menu.activeItemIdx),this.layout=(0,utils_2.fromLocalStorage)("layoutVariant")||this.options.layout||this.layout,this.activeSampleLanguage=(0,utils_2.fromLocalStorage)("activeSampleLanguage")||this.options.defaultSampleLanguage,this.options.showRightPanelToggle){var e=(0,utils_2.fromStorage)("showRightPanelToggleState");e&&(this.showRightPanel="true"===e)}}}),Object.defineProperty(e.prototype,"toggleRightPanel",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.showRightPanel=null!=e?e:!this.showRightPanel,(0,utils_2.toStorage)("showRightPanelToggleState",JSON.stringify(this.showRightPanel))}}),Object.defineProperty(e.prototype,"toggleLayout",{enumerable:!1,configurable:!0,writable:!0,value:function(e){void 0===e&&(e=store_types_1.LayoutVariant.THREE_PANEL),this.layout=e,(0,utils_2.toLocalStorage)("layoutVariant",e)}}),Object.defineProperty(e.prototype,"disableConsole",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.options.showConsole=!1}}),Object.defineProperty(e.prototype,"enableConsole",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.options.showConsole=!0}}),Object.defineProperty(e.prototype,"tryItOut",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.tryItOperation=e}}),Object.defineProperty(e.prototype,"setActiveSampleLanguage",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.activeSampleLanguage===e)return this.stopLoader();this.activeSampleLanguage=e,(0,utils_2.toLocalStorage)("activeSampleLanguage",e)}}),Object.defineProperty(e.prototype,"startLoader",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.isLoading||(this.isLoading=!0)}}),Object.defineProperty(e.prototype,"stopLoader",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.isLoading&&(this.isLoading=!1)}}),Object.defineProperty(e.prototype,"dereferenceSpecForTryIt",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var i,o,n,r;return(0,tslib_1.__awaiter)(this,void 0,void 0,(function(){var a,s,l,p,u,c,h,d;return(0,tslib_1.__generator)(this,(function(b){switch(b.label){case 0:return a=void 0!==e&&this.definition.specs?this.definition.specs[e].parser.definition:this.definition.parser.definition,s=JSON.parse(JSON.stringify(a)),l=(0,tslib_1.__assign)((0,tslib_1.__assign)({},getSpecVersionObj(s)),{components:s.components,paths:(h={},h[t.path]=(d={},d[t.httpVerb]=null===(o=null===(i=s.paths)||void 0===i?void 0:i[t.path])||void 0===o?void 0:o[t.httpVerb],d.parameters=null===(r=null===(n=s.paths)||void 0===n?void 0:n[t.path])||void 0===r?void 0:r.parameters,d),h)}),p=new openapi_core_1.Config({}),u=(0,redoc_lib_1.createParsedDocument)(l),c={config:p,doc:u,dereference:!0},[4,(0,openapi_core_1.bundle)(c)];case 1:return b.sent(),[2,s]}}))}))}}),Object.defineProperty(e.prototype,"observeAllAndRemark",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this,t=function(i){for(var o=0,n=i;o<n.length;o++){var r=n[o];if("operation"===r.type)for(var a=0,s=r.responses;a<s.length;a++){var l=s[a];(0,mobx_1.observe)(l,"expanded",(function(t){return e.remark(t)}))}else"tag"===r.type&&t(r.items||[])}};t(this.menu.renderItems),"none"!==this.options.pagination&&(0,mobx_1.observe)(this.menu,"renderItems",(function(){return t(e.menu.renderItems)}))}}),Object.defineProperty(e.prototype,"remark",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;e.newValue&&setTimeout((function(){return t.marker.mark()}),0)}}),Object.defineProperty(e,"fromJS",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var i,o=new e(t.definition.data,t.definition.url,t.options,!1);(0,utils_2.setGlobalStore)(o),o.menu.activeItemIdx=void 0!==t.menu.activeItemIdx?t.menu.activeItemIdx:-1,o.definition instanceof VersionedSpecStore_1.VersionedSpecStore&&t.definition.activeVersionIdx&&(o.definition.activeVersionIdx=t.definition.activeVersionIdx||0);var n=o.menu.flatItems[o.menu.activeItemIdx];if(n&&o.menu.activate(n,!1),!o.options.disableSearch){var r=new URL(window.location.href);r.pathname=t.searchIndexPath&&t.searchIndexPath.startsWith("/")?t.searchIndexPath:r.pathname+(r.pathname.endsWith("/")?"":"/")+t.searchIndexPath,null===(i=o.search)||void 0===i||i.fromExternalJS(r.toString(),t.searchIndexExport)}return t.tryItOperationId&&(o.tryItOperation=o.menu.flatItems.find((function(e){return e.id===t.tryItOperationId}))),setTimeout((function(){return o.observeAllAndRemark()}),0),o}}),Object.defineProperty(e.prototype,"toJS",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e;return(0,tslib_1.__awaiter)(this,void 0,void 0,(function(){var t,i;return(0,tslib_1.__generator)(this,(function(o){switch(o.label){case 0:return i={menu:{activeItemIdx:this.menu.activeItemIdx},definition:this.definition instanceof MultipleSpecsStore_1.MultipleSpecsStore||this.definition instanceof VersionedSpecStore_1.VersionedSpecStore?{url:void 0,data:this.definition.toJS()}:{url:this.definition.parser.definitionUrl,data:this.definition.parser.definition}},this.search?[4,this.search.toJS()]:[3,2];case 1:return t=o.sent(),[3,3];case 2:t=void 0,o.label=3;case 3:return[2,(i.searchIndex=t,i.options=this.rawOptions,i.tryItOperationId=null===(e=this.tryItOperation)||void 0===e?void 0:e.id,i)]}}))}))}}),Object.defineProperty(e.prototype,"dispose",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.scroll.dispose(),this.menu.dispose(),this.search&&this.search.dispose(),this.disposer()}}),Object.defineProperty(e.prototype,"updateMarkOnMenu",{enumerable:!1,configurable:!0,writable:!0,value:function(e){for(var t,i=Math.max(0,e),o=Math.min(this.menu.flatItems.length,i+5),n=[],r=i;r<o;r++){var a;(a=this.menu.getElementAt(r))&&(a&&n.push(a))}"item"===this.options.pagination&&(this.menu.flatItems[e]&&this.menu.flatItems[e].parent&&(a=this.menu.getElementAt(null===(t=this.menu.flatItems[e].parent)||void 0===t?void 0:t.absoluteIdx))&&n.push(a));this.marker.addOnly(n),this.marker.mark()}}),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"search",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"tryItOperation",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"showRightPanel",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"layout",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"activeSampleLanguage",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"isLoading",void 0),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"onDidMount",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"toggleRightPanel",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"toggleLayout",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"disableConsole",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"enableConsole",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"tryItOut",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"setActiveSampleLanguage",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"startLoader",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"stopLoader",null),e}();exports.ProStore=ProStore;var DEFAULT_OPTIONS={ignoreNamedSchemas:["java.io.ObjectStreamField"],allowedMdComponents:(_a={RedocResponse:{component:pluggable_1.RedocResponse,propsSelector:function(e){return{store:e}}},PullRight:{component:pluggable_1.PullRight,propsSelector:function(){return{}}}},_a[redoc_lib_1.SECURITY_DEFINITIONS_COMPONENT_NAME]={component:redoc_lib_1.SecurityDefs,propsSelector:function(e){return{securitySchemes:e.definition.securitySchemes}}},_a[redoc_lib_1.SECURITY_DEFINITIONS_JSX_NAME]={component:redoc_lib_1.SecurityDefs,propsSelector:function(e){return{securitySchemes:e.definition.securitySchemes}}},_a[redoc_lib_1.SCHEMA_DEFINITION_JSX_NAME]={component:redoc_lib_1.SchemaDefinition,propsSelector:function(e){return{parser:e.definition.parser,options:e.options,layout:e.layout,showRightPanel:e.showRightPanel}}},_a)};function joinURLs(e,t){return e.endsWith("/")&&(e=e.slice(0,-1)),t.startsWith("/")&&(t=t.substring(1)),e+"/"+t}function addTrailingSlash(e){return e.endsWith("/")?e:e+"/"}function getSpecVersionObj(e){return e.openapi?{openapi:e.openapi}:e.swagger?{swagger:e.swagger}:void 0}function deepClone(e){if("object"!=typeof e||null===e)return e;var t=Array.isArray(e)?[]:{};for(var i in e){var o=e[i];t[i]=deepClone(o)}return t}
1
+ "use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ProStore=exports.NestingGroup=void 0;var tslib_1=require("tslib"),mobx_1=require("mobx"),openapi_core_1=require("@redocly/openapi-core"),lodash_1=require("lodash"),redoc_lib_1=require("../redoc-lib"),history_1=require("./history"),ProMenu_1=require("./ProMenu"),SearchStore_1=require("./SearchStore"),extendTheme_1=require("./extendTheme"),pluggable_1=require("../components/pluggable"),MultipleSpecsStore_1=require("./MultipleSpecsStore"),VersionedSpecStore_1=require("./VersionedSpecStore"),check_1=(0,tslib_1.__importDefault)(require("./check")),utils_1=require("./utils"),utils_2=require("../utils"),store_types_1=require("./store-types"),global="undefined"==typeof window?{__REDOCLY_SEARCH_URL:void 0}:window,NestingGroup=function(){function e(e,t,i,o){var n=this;Object.defineProperty(this,"id",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"absoluteIdx",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"description",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"type",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"linkable",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"items",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"parent",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"externalDocs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"active",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"expanded",{enumerable:!0,configurable:!0,writable:!0,value:!1}),Object.defineProperty(this,"depth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"level",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),(0,mobx_1.makeObservable)(this),this.id="section/"+e,this.type="nesting-group",this.name=i||"",this.level=1,this.depth=1,this.description="",this.parent=void 0,this.expanded=!1,this.items=t,this.linkable=!!o,t.forEach((function(e){return e.parent=n})),increaseDepthDeep(t)}return Object.defineProperty(e.prototype,"activate",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.active=!0}}),Object.defineProperty(e.prototype,"expand",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.expanded=!0,this.parent&&this.parent.expand()}}),Object.defineProperty(e.prototype,"collapse",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.expanded=!1}}),Object.defineProperty(e.prototype,"deactivate",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.active=!1}}),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"active",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"expanded",void 0),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"activate",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"expand",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"collapse",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"deactivate",null),e}();function increaseDepthDeep(e){Array.isArray(e)&&e.forEach((function(e){e.depth++,e.parent&&"group"===e.parent.type&&(e.depth=e.parent.depth),increaseDepthDeep(e.items)}))}exports.NestingGroup=NestingGroup;var ProStore=function(){function e(e,t,i,o){var n=this;void 0===i&&(i={}),void 0===o&&(o=!0),Object.defineProperty(this,"rawOptions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"options",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"menu",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"definition",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"marker",{enumerable:!0,configurable:!0,writable:!0,value:new redoc_lib_1.MarkerService}),Object.defineProperty(this,"scroll",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"disposer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"search",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"tryItOperation",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"showRightPanel",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"layout",{enumerable:!0,configurable:!0,writable:!0,value:store_types_1.LayoutVariant.THREE_PANEL}),Object.defineProperty(this,"activeSampleLanguage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"isLoading",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"l",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"activateSampleLanguage",{enumerable:!0,configurable:!0,writable:!0,value:(0,lodash_1.debounce)((function(e){return n.setActiveSampleLanguage(e)}),500)}),(0,mobx_1.makeObservable)(this),this.initProOptions(i),redoc_lib_1.IS_BROWSER&&(this.l=(0,check_1.default)(i.licenseKey),this.l.then((function(e){e.valid&&e.allowed&&!e.expired||e.local||(n.menu.items=[],n.menu.flatItems=n.menu.flatItems.slice(0,1),n.menu.renderItems=[])})));var r=Array.isArray(e),a=e&&Array.isArray(e.versions),s=this.options.disableSidebar?new history_1.FakeHistoryService(this.options):"browser"===this.options.routingStrategy?new history_1.PushStateHistoryService(this.options,r||a):new history_1.ProHashHistoryService(this.options,r||a);this.definition=r?new MultipleSpecsStore_1.MultipleSpecsStore(e,this.options):a?new VersionedSpecStore_1.VersionedSpecStore(e,this.options,s.currentId.split("/")[0]):new redoc_lib_1.SpecStore(e,t,this.options),i.downloadDefinitionUrl&&(this.definition.info.downloadLink=i.downloadDefinitionUrl,this.definition.info.downloadFileName=""),this.scroll=new redoc_lib_1.ScrollService(this.options),this.options.disableSidebar||ProMenu_1.ProMenu.updateOnHistory(s.currentId,this.scroll),this.menu=new ProMenu_1.ProMenu(this.definition,this.scroll,this.options,s),this.menu.initOnHistory(),this.options.disableSearch||this.initSearch(this.options,o),this.disposer=(0,mobx_1.observe)(this.menu,"none"===this.options.pagination?"activeItemIdx":"activeRenderItemIdx",(function(e){setTimeout((function(){return n.updateMarkOnMenu(e.newValue)}))})),(0,utils_2.setGlobalStore)(this)}return Object.defineProperty(e.prototype,"initProOptions",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t,i,o,n,r;e=deepClone(e),this.rawOptions=(0,extendTheme_1.extendTheme)(e),this.options=new redoc_lib_1.RedocNormalizedOptions(this.rawOptions,DEFAULT_OPTIONS),this.options.showConsole=null===(t=this.rawOptions.showConsole)||void 0===t||t,this.options.hideRightPanel=null!==(i=this.rawOptions.hideRightPanel)&&void 0!==i&&i,this.showRightPanel=!this.options.hideRightPanel,this.options.showRightPanelToggle=null===(o=this.rawOptions.showRightPanelToggle)||void 0===o||o,this.options.showChangeLayoutButton=null===(n=this.rawOptions.showChangeLayoutButton)||void 0===n||n,this.options.layout=this.rawOptions.layout||store_types_1.LayoutVariant.THREE_PANEL,this.options.defaultSampleLanguage=this.rawOptions.defaultSampleLanguage||"",this.options.deepLinkSeparator=this.rawOptions.deepLinkSeparator||"/",this.options.deepLinkPrefix=this.rawOptions.deepLinkPrefix||"!",this.options.disableDeepLinks=this.rawOptions.disableDeepLinks||!1,this.options.sideNavStyle=this.rawOptions.sideNavStyle||"summary-only",this.options.whiteLabel=!!this.rawOptions.whiteLabel,this.options.hideLogo=!!this.rawOptions.hideLogo,this.options.hideInfoSection=!!this.rawOptions.hideInfoSection,this.options.oAuth2RedirectURI=this.rawOptions.oAuth2RedirectURI||null,this.options.oAuth2RedirectURI=this.rawOptions.oAuth2RedirectURI||null,this.options.events=this.rawOptions.events||{},this.options.corsProxyUrl=this.rawOptions.corsProxyUrl?addTrailingSlash(this.rawOptions.corsProxyUrl):null,this.options.authCorsProxyUrl=this.rawOptions.authCorsProxyUrl?addTrailingSlash(this.rawOptions.authCorsProxyUrl):null,this.options.theme.scrollYOffset=this.options.scrollYOffset,this.options.linkForId=this.rawOptions.linkForId||null,this.options.generateDeepLink=this.rawOptions.generateDeepLink||null,this.options.onDeepLinkClick=this.rawOptions.onDeepLinkClick||null,this.options.requestInterceptor=this.rawOptions.requestInterceptor||null,this.options.sidebarLinks=this.rawOptions.sidebarLinks||{};var a="object"==typeof this.rawOptions.layout?this.rawOptions.layout:null;if(this.options.pagination=this.rawOptions.pagination||"none",this.options.routingStrategy="none"===this.options.pagination?"hash":"browser",!(null===(r=this.rawOptions)||void 0===r?void 0:r.pagination)&&(null==a?void 0:a.scope))switch(console.warn('"layout.scope" and "routingStrategy" settings are deprecated. Please, use "pagination" instead.'),null==a?void 0:a.scope){case"all":this.options.pagination="none",this.options.routingStrategy="hash";break;case"section":this.options.pagination="section",this.options.routingStrategy="browser";break;case"item":this.options.pagination="item",this.options.routingStrategy="browser";break;default:this.options.pagination="none",this.options.routingStrategy="hash"}this.options.markdownItemsPagination="none",!1!==this.rawOptions.showNextButton&&(this.options.showNextButton=!0),this.options.disableSidebar=!!e.disableSidebar,this.options.disableSidebar&&(this.options.theme.sidebar.width="0px"),this.options.skipBundleAndConvert=!!e.skipBundleAndConvert,this.options.routingBasePath=e.routingBasePath&&(0,utils_1.normalizePath)(e.routingBasePath)||"",this.options.searchAutoExpand=!1!==e.searchAutoExpand,this.options.searchMode=e.searchMode||"default",this.options.ctrlFHijack=void 0===e.ctrlFHijack||e.ctrlFHijack,this.options.disablePaginationLoadingAnimation=!!e.disablePaginationLoadingAnimation||"none"===this.options.pagination,this.options.showConsole,this.options.generateCodeSamples=e.generateCodeSamples||{languages:[]},this.options.searchMaxDepth=this.rawOptions.searchMaxDepth||SearchStore_1.SEARCH_MAX_DEPTH}}),Object.defineProperty(e.prototype,"initSearch",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var i=this;global.__REDOCLY_SEARCH_URL?this.search=new SearchStore_1.RemoteSearch(global.__REDOCLY_SEARCH_URL):this.search=new SearchStore_1.DeepSearchStore(e),t&&setTimeout((function(){var e;return null===(e=i.search)||void 0===e?void 0:e.indexItems(i.menu.items)}),50),this.definition instanceof VersionedSpecStore_1.VersionedSpecStore&&(0,mobx_1.observe)(this.definition,"activeVersionIdx",(function(t){var o,n,r=i.definition;null===(o=i.search)||void 0===o||o.dispose(),i.search=new SearchStore_1.DeepSearchStore(e);var a=r.versions[t.newValue]._searchIndexName;if(redoc_lib_1.IS_BROWSER&&a){var s=r.versions[t.newValue]._searchIndexName,l=new URL(window.location.href);l.pathname=joinURLs(i.options.routingBasePath,s),null===(n=i.search)||void 0===n||n.fromExternalJS(l.toString(),__redoc_state.searchIndexExport),i.observeAllAndRemark()}else setTimeout((function(){var e;null===(e=i.search)||void 0===e||e.indexItems(i.menu.items)}),0)})),redoc_lib_1.IS_BROWSER&&this.observeAllAndRemark()}}),Object.defineProperty(e.prototype,"onDidMount",{enumerable:!1,configurable:!0,writable:!0,value:function(){if(this.menu.updateOnHistory(),this.updateMarkOnMenu(this.menu.activeItemIdx),this.layout=(0,utils_2.fromLocalStorage)("layoutVariant")||this.options.layout||this.layout,this.activeSampleLanguage=(0,utils_2.fromLocalStorage)("activeSampleLanguage")||this.options.defaultSampleLanguage,this.options.showRightPanelToggle){var e=(0,utils_2.fromStorage)("showRightPanelToggleState");e&&(this.showRightPanel="true"===e)}}}),Object.defineProperty(e.prototype,"toggleRightPanel",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.showRightPanel=null!=e?e:!this.showRightPanel,(0,utils_2.toStorage)("showRightPanelToggleState",JSON.stringify(this.showRightPanel))}}),Object.defineProperty(e.prototype,"toggleLayout",{enumerable:!1,configurable:!0,writable:!0,value:function(e){void 0===e&&(e=store_types_1.LayoutVariant.THREE_PANEL),this.layout=e,(0,utils_2.toLocalStorage)("layoutVariant",e)}}),Object.defineProperty(e.prototype,"disableConsole",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.options.showConsole=!1}}),Object.defineProperty(e.prototype,"enableConsole",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.options.showConsole=!0}}),Object.defineProperty(e.prototype,"tryItOut",{enumerable:!1,configurable:!0,writable:!0,value:function(e){this.tryItOperation=e}}),Object.defineProperty(e.prototype,"setActiveSampleLanguage",{enumerable:!1,configurable:!0,writable:!0,value:function(e){if(this.activeSampleLanguage===e)return this.stopLoader();this.activeSampleLanguage=e,(0,utils_2.toLocalStorage)("activeSampleLanguage",e)}}),Object.defineProperty(e.prototype,"startLoader",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.isLoading||(this.isLoading=!0)}}),Object.defineProperty(e.prototype,"stopLoader",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.isLoading&&(this.isLoading=!1)}}),Object.defineProperty(e.prototype,"dereferenceSpecForTryIt",{enumerable:!1,configurable:!0,writable:!0,value:function(e,t){var i,o,n,r;return(0,tslib_1.__awaiter)(this,void 0,void 0,(function(){var a,s,l,p,u,c,h,d;return(0,tslib_1.__generator)(this,(function(b){switch(b.label){case 0:return a=void 0!==e&&this.definition.specs?this.definition.specs[e].parser.definition:this.definition.parser.definition,s=JSON.parse(JSON.stringify(a)),l=(0,tslib_1.__assign)((0,tslib_1.__assign)({},getSpecVersionObj(s)),{components:s.components,paths:(h={},h[t.path]=(d={},d[t.httpVerb]=null===(o=null===(i=s.paths)||void 0===i?void 0:i[t.path])||void 0===o?void 0:o[t.httpVerb],d.parameters=null===(r=null===(n=s.paths)||void 0===n?void 0:n[t.path])||void 0===r?void 0:r.parameters,d),h)}),p=new openapi_core_1.Config({}),u=(0,redoc_lib_1.createParsedDocument)(l),c={config:p,doc:u,dereference:!0},[4,(0,openapi_core_1.bundle)(c)];case 1:return b.sent(),[2,s]}}))}))}}),Object.defineProperty(e.prototype,"observeAllAndRemark",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this,t=function(i){for(var o=0,n=i;o<n.length;o++){var r=n[o];if("operation"===r.type)for(var a=0,s=r.responses;a<s.length;a++){var l=s[a];(0,mobx_1.observe)(l,"expanded",(function(t){return e.remark(t)}))}else"tag"===r.type&&t(r.items||[])}};t(this.menu.renderItems),"none"!==this.options.pagination&&(0,mobx_1.observe)(this.menu,"renderItems",(function(){return t(e.menu.renderItems)}))}}),Object.defineProperty(e.prototype,"remark",{enumerable:!1,configurable:!0,writable:!0,value:function(e){var t=this;e.newValue&&setTimeout((function(){return t.marker.mark()}),0)}}),Object.defineProperty(e,"fromJS",{enumerable:!1,configurable:!0,writable:!0,value:function(t){var i,o=new e(t.definition.data,t.definition.url,t.options,!1);(0,utils_2.setGlobalStore)(o),o.menu.activeItemIdx=void 0!==t.menu.activeItemIdx?t.menu.activeItemIdx:-1,o.definition instanceof VersionedSpecStore_1.VersionedSpecStore&&t.definition.activeVersionIdx&&(o.definition.activeVersionIdx=t.definition.activeVersionIdx||0);var n=o.menu.flatItems[o.menu.activeItemIdx];if(n&&o.menu.activate(n,!1),!o.options.disableSearch){var r=new URL(window.location.href);r.pathname=t.searchIndexPath&&t.searchIndexPath.startsWith("/")?t.searchIndexPath:r.pathname+(r.pathname.endsWith("/")?"":"/")+t.searchIndexPath,null===(i=o.search)||void 0===i||i.fromExternalJS(r.toString(),t.searchIndexExport)}return t.tryItOperationId&&(o.tryItOperation=o.menu.flatItems.find((function(e){return e.id===t.tryItOperationId}))),setTimeout((function(){return o.observeAllAndRemark()}),0),o}}),Object.defineProperty(e.prototype,"toJS",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e;return(0,tslib_1.__awaiter)(this,void 0,void 0,(function(){var t,i;return(0,tslib_1.__generator)(this,(function(o){switch(o.label){case 0:return i={menu:{activeItemIdx:this.menu.activeItemIdx},definition:this.definition instanceof MultipleSpecsStore_1.MultipleSpecsStore||this.definition instanceof VersionedSpecStore_1.VersionedSpecStore?{url:void 0,data:this.definition.toJS()}:{url:this.definition.parser.definitionUrl,data:this.definition.parser.definition}},this.search?[4,this.search.toJS()]:[3,2];case 1:return t=o.sent(),[3,3];case 2:t=void 0,o.label=3;case 3:return[2,(i.searchIndex=t,i.options=this.rawOptions,i.tryItOperationId=null===(e=this.tryItOperation)||void 0===e?void 0:e.id,i)]}}))}))}}),Object.defineProperty(e.prototype,"dispose",{enumerable:!1,configurable:!0,writable:!0,value:function(){this.scroll.dispose(),this.menu.dispose(),this.search&&this.search.dispose(),this.disposer()}}),Object.defineProperty(e.prototype,"updateMarkOnMenu",{enumerable:!1,configurable:!0,writable:!0,value:function(e){for(var t,i=Math.max(0,e),o=Math.min(this.menu.flatItems.length,i+5),n=[],r=i;r<o;r++){var a;(a=this.menu.getElementAt(r))&&(a&&n.push(a))}"item"===this.options.pagination&&(this.menu.flatItems[e]&&this.menu.flatItems[e].parent&&(a=this.menu.getElementAt(null===(t=this.menu.flatItems[e].parent)||void 0===t?void 0:t.absoluteIdx))&&n.push(a));this.marker.addOnly(n),this.marker.mark()}}),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"search",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"tryItOperation",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"showRightPanel",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"layout",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"activeSampleLanguage",void 0),(0,tslib_1.__decorate)([mobx_1.observable],e.prototype,"isLoading",void 0),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"onDidMount",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"toggleRightPanel",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"toggleLayout",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"disableConsole",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"enableConsole",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"tryItOut",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"setActiveSampleLanguage",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"startLoader",null),(0,tslib_1.__decorate)([mobx_1.action],e.prototype,"stopLoader",null),e}();exports.ProStore=ProStore;var DEFAULT_OPTIONS={ignoreNamedSchemas:["java.io.ObjectStreamField"],allowedMdComponents:(_a={RedocResponse:{component:pluggable_1.RedocResponse,propsSelector:function(e){return{store:e}}},PullRight:{component:pluggable_1.PullRight,propsSelector:function(){return{}}}},_a[redoc_lib_1.SECURITY_DEFINITIONS_COMPONENT_NAME]={component:redoc_lib_1.SecurityDefs,propsSelector:function(e){return{securitySchemes:e.definition.securitySchemes}}},_a[redoc_lib_1.SECURITY_DEFINITIONS_JSX_NAME]={component:redoc_lib_1.SecurityDefs,propsSelector:function(e){return{securitySchemes:e.definition.securitySchemes}}},_a[redoc_lib_1.SCHEMA_DEFINITION_JSX_NAME]={component:redoc_lib_1.SchemaDefinition,propsSelector:function(e){return{parser:e.definition.parser,options:e.options,layout:e.layout,showRightPanel:e.showRightPanel}}},_a)};function joinURLs(e,t){return e.endsWith("/")&&(e=e.slice(0,-1)),t.startsWith("/")&&(t=t.substring(1)),e+"/"+t}function addTrailingSlash(e){return e.endsWith("/")?e:e+"/"}function getSpecVersionObj(e){return e.openapi?{openapi:e.openapi}:e.swagger?{swagger:e.swagger}:void 0}function deepClone(e){if("object"!=typeof e||null===e)return e;var t=Array.isArray(e)?[]:{};for(var i in e){var o=e[i];t[i]=deepClone(o)}return t}
2
2
  //# sourceMappingURL=ProStore.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),stringify_object_1=(0,tslib_1.__importDefault)(require("stringify-object")),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),code_helpers_1=require("../../helpers/code-helpers"),utils_1=require("../../../../utils"),generator_1=require("../../../generator"),constants_1=require("../../helpers/constants"),handler=function(t,e,s){var a,n,i,r,o=s.target,p=s.client,u=Object.assign({indent:" ",withWrapper:!0},e),l=new code_builder_1.CodeBuilder({indentation:u.indent,variablesPrefix:u.variablesPrefix,capitalize:!0,lang:constants_1.Lang.CSHARP}),c=formatHttpMethod(t.method);if(u.withComments&&addComments(l),u.withWrapper&&(l.push("using System;"),l.push("using System.Net.Http;"),l.push("using System.Threading.Tasks;"),(m("application/json")||m("application/xml")||t.basicAuth)&&l.push("using System.Text;"),(m("application/x-www-form-urlencoded")||(null===(a=t.securityOAuth2ExtraCalls)||void 0===a?void 0:a.length))&&l.push("using System.Collections.Generic;"),(m("application/json")||(null===(n=t.securityOAuth2ExtraCalls)||void 0===n?void 0:n.length))&&l.push("using Newtonsoft.Json.Linq;"),t.headersObj&&"application/octet-stream"===t.headersObj["Content-Type"]&&(l.push("using System.IO;"),l.push("using System.Net.Http.Headers;")),l.blank(),l.push("public class Program"),l.push("{"),l.push(1,"public static async Task Main(string[] args)"),l.push(1,"{"),l.push(2,"using (var client = new HttpClient())"),l.push(2,"{")),null===(i=t.securityOAuth2ExtraCalls)||void 0===i?void 0:i.length){var h=new __1.HTTPSnippet(null===(r=t.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0]).convert(o,p,(0,tslib_1.__assign)((0,tslib_1.__assign)({},u),{withImports:!1,withWrapper:!1,withComments:!1,variablesPrefix:"oauth2"}));l.push(h),l.push(3,"var oauth2Response = await oauth2Request.Content.ReadAsStringAsync();"),l.push(3,"JObject inputJObject = JObject.Parse(oauth2Response);"),l.push(3,'var accessToken = inputJObject["access_token"].ToString();'),l.blank()}var d=Object.keys(t.allHeaders).filter((function(t){switch(t.toLowerCase()){case"content-type":case"content-length":case"accept-encoding":return!1;default:return!0}}));if(d.length&&d.forEach((function(e){var s;l.push(3,'client.DefaultRequestHeaders.Add("%s", %s);',e,(null===(s=t.securityOAuth2ExtraCalls)||void 0===s?void 0:s.length)?'"Bearer " + accessToken':'"'+t.allHeaders[e]+'"')})),t.basicAuth&&(l.push(3,'var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes($"<username>:<password>"));'),l.push(3,'client.DefaultRequestHeaders.Add("Authorization", "Basic "+ base64String);')),t.postData)switch((0,utils_1.normalizeMimeType)(t.postData.mimeType)){case"application/x-www-form-urlencoded":t.postData.params&&(l.blank(),l.push(3,"List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();"),t.postData.params.forEach((function(t){l.push(3,'postData.Add(new KeyValuePair<string, string>("%s", "%s"));',t.name,t.value)})),l.blank());break;case"multipart/form-data":t.postData.params&&(l.blank(),l.push(3,"MultipartFormDataContent postData = new MultipartFormDataContent();"),t.postData.params.forEach((function(t){l.push(3,'postData.Add(new StringContent("%s"), "%s");',t.value,t.name)})));break;case"application/json":t.postData.jsonObj&&(l.push(3,'JObject json = JObject.Parse(@"'+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(t.postData.jsonObj,{indent:u.indent,inlineCharacterLimit:25}).replace(/"/g,'""'),{level:3,firstLine:!1})+'");'),l.push(3,'var postData = new StringContent(json.ToString(), Encoding.UTF8, "application/json");'));break;case"application/xml":t.postData.text&&(t.postData.text.trim().split("\n").forEach((function(t,e){var s=(0===e?'string xml = @"':"")+t.replace(/"/g,'""');l.push(0===e?3:4,s)})),l.push(3,'";'),l.push(3,'var postData = new StringContent(xml, Encoding.UTF8, "application/xml");'))}else g()&&(l.push(3,"var ms = new MemoryStream();"),l.push(3,"var postData = new StreamContent(ms);"),l.push(3,'postData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");'));return(0,code_helpers_1.printUrlVariablesDeclarations)(t,l,3),l.push(3,"var %s = await client.%sAsync(%s%s);",l.var("request"),c,(0,code_helpers_1.buildUrlExpression)(t,l),u.withImports?isDataMethod(t.method)?"application/x-www-form-urlencoded"===(0,utils_1.normalizeMimeType)(t.postData&&t.postData.mimeType)?", new FormUrlEncodedContent(postData)":"delete"===t.method?"":t.postData&&t.postData.params||g()?", postData":", null":"":", new FormUrlEncodedContent(postData)"),u.withWrapper&&(l.push(3,"var response = await request.Content.ReadAsStringAsync();"),l.blank(),l.push(3,"Console.WriteLine(response);"),l.push(2,"}"),l.push(1,"}"),l.push("}")),l.join();function m(e){return t.postData&&(0,utils_1.normalizeMimeType)(t.postData.mimeType)===e}function g(){return t.headersObj&&"application/octet-stream"===t.headersObj["Content-Type"]}};function addComments(t){t.push("/*"),t.push(" * Requires >= .NET 5"),t.push(" *"),t.push(' * Requires package "Newtonsoft.Json" >= 9.01'),t.push(" * See here for installation details:"),t.push(" * https://www.newtonsoft.com/json"),t.push(" */"),t.blank()}function formatHttpMethod(t){return(0,generator_1.capitalizeFirst)(t.toLowerCase())}function isDataMethod(t){return t&&["POST","PUT","DELETE","PATCH"].includes(t.toUpperCase())}exports.info={key:"httpclient",title:"HttpClient",link:"https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient",description:".NET Standard HTTP Client"},exports.default=handler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),stringify_object_1=(0,tslib_1.__importDefault)(require("stringify-object")),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),code_helpers_1=require("../../helpers/code-helpers"),utils_1=require("../../../../utils"),generator_1=require("../../../generator"),constants_1=require("../../helpers/constants"),handler=function(t,e,s){var a,n,i,r,o=s.target,p=s.client,u=Object.assign({indent:" ",withWrapper:!0},e),l=new code_builder_1.CodeBuilder({indentation:u.indent,variablesPrefix:u.variablesPrefix,capitalize:!0,lang:constants_1.Lang.CSHARP}),c=formatHttpMethod(t.method);if(u.withComments&&addComments(l),u.withWrapper&&(l.push("using System;"),l.push("using System.Net.Http;"),l.push("using System.Threading.Tasks;"),(f("application/json")||f("application/xml")||t.basicAuth)&&l.push("using System.Text;"),(f("application/x-www-form-urlencoded")||(null===(a=t.securityOAuth2ExtraCalls)||void 0===a?void 0:a.length))&&l.push("using System.Collections.Generic;"),(f("application/json")||(null===(n=t.securityOAuth2ExtraCalls)||void 0===n?void 0:n.length))&&l.push("using Newtonsoft.Json.Linq;"),t.headersObj&&"application/octet-stream"===t.headersObj["Content-Type"]&&(l.push("using System.IO;"),l.push("using System.Net.Http.Headers;")),l.blank(),l.push("public class Program"),l.push("{"),l.push(1,"public static async Task Main(string[] args)"),l.push(1,"{"),l.push(2,"using (var client = new HttpClient())"),l.push(2,"{")),null===(i=t.securityOAuth2ExtraCalls)||void 0===i?void 0:i.length){var h=new __1.HTTPSnippet(null===(r=t.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0]).convert(o,p,(0,tslib_1.__assign)((0,tslib_1.__assign)({},u),{withImports:!1,withWrapper:!1,withComments:!1,variablesPrefix:"oauth2"}));l.push(h),l.push(3,"var oauth2Response = await oauth2Request.Content.ReadAsStringAsync();"),l.push(3,"JObject inputJObject = JObject.Parse(oauth2Response);"),l.push(3,'var accessToken = inputJObject["access_token"].ToString();'),l.blank()}var d=Object.keys(t.allHeaders).filter((function(t){switch(t.toLowerCase()){case"content-type":case"content-length":case"accept-encoding":return!1;default:return!0}}));if(d.length&&d.forEach((function(e){var s;l.push(3,'client.DefaultRequestHeaders.Add("%s", %s);',e,(null===(s=t.securityOAuth2ExtraCalls)||void 0===s?void 0:s.length)?'"Bearer " + accessToken':'"'+t.allHeaders[e]+'"')})),t.basicAuth){var m=t.basicAuth,g=m.username,b=m.password;l.push(3,'var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes("'+g+":"+b+'"));'),l.push(3,'client.DefaultRequestHeaders.Add("Authorization", "Basic "+ base64String);')}if(t.postData)switch((0,utils_1.normalizeMimeType)(t.postData.mimeType)){case"application/x-www-form-urlencoded":t.postData.params&&(l.blank(),l.push(3,"List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();"),t.postData.params.forEach((function(t){l.push(3,'postData.Add(new KeyValuePair<string, string>("%s", "%s"));',t.name,t.value)})),l.blank());break;case"multipart/form-data":t.postData.params&&(l.blank(),l.push(3,"MultipartFormDataContent postData = new MultipartFormDataContent();"),t.postData.params.forEach((function(t){l.push(3,'postData.Add(new StringContent("%s"), "%s");',t.value,t.name)})));break;case"application/json":t.postData.jsonObj&&(l.push(3,'JObject json = JObject.Parse(@"'+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(t.postData.jsonObj,{indent:u.indent,inlineCharacterLimit:25}).replace(/"/g,'""'),{level:3,firstLine:!1})+'");'),l.push(3,'var postData = new StringContent(json.ToString(), Encoding.UTF8, "application/json");'));break;case"application/xml":t.postData.text&&(t.postData.text.trim().split("\n").forEach((function(t,e){var s=(0===e?'string xml = @"':"")+t.replace(/"/g,'""');l.push(0===e?3:4,s)})),l.push(3,'";'),l.push(3,'var postData = new StringContent(xml, Encoding.UTF8, "application/xml");'))}else w()&&(l.push(3,"var ms = new MemoryStream();"),l.push(3,"var postData = new StreamContent(ms);"),l.push(3,'postData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");'));return(0,code_helpers_1.printUrlVariablesDeclarations)(t,l,3),l.push(3,"var %s = await client.%sAsync(%s%s);",l.var("request"),c,(0,code_helpers_1.buildUrlExpression)(t,l),u.withImports?isDataMethod(t.method)?"application/x-www-form-urlencoded"===(0,utils_1.normalizeMimeType)(t.postData&&t.postData.mimeType)?", new FormUrlEncodedContent(postData)":"delete"===t.method?"":t.postData&&t.postData.params||w()?", postData":", null":"":", new FormUrlEncodedContent(postData)"),u.withWrapper&&(l.push(3,"var response = await request.Content.ReadAsStringAsync();"),l.blank(),l.push(3,"Console.WriteLine(response);"),l.push(2,"}"),l.push(1,"}"),l.push("}")),l.join();function f(e){return t.postData&&(0,utils_1.normalizeMimeType)(t.postData.mimeType)===e}function w(){return t.headersObj&&"application/octet-stream"===t.headersObj["Content-Type"]}};function addComments(t){t.push("/*"),t.push(" * Requires >= .NET 5"),t.push(" *"),t.push(' * Requires package "Newtonsoft.Json" >= 9.01'),t.push(" * See here for installation details:"),t.push(" * https://www.newtonsoft.com/json"),t.push(" */"),t.blank()}function formatHttpMethod(t){return(0,generator_1.capitalizeFirst)(t.toLowerCase())}function isDataMethod(t){return t&&["POST","PUT","DELETE","PATCH"].includes(t.toUpperCase())}exports.info={key:"httpclient",title:"HttpClient",link:"https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient",description:".NET Standard HTTP Client"},exports.default=handler;
2
2
  //# sourceMappingURL=httpclient.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),constants_1=require("../../helpers/constants"),code_helpers_1=require("../../helpers/code-helpers"),utils_1=require("../../../../utils"),indent=1,contentType={X_FORM_URLENCODED:"application/x-www-form-urlencoded",JSON:"application/json",FORM_DATA:"multipart/form-data"};function hasMimeType(e,t){return void 0===e&&(e={}),(0,utils_1.normalizeMimeType)(e.mimeType)===t}var handler=function(e,t,n){var s,r,a,i,o,p,d=n.target,l=n.client,u=(0,tslib_1.__assign)({capitalize:!0,showBoilerplate:!0,checkErrors:!1,printBody:!0,timeout:-1,indent:" "},t),h=null===(s=e.securityOAuth2ExtraCalls)||void 0===s?void 0:s[0],c=u.checkErrors?"err":"_",v=e.method.toUpperCase(),y=new code_builder_1.CodeBuilder({indentation:u.indent,variablesPrefix:u.variablesPrefix,capitalize:u.capitalize,lang:constants_1.Lang.GO}),m=function(){u.checkErrors&&y.push(indent,"if err != nil {").push(indent+1,"panic(err)").push(indent,"}")};if(u.showBoilerplate&&(y.push("package main").blank().push("import (").push(indent,'"fmt"'),u.timeout>0&&y.push(indent,'"time"'),h&&y.push(indent,'"encoding/json"'),hasMimeType(e.postData,contentType.FORM_DATA)&&(y.push(indent,'"mime/multipart"'),y.push(indent,'"io"'),y.push(indent,'"bytes"')),(hasMimeType(e.postData,contentType.X_FORM_URLENCODED)||hasMimeType(null===(a=null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0])||void 0===a?void 0:a.postData,contentType.X_FORM_URLENCODED))&&(y.push(indent,'"net/url"'),y.push(indent,'"strconv"')),(hasMimeType(e.postData,contentType.JSON)||hasMimeType(null===(o=null===(i=e.securityOAuth2ExtraCalls)||void 0===i?void 0:i[0])||void 0===o?void 0:o.postData,contentType.JSON))&&y.push(indent,'"bytes"'),(e.postData&&!hasMimeType(e.postData,contentType.JSON)||h)&&y.push(indent,'"strings"'),y.push(indent,'"net/http"'),u.printBody&&y.push(indent,'"io/ioutil"'),y.push(")").blank().push("func main() {")),Object.keys(e.allHeaders).length&&Object.keys(e.allHeaders).forEach((function(t){e.allHeaders[t]='"'+e.allHeaders[t]+'"'})),h){var _="oAuth2",b=u.checkErrors?c+" := ":"",f=u.capitalize?"Res":"res",q=new __1.HTTPSnippet(h).convert(d,l,(0,tslib_1.__assign)((0,tslib_1.__assign)({},u),{printBody:!1,variablesPrefix:_,showBoilerplate:!1}));y.push(q).blank().push(indent,"var oAuth2"+f+"Body struct {").push(indent+1,"Access_token string").push(indent,"}").push(indent,b+"json.NewDecoder("+_+f+".Body).Decode(&"+_+f+"Body)").blank(),m(),e.allHeaders.Authorization='"Bearer " + oAuth2'+f+"Body.Access_token"}if((0,code_helpers_1.printUrlVariablesDeclarations)(e,y,indent),u.timeout>0&&(l=y.var("client"),y.push(indent,"%s := http.Client{",l).push(indent+1,"Timeout: time.Duration(%s * time.Second),",u.timeout).push(indent,"}").blank()),y.push(indent,y.var("reqUrl")+" := "+(0,code_helpers_1.buildUrlExpression)(e,y)),e.postData){var w=void 0;switch((0,utils_1.normalizeMimeType)(e.postData.mimeType)){case contentType.X_FORM_URLENCODED:y.push(indent,"%s := url.Values{}",y.var("data")),e.postData.params.forEach((function(e){y.push(indent,'%s.Set("%s", "%s")',y.var("data"),e.name,e.value)})),y.push(indent,'%s, %s := http.NewRequest("%s", %s, strings.NewReader(%s.Encode()))',y.var("req"),c,v,y.var("reqUrl"),y.var("data")),e.allHeaders["Content-Length"]="strconv.Itoa(len("+y.var("data")+".Encode()))";break;case contentType.JSON:w=JSON.stringify(e.postData.jsonObj,null,2).split("\n").map((function(e){return u.indent+e})).join("\n").trim(),y.push(indent,"var "+y.var("data")+" = []byte(`"+w+"`)"),y.push(indent,'%s, %s := http.NewRequest("%s", %s, bytes.NewBuffer(%s))',y.var("req"),c,v,y.var("reqUrl"),y.var("data"));break;case contentType.FORM_DATA:y.push(indent,"%s := &bytes.Buffer{}",y.var("data")).push(indent,"writer := multipart.NewWriter(%s)",y.var("data")),e.postData.params.forEach((function(e){if(!e.fileName&&!e.contentType)return y.push(indent,'%s, _ := writer.CreateFormField("%s")',y.var(e.name+"Fw"),e.name).push(indent,'_, %s = io.Copy(%s, strings.NewReader("%s"))',c,y.var(e.name+"Fw"),e.value),void m();e.fileName&&(y.push(indent,'%s, %s = writer.CreateFormFile("%s", "%s")',y.var(e.name+"Fw"),c,e.name,e.fileName),m())})),y.push(indent,"writer.Close()").blank().push(indent,"%s := bytes.NewReader(%s.Bytes())",y.var("payload"),y.var("data")).push(indent,'%s, %s := http.NewRequest("%s", %s, %s)',y.var("req"),c,v,y.var("reqUrl"),y.var("payload")),e.allHeaders["Content-Type"]="writer.FormDataContentType()";break;default:e.postData.text&&y.push(indent,"%s := strings.NewReader(%s)",y.var("payload"),JSON.stringify(null===(p=e.postData)||void 0===p?void 0:p.text)).push(indent,'%s, %s := http.NewRequest("%s", %s, %s)',y.var("req"),c,v,y.var("reqUrl"),y.var("payload"))}}else y.push(indent,'%s, %s := http.NewRequest("%s", %s, nil)',y.var("req"),c,v,y.var("reqUrl"));if(Object.getOwnPropertyNames(e.queryObj).length){for(var O in y.blank().push(indent,y.var("query")+" := "+y.var("req")+".URL.Query()"),e.queryObj)y.push(indent,y.var("query")+'.Add("'+O+'", "'+e.queryObj[O]+'")');y.push(indent,y.var("req")+".URL.RawQuery = "+y.var("query")+".Encode()").blank()}return m(),e.basicAuth&&y.push(indent,'%s.SetBasicAuth("<username>", "<password>")',y.var("req")),Object.keys(e.allHeaders).length&&Object.keys(e.allHeaders).forEach((function(t){y.push(indent,'%s.Header.Add("%s", %s)',y.var("req"),t,e.allHeaders[t])})),y.push(indent,"%s, %s := %s.Do(%s)",y.var("res"),c,l,y.var("req")),m(),u.printBody&&(y.push(indent,"defer %s.Body.Close()",y.var("res")).push(indent,"%s, %s := ioutil.ReadAll(%s.Body)",y.var("body"),c,y.var("res")),m()),y.blank().push(indent,"fmt.Println(%s)",y.var("res")),u.printBody&&y.push(indent,"fmt.Println(string(%s))",y.var("body")),u.showBoilerplate&&y.push("}"),y.join()};exports.info={key:"native",title:"NewRequest",link:"http://golang.org/pkg/net/http/#NewRequest",description:"Golang HTTP client request"},exports.default=handler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),constants_1=require("../../helpers/constants"),code_helpers_1=require("../../helpers/code-helpers"),utils_1=require("../../../../utils"),indent=1,contentType={X_FORM_URLENCODED:"application/x-www-form-urlencoded",JSON:"application/json",FORM_DATA:"multipart/form-data"};function hasMimeType(e,t){return void 0===e&&(e={}),(0,utils_1.normalizeMimeType)(e.mimeType)===t}var handler=function(e,t,n){var s,r,a,i,o,p,d=n.target,l=n.client,u=(0,tslib_1.__assign)({capitalize:!0,showBoilerplate:!0,checkErrors:!1,printBody:!0,timeout:-1,indent:" "},t),h=null===(s=e.securityOAuth2ExtraCalls)||void 0===s?void 0:s[0],c=u.checkErrors?"err":"_",v=e.method.toUpperCase(),y=new code_builder_1.CodeBuilder({indentation:u.indent,variablesPrefix:u.variablesPrefix,capitalize:u.capitalize,lang:constants_1.Lang.GO}),m=function(){u.checkErrors&&y.push(indent,"if err != nil {").push(indent+1,"panic(err)").push(indent,"}")};if(u.showBoilerplate&&(y.push("package main").blank().push("import (").push(indent,'"fmt"'),u.timeout>0&&y.push(indent,'"time"'),h&&y.push(indent,'"encoding/json"'),hasMimeType(e.postData,contentType.FORM_DATA)&&(y.push(indent,'"mime/multipart"'),y.push(indent,'"io"'),y.push(indent,'"bytes"')),(hasMimeType(e.postData,contentType.X_FORM_URLENCODED)||hasMimeType(null===(a=null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0])||void 0===a?void 0:a.postData,contentType.X_FORM_URLENCODED))&&(y.push(indent,'"net/url"'),y.push(indent,'"strconv"')),(hasMimeType(e.postData,contentType.JSON)||hasMimeType(null===(o=null===(i=e.securityOAuth2ExtraCalls)||void 0===i?void 0:i[0])||void 0===o?void 0:o.postData,contentType.JSON))&&y.push(indent,'"bytes"'),(e.postData&&!hasMimeType(e.postData,contentType.JSON)||h)&&y.push(indent,'"strings"'),y.push(indent,'"net/http"'),u.printBody&&y.push(indent,'"io/ioutil"'),y.push(")").blank().push("func main() {")),Object.keys(e.allHeaders).length&&Object.keys(e.allHeaders).forEach((function(t){e.allHeaders[t]='"'+e.allHeaders[t]+'"'})),h){var _="oAuth2",b=u.checkErrors?c+" := ":"",f=u.capitalize?"Res":"res",q=new __1.HTTPSnippet(h).convert(d,l,(0,tslib_1.__assign)((0,tslib_1.__assign)({},u),{printBody:!1,variablesPrefix:_,showBoilerplate:!1}));y.push(q).blank().push(indent,"var oAuth2"+f+"Body struct {").push(indent+1,"Access_token string").push(indent,"}").push(indent,b+"json.NewDecoder("+_+f+".Body).Decode(&"+_+f+"Body)").blank(),m(),e.allHeaders.Authorization='"Bearer " + oAuth2'+f+"Body.Access_token"}if((0,code_helpers_1.printUrlVariablesDeclarations)(e,y,indent),u.timeout>0&&(l=y.var("client"),y.push(indent,"%s := http.Client{",l).push(indent+1,"Timeout: time.Duration(%s * time.Second),",u.timeout).push(indent,"}").blank()),y.push(indent,y.var("reqUrl")+" := "+(0,code_helpers_1.buildUrlExpression)(e,y)),e.postData){var w=void 0;switch((0,utils_1.normalizeMimeType)(e.postData.mimeType)){case contentType.X_FORM_URLENCODED:y.push(indent,"%s := url.Values{}",y.var("data")),e.postData.params.forEach((function(e){y.push(indent,'%s.Set("%s", "%s")',y.var("data"),e.name,e.value)})),y.push(indent,'%s, %s := http.NewRequest("%s", %s, strings.NewReader(%s.Encode()))',y.var("req"),c,v,y.var("reqUrl"),y.var("data")),e.allHeaders["Content-Length"]="strconv.Itoa(len("+y.var("data")+".Encode()))";break;case contentType.JSON:w=JSON.stringify(e.postData.jsonObj,null,2).split("\n").map((function(e){return u.indent+e})).join("\n").trim(),y.push(indent,"var "+y.var("data")+" = []byte(`"+w+"`)"),y.push(indent,'%s, %s := http.NewRequest("%s", %s, bytes.NewBuffer(%s))',y.var("req"),c,v,y.var("reqUrl"),y.var("data"));break;case contentType.FORM_DATA:y.push(indent,"%s := &bytes.Buffer{}",y.var("data")).push(indent,"writer := multipart.NewWriter(%s)",y.var("data")),e.postData.params.forEach((function(e){if(!e.fileName&&!e.contentType)return y.push(indent,'%s, _ := writer.CreateFormField("%s")',y.var(e.name+"Fw"),e.name).push(indent,'_, %s = io.Copy(%s, strings.NewReader("%s"))',c,y.var(e.name+"Fw"),e.value),void m();e.fileName&&(y.push(indent,'%s, %s = writer.CreateFormFile("%s", "%s")',y.var(e.name+"Fw"),c,e.name,e.fileName),m())})),y.push(indent,"writer.Close()").blank().push(indent,"%s := bytes.NewReader(%s.Bytes())",y.var("payload"),y.var("data")).push(indent,'%s, %s := http.NewRequest("%s", %s, %s)',y.var("req"),c,v,y.var("reqUrl"),y.var("payload")),e.allHeaders["Content-Type"]="writer.FormDataContentType()";break;default:e.postData.text&&y.push(indent,"%s := strings.NewReader(%s)",y.var("payload"),JSON.stringify(null===(p=e.postData)||void 0===p?void 0:p.text)).push(indent,'%s, %s := http.NewRequest("%s", %s, %s)',y.var("req"),c,v,y.var("reqUrl"),y.var("payload"))}}else y.push(indent,'%s, %s := http.NewRequest("%s", %s, nil)',y.var("req"),c,v,y.var("reqUrl"));if(Object.getOwnPropertyNames(e.queryObj).length){for(var O in y.blank().push(indent,y.var("query")+" := "+y.var("req")+".URL.Query()"),e.queryObj)y.push(indent,y.var("query")+'.Add("'+O+'", "'+e.queryObj[O]+'")');y.push(indent,y.var("req")+".URL.RawQuery = "+y.var("query")+".Encode()").blank()}if(m(),e.basicAuth){var T=e.basicAuth,D=T.username,N=T.password;y.push(indent,'%s.SetBasicAuth("'+D+'", "'+N+'")',y.var("req"))}return Object.keys(e.allHeaders).length&&Object.keys(e.allHeaders).forEach((function(t){y.push(indent,'%s.Header.Add("%s", %s)',y.var("req"),t,e.allHeaders[t])})),y.push(indent,"%s, %s := %s.Do(%s)",y.var("res"),c,l,y.var("req")),m(),u.printBody&&(y.push(indent,"defer %s.Body.Close()",y.var("res")).push(indent,"%s, %s := ioutil.ReadAll(%s.Body)",y.var("body"),c,y.var("res")),m()),y.blank().push(indent,"fmt.Println(%s)",y.var("res")),u.printBody&&y.push(indent,"fmt.Println(string(%s))",y.var("body")),u.showBoilerplate&&y.push("}"),y.join()};exports.info={key:"native",title:"NewRequest",link:"http://golang.org/pkg/net/http/#NewRequest",description:"Golang HTTP client request"},exports.default=handler;
2
2
  //# sourceMappingURL=native.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),utils_1=require("../../../../utils"),code_helpers_1=require("../../helpers/code-helpers"),constants_1=require("../../helpers/constants"),URL_ENCODED="application/x-www-form-urlencoded",hasQueryParams=function(e){return!(!e.uriObj.query||!Object.keys(e.uriObj.query).length)},getBody=function(e){return e.postData&&e.postData.mimeType===URL_ENCODED?"HttpRequest.BodyPublishers.ofString(form)":e.postData?"HttpRequest.BodyPublishers.ofString(payload)":["POST","PUT","PATCH"].includes(e.method.toUpperCase())?'HttpRequest.BodyPublishers.ofString("some body text")':""},handler=function(e,t,a){var s,r,i,n=a.target,o=a.client,p=Object.assign({indent:" ",withWrapper:!0},t),l=new code_builder_1.CodeBuilder({indentation:p.indent,variablesPrefix:p.variablesPrefix,capitalize:!0,lang:constants_1.Lang.JAVA}),u=!1;if(p.withComments&&addComments(l,e),p.withImports&&addImports(l,e),p.withWrapper&&(l.push("public class App {"),l.push(1,"public static void main(String[] args) throws Exception {"),l.push(2,"var httpClient = HttpClient.newBuilder().build();"),l.blank()),null===(s=e.securityOAuth2ExtraCalls)||void 0===s?void 0:s.length){var h=new __1.HTTPSnippet(null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0]).convert(n,o,(0,tslib_1.__assign)((0,tslib_1.__assign)({},p),{withImports:!1,withWrapper:!1,withComments:!1,variablesPrefix:"oauth2"}));l.push(h),l.blank(),l.push(2,"var oauth2Response = httpClient.send(oauth2Request, HttpResponse.BodyHandlers.ofString());"),l.push(2,'var accessToken = new JSONObject(oauth2Response.body()).getString("access_token");'),l.blank()}if(e.postData)switch((0,utils_1.normalizeMimeType)(e.postData.mimeType)){case URL_ENCODED:e.postData.params&&(l.push(2,"HashMap<String, String> params = new HashMap<>();"),e.postData.params.forEach((function(e){l.push(2,'params.put("%s", "%s");',e.name,e.value)})),l.blank(),l.push(2,"var form = params.keySet().stream()"),l.push(3,'.map(key -> key + "=" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))'),l.push(3,'.collect(Collectors.joining("&"));'),l.blank());break;case"application/json":e.postData.jsonObj&&(l.push(2,'var payload = String.join("\\n"\n '+(0,code_helpers_1.addIndentation)(JSON.stringify(e.postData.jsonObj,null,1).replace(/"/g,'\\"').replace(/^/gm,', "').replace(/$/gm,'"'),{level:3,indent:p.indent,firstLine:!1})),l.push(2,");"),l.blank());break;case"application/xml":e.postData.text&&(l.push(2,'var payload = String.join("\\n"'),e.postData.text.trim().split("\n").forEach((function(e){var t=e.replace(/"/g,'\\"');l.push(3,', "'+t+'"')})),l.push(2,");"),l.blank());break;case"multipart/form-data":u=!0,l.unshift("# multipart/form-data is not supported yet\n")}if(hasQueryParams(e)){l.push(2,"HashMap<String, String> params = new HashMap<>();");for(var d=0,c=Object.entries(e.uriObj.query);d<c.length;d++){var m=c[d],v=m[0],b=m[1];l.push(2,'params.put("%s", "%s");',v,b)}l.blank(),l.push(2,"var query = params.keySet().stream()"),l.push(3,'.map(key -> key + "=" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))'),l.push(3,'.collect(Collectors.joining("&"));'),l.blank()}l.push(2,"var "+l.var("host")+' = "%s";',e.uriObj.protocol+"//"+e.uriObj.host),(0,code_helpers_1.printUrlVariablesDeclarations)(e,l,2);var g=(0,tslib_1.__assign)((0,tslib_1.__assign)({},e),{pathname:e.uriObj.pathname});l.push(2,"var "+l.var("pathname")+" = %s;",(0,code_helpers_1.buildUrlExpression)(g,l)),l.push(2,"var "+l.var("request")+" = HttpRequest.newBuilder()"),"PATCH"===e.method.toUpperCase()?l.push(3,'.method("PATCH", %s)',getBody(e)):l.push(3,".%s(%s)",e.method.toUpperCase(),getBody(e)),l.push(3,".uri(URI.create("+l.var("host")+" + "+l.var("pathname")+" %s))",hasQueryParams(e)?"+ '?' + query":""),(null===(i=e.securityOAuth2ExtraCalls)||void 0===i?void 0:i.length)&&(e.allHeaders.Authorization='"Bearer " + accessToken');var y=Object.keys(e.allHeaders);return y.length&&y.forEach((function(t){var a;l.push(3,'.header("%s", %s)',t,"Authorization"===t&&(null===(a=e.securityOAuth2ExtraCalls)||void 0===a?void 0:a.length)?e.allHeaders[t]:'"'+e.allHeaders[t]+'"')})),e.basicAuth&&l.push(3,'.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(("<username>:<password>").getBytes()))'),l.push(3,".build();"),p.withWrapper&&(l.blank(),l.push(2,"var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());"),l.blank(),l.push(2,"System.out.println(response.body());"),l.push(1,"}"),l.push("}")),u&&l.clean(),l.join()};function addComments(e,t){var a;e.push("/**"),e.push(" * Requires JDK >= 11"),(null===(a=t.securityOAuth2ExtraCalls)||void 0===a?void 0:a.length)&&(e.push(" *"),e.push(' * Requires package "org.json" >= 20201115'),e.push(" * See here for installation details:"),e.push(" * https://search.maven.org/artifact/org.json/json")),e.push(" */"),e.blank()}function addImports(e,t){var a,s,r,i;e.push("import java.net.*;"),e.push("import java.net.http.*;"),e.push("import java.util.*;"),((0,utils_1.normalizeMimeType)(null===(a=t.postData)||void 0===a?void 0:a.mimeType)===URL_ENCODED&&(null===(s=t.postData)||void 0===s?void 0:s.params)||(null===(r=t.securityOAuth2ExtraCalls)||void 0===r?void 0:r.length)||hasQueryParams(t))&&(e.push("import java.nio.charset.StandardCharsets;"),e.push("import java.util.stream.Collectors;")),(null===(i=t.securityOAuth2ExtraCalls)||void 0===i?void 0:i.length)&&e.push("import org.json.JSONObject;"),e.blank()}exports.info={key:"httpclient",title:"HttpClient",link:"https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html",description:"HttpClient (Java SE 11 & JDK 11 )"},exports.default=handler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),utils_1=require("../../../../utils"),code_helpers_1=require("../../helpers/code-helpers"),constants_1=require("../../helpers/constants"),URL_ENCODED="application/x-www-form-urlencoded",hasQueryParams=function(e){return!(!e.uriObj.query||!Object.keys(e.uriObj.query).length)},getBody=function(e){return e.postData&&e.postData.mimeType===URL_ENCODED?"HttpRequest.BodyPublishers.ofString(form)":e.postData?"HttpRequest.BodyPublishers.ofString(payload)":["POST","PUT","PATCH"].includes(e.method.toUpperCase())?'HttpRequest.BodyPublishers.ofString("some body text")':""},handler=function(e,t,a){var s,r,i,n=a.target,o=a.client,p=Object.assign({indent:" ",withWrapper:!0},t),l=new code_builder_1.CodeBuilder({indentation:p.indent,variablesPrefix:p.variablesPrefix,capitalize:!0,lang:constants_1.Lang.JAVA}),u=!1;if(p.withComments&&addComments(l,e),p.withImports&&addImports(l,e),p.withWrapper&&(l.push("public class App {"),l.push(1,"public static void main(String[] args) throws Exception {"),l.push(2,"var httpClient = HttpClient.newBuilder().build();"),l.blank()),null===(s=e.securityOAuth2ExtraCalls)||void 0===s?void 0:s.length){var h=new __1.HTTPSnippet(null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0]).convert(n,o,(0,tslib_1.__assign)((0,tslib_1.__assign)({},p),{withImports:!1,withWrapper:!1,withComments:!1,variablesPrefix:"oauth2"}));l.push(h),l.blank(),l.push(2,"var oauth2Response = httpClient.send(oauth2Request, HttpResponse.BodyHandlers.ofString());"),l.push(2,'var accessToken = new JSONObject(oauth2Response.body()).getString("access_token");'),l.blank()}if(e.postData)switch((0,utils_1.normalizeMimeType)(e.postData.mimeType)){case URL_ENCODED:e.postData.params&&(l.push(2,"HashMap<String, String> params = new HashMap<>();"),e.postData.params.forEach((function(e){l.push(2,'params.put("%s", "%s");',e.name,e.value)})),l.blank(),l.push(2,"var form = params.keySet().stream()"),l.push(3,'.map(key -> key + "=" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))'),l.push(3,'.collect(Collectors.joining("&"));'),l.blank());break;case"application/json":e.postData.jsonObj&&(l.push(2,'var payload = String.join("\\n"\n '+(0,code_helpers_1.addIndentation)(JSON.stringify(e.postData.jsonObj,null,1).replace(/"/g,'\\"').replace(/^/gm,', "').replace(/$/gm,'"'),{level:3,indent:p.indent,firstLine:!1})),l.push(2,");"),l.blank());break;case"application/xml":e.postData.text&&(l.push(2,'var payload = String.join("\\n"'),e.postData.text.trim().split("\n").forEach((function(e){var t=e.replace(/"/g,'\\"');l.push(3,', "'+t+'"')})),l.push(2,");"),l.blank());break;case"multipart/form-data":u=!0,l.unshift("# multipart/form-data is not supported yet\n")}if(hasQueryParams(e)){l.push(2,"HashMap<String, String> params = new HashMap<>();");for(var d=0,c=Object.entries(e.uriObj.query);d<c.length;d++){var m=c[d],v=m[0],b=m[1];l.push(2,'params.put("%s", "%s");',v,b)}l.blank(),l.push(2,"var query = params.keySet().stream()"),l.push(3,'.map(key -> key + "=" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))'),l.push(3,'.collect(Collectors.joining("&"));'),l.blank()}l.push(2,"var "+l.var("host")+' = "%s";',e.uriObj.protocol+"//"+e.uriObj.host),(0,code_helpers_1.printUrlVariablesDeclarations)(e,l,2);var g=(0,tslib_1.__assign)((0,tslib_1.__assign)({},e),{pathname:e.uriObj.pathname});l.push(2,"var "+l.var("pathname")+" = %s;",(0,code_helpers_1.buildUrlExpression)(g,l)),l.push(2,"var "+l.var("request")+" = HttpRequest.newBuilder()"),"PATCH"===e.method.toUpperCase()?l.push(3,'.method("PATCH", %s)',getBody(e)):l.push(3,".%s(%s)",e.method.toUpperCase(),getBody(e)),l.push(3,".uri(URI.create("+l.var("host")+" + "+l.var("pathname")+" %s))",hasQueryParams(e)?"+ '?' + query":""),(null===(i=e.securityOAuth2ExtraCalls)||void 0===i?void 0:i.length)&&(e.allHeaders.Authorization='"Bearer " + accessToken');var y=Object.keys(e.allHeaders);if(y.length&&y.forEach((function(t){var a;l.push(3,'.header("%s", %s)',t,"Authorization"===t&&(null===(a=e.securityOAuth2ExtraCalls)||void 0===a?void 0:a.length)?e.allHeaders[t]:'"'+e.allHeaders[t]+'"')})),e.basicAuth){var _=e.basicAuth,f=_.username,j=_.password;l.push(3,'.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(("'+f+":"+j+'").getBytes()))')}return l.push(3,".build();"),p.withWrapper&&(l.blank(),l.push(2,"var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());"),l.blank(),l.push(2,"System.out.println(response.body());"),l.push(1,"}"),l.push("}")),u&&l.clean(),l.join()};function addComments(e,t){var a;e.push("/**"),e.push(" * Requires JDK >= 11"),(null===(a=t.securityOAuth2ExtraCalls)||void 0===a?void 0:a.length)&&(e.push(" *"),e.push(' * Requires package "org.json" >= 20201115'),e.push(" * See here for installation details:"),e.push(" * https://search.maven.org/artifact/org.json/json")),e.push(" */"),e.blank()}function addImports(e,t){var a,s,r,i;e.push("import java.net.*;"),e.push("import java.net.http.*;"),e.push("import java.util.*;"),((0,utils_1.normalizeMimeType)(null===(a=t.postData)||void 0===a?void 0:a.mimeType)===URL_ENCODED&&(null===(s=t.postData)||void 0===s?void 0:s.params)||(null===(r=t.securityOAuth2ExtraCalls)||void 0===r?void 0:r.length)||hasQueryParams(t))&&(e.push("import java.nio.charset.StandardCharsets;"),e.push("import java.util.stream.Collectors;")),(null===(i=t.securityOAuth2ExtraCalls)||void 0===i?void 0:i.length)&&e.push("import org.json.JSONObject;"),e.blank()}exports.info={key:"httpclient",title:"HttpClient",link:"https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html",description:"HttpClient (Java SE 11 & JDK 11 )"},exports.default=handler;
2
2
  //# sourceMappingURL=httpclient.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),utils_1=require("../../../../utils"),generator_1=require("../../../generator"),constants_1=require("../../helpers/constants"),code_helpers_1=require("../../helpers/code-helpers"),handler=function(t,e,a){var s,r,i=a.target,p=a.client,n=Object.assign({indent:" ",withWrapper:!0},e),o=new code_builder_1.CodeBuilder({indentation:n.indent,variablesPrefix:n.variablesPrefix,capitalize:!0,lang:constants_1.Lang.JAVA8}),u=formatHttpMethod(t.method);if(n.withComments&&addComments(o),n.withImports&&addImports(o,t),n.withWrapper&&(o.push("public class App {"),o.push(1,"public static void main(String[] args ) throws java.io.IOException {"),o.push(2,"HttpClient httpClient = HttpClientBuilder.create().build();"),o.blank()),null===(s=t.securityOAuth2ExtraCalls)||void 0===s?void 0:s.length){var h=new __1.HTTPSnippet(null===(r=t.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0]).convert(i,p,(0,tslib_1.__assign)((0,tslib_1.__assign)({},n),{withImports:!1,withWrapper:!1,withComments:!1,variablesPrefix:"oauth2"}));o.push(h),o.push(2,"JSONObject %s = new JSONObject(EntityUtils.toString(httpClient.execute(%s).getEntity()));","oauth2Response","oauth2Request"),o.push(2,'String accessToken = %s.getString("access_token");',"oauth2Response"),o.blank()}(0,code_helpers_1.printUrlVariablesDeclarations)(t,o,2);var l=(0,code_helpers_1.buildUrlExpression)(t,o);o.push(2,"%s "+o.var("request")+" = new %s(%s);",u,u,l);var c=Object.keys(t.allHeaders);if(!c.length||t.postData&&"multipart/form-data"==t.postData.mimeType||c.forEach((function(e){var a;o.push(2,'%s.setHeader("%s", %s);',o.var("request"),e,(null===(a=t.securityOAuth2ExtraCalls)||void 0===a?void 0:a.length)?'"Bearer " + accessToken':'"'+t.allHeaders[e]+'"')})),t.basicAuth&&(o.push(2,'String encodedString = Base64.getEncoder().encodeToString("<username>:<password>".getBytes());'),o.push(2,'%s.setHeader("%s", "%s"+encodedString);',o.var("request"),"Authorization","Basic ")),t.postData)switch((0,utils_1.normalizeMimeType)(t.postData.mimeType)){case"application/x-www-form-urlencoded":t.postData.params&&(o.blank(),o.push(2,"List<NameValuePair> params = new ArrayList<NameValuePair>();"),t.postData.params.forEach((function(t){o.push(2,'params.add(new BasicNameValuePair("%s", "%s"));',t.name,t.value)})),o.push(2,"%s.setEntity(new UrlEncodedFormEntity(params));",o.var("request")),o.blank());break;case"multipart/form-data":t.postData.params&&(o.push(2,"MultipartEntity reqEntity = new MultipartEntity();"),t.postData.params.forEach((function(t){o.push(2,'reqEntity.addPart("%s", %s);',t.name,isString(t.value)?'new StringBody("'+t.value+'")':t.value)})),o.push(2,"%s.setEntity(reqEntity);",o.var("request")));break;case"application/json":if(t.postData.jsonObj){o.push(2,"JSONObject payload = new JSONObject();");for(var d=0,m=Object.entries(t.postData.jsonObj);d<m.length;d++){var g=m[d],y=g[0],b=g[1];Array.isArray(b)?(o.push(2,'payload.put("%s", new JSONArray()',y),b.forEach((function(t){isObject(t)?(o.push(3,".put(new JSONObject()"),v(t,4),o.push(3,")")):o.push(3,".put(%s)",formatValue(t))})),o.push(2,");")):isObject(b)?(o.push(2,'payload.put("%s", new JSONObject()%s',y,(0,utils_1.isEmptyObject)(b)?");":""),v(b,3),(0,utils_1.isEmptyObject)(b)||o.push(2,");")):o.push(2,'payload.put("%s", %s);',y,formatValue(b))}o.push(2,"%s.setEntity(new StringEntity(payload.toString()));",o.var("request"))}break;case"application/xml":t.postData.text&&(o.push(2,'String payload = String.join("\\n"'),t.postData.text.trim().split("\n").forEach((function(t){var e=t.replace(/"/g,'\\"');o.push(3,', "'+e+'"')})),o.push(2,");"),o.push(2,"%s.setEntity(new StringEntity(payload));",o.var("request")))}return n.withWrapper&&(o.push(2,"String "+o.var("response")+" = EntityUtils.toString(httpClient.execute(request).getEntity());"),o.blank(),o.push(2,"System.out.println(response);"),o.push(1,"}"),o.push("}")),o.join();function v(t,e){for(var a=0,s=Object.entries(t);a<s.length;a++){var r=s[a],i=r[0],p=r[1];isObject(p)?(o.push(e,'.put("%s", new JSONObject()',i),v(p,e+1),o.push(e,")")):o.push(e,'.put("%s", %s)',i,formatValue(p))}}};function addComments(t){t.push("/**"),t.push(" * Requires JDK >= 8"),t.push(" *"),t.push(" * Requires Apache HttpComponents Client >= 4.3.5"),t.push(" * See here for installation details:"),t.push(" * https://search.maven.org/artifact/org.apache.httpcomponents/httpcomponents-client"),t.push(" *"),t.push(' * Requires package "junit4"'),t.push(" * See here for installation details:"),t.push(" * https://junit.org/junit4"),t.push(" *"),t.push(' * Requires package "org.json" >= 20180130'),t.push(" * See here for installation details:"),t.push(" * https://search.maven.org/artifact/org.json/json"),t.push(" */"),t.blank()}function addImports(t,e){var a,s,r;t.push("import org.apache.http.util.EntityUtils;"),t.push("import org.apache.http.NameValuePair;"),t.push("import org.apache.http.client.HttpClient;"),t.push("import org.apache.http.client.entity.UrlEncodedFormEntity;"),e.method&&addHttpMethodImport(t,e.method),(null===(a=e.securityOAuth2ExtraCalls)||void 0===a?void 0:a.length)&&(null===(s=e.securityOAuth2ExtraCalls)||void 0===s?void 0:s[0].method.toLowerCase())!==e.method.toLowerCase()&&addHttpMethodImport(t,null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0].method),t.push("import org.apache.http.impl.client.HttpClientBuilder;"),t.push("import org.apache.http.message.BasicNameValuePair;"),t.push("import org.apache.http.entity.StringEntity;"),t.push("import org.json.JSONObject;"),t.push("import org.json.JSONArray;"),t.push("import java.util.ArrayList;"),t.push("import java.util.List;"),t.push("import org.apache.http.entity.mime.MultipartEntity;"),t.push("import org.apache.http.entity.mime.content.StringBody;"),e.basicAuth&&t.push("import java.util.Base64;"),t.blank()}function addHttpMethodImport(t,e){var a=formatHttpMethod(e);t.push("import org.apache.http.client.methods."+a+";")}function formatHttpMethod(t){return"Http"+(0,generator_1.capitalizeFirst)(t.toLowerCase())}function isString(t){return"[object String]"===Object.prototype.toString.call(t)}function isObject(t){var e=typeof t;return"function"===e||"object"===e&&!!t}function formatValue(t){return isString(t)?JSON.stringify(t):null==t?"JSONObject.NULL":t}exports.info={key:"apachehttp",title:"Apache http",link:"https://hc.apache.org/httpcomponents-client-4.5.x/",description:"Apache HttpClient"},exports.default=handler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),utils_1=require("../../../../utils"),generator_1=require("../../../generator"),constants_1=require("../../helpers/constants"),code_helpers_1=require("../../helpers/code-helpers"),handler=function(t,e,a){var s,r,i=a.target,p=a.client,n=Object.assign({indent:" ",withWrapper:!0},e),o=new code_builder_1.CodeBuilder({indentation:n.indent,variablesPrefix:n.variablesPrefix,capitalize:!0,lang:constants_1.Lang.JAVA8}),u=formatHttpMethod(t.method);if(n.withComments&&addComments(o),n.withImports&&addImports(o,t),n.withWrapper&&(o.push("public class App {"),o.push(1,"public static void main(String[] args ) throws java.io.IOException {"),o.push(2,"HttpClient httpClient = HttpClientBuilder.create().build();"),o.blank()),null===(s=t.securityOAuth2ExtraCalls)||void 0===s?void 0:s.length){var h=new __1.HTTPSnippet(null===(r=t.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0]).convert(i,p,(0,tslib_1.__assign)((0,tslib_1.__assign)({},n),{withImports:!1,withWrapper:!1,withComments:!1,variablesPrefix:"oauth2"}));o.push(h),o.push(2,"JSONObject %s = new JSONObject(EntityUtils.toString(httpClient.execute(%s).getEntity()));","oauth2Response","oauth2Request"),o.push(2,'String accessToken = %s.getString("access_token");',"oauth2Response"),o.blank()}(0,code_helpers_1.printUrlVariablesDeclarations)(t,o,2);var l=(0,code_helpers_1.buildUrlExpression)(t,o);o.push(2,"%s "+o.var("request")+" = new %s(%s);",u,u,l);var c=Object.keys(t.allHeaders);if(!c.length||t.postData&&"multipart/form-data"==t.postData.mimeType||c.forEach((function(e){var a;o.push(2,'%s.setHeader("%s", %s);',o.var("request"),e,(null===(a=t.securityOAuth2ExtraCalls)||void 0===a?void 0:a.length)?'"Bearer " + accessToken':'"'+t.allHeaders[e]+'"')})),t.basicAuth){var d=t.basicAuth,m=d.username,g=d.password;o.push(2,'String encodedString = Base64.getEncoder().encodeToString("'+m+":"+g+'".getBytes());'),o.push(2,'%s.setHeader("%s", "%s"+encodedString);',o.var("request"),"Authorization","Basic ")}if(t.postData)switch((0,utils_1.normalizeMimeType)(t.postData.mimeType)){case"application/x-www-form-urlencoded":t.postData.params&&(o.blank(),o.push(2,"List<NameValuePair> params = new ArrayList<NameValuePair>();"),t.postData.params.forEach((function(t){o.push(2,'params.add(new BasicNameValuePair("%s", "%s"));',t.name,t.value)})),o.push(2,"%s.setEntity(new UrlEncodedFormEntity(params));",o.var("request")),o.blank());break;case"multipart/form-data":t.postData.params&&(o.push(2,"MultipartEntity reqEntity = new MultipartEntity();"),t.postData.params.forEach((function(t){o.push(2,'reqEntity.addPart("%s", %s);',t.name,isString(t.value)?'new StringBody("'+t.value+'")':t.value)})),o.push(2,"%s.setEntity(reqEntity);",o.var("request")));break;case"application/json":if(t.postData.jsonObj){o.push(2,"JSONObject payload = new JSONObject();");for(var y=0,b=Object.entries(t.postData.jsonObj);y<b.length;y++){var v=b[y],f=v[0],j=v[1];Array.isArray(j)?(o.push(2,'payload.put("%s", new JSONArray()',f),j.forEach((function(t){isObject(t)?(o.push(3,".put(new JSONObject()"),O(t,4),o.push(3,")")):o.push(3,".put(%s)",formatValue(t))})),o.push(2,");")):isObject(j)?(o.push(2,'payload.put("%s", new JSONObject()%s',f,(0,utils_1.isEmptyObject)(j)?");":""),O(j,3),(0,utils_1.isEmptyObject)(j)||o.push(2,");")):o.push(2,'payload.put("%s", %s);',f,formatValue(j))}o.push(2,"%s.setEntity(new StringEntity(payload.toString()));",o.var("request"))}break;case"application/xml":t.postData.text&&(o.push(2,'String payload = String.join("\\n"'),t.postData.text.trim().split("\n").forEach((function(t){var e=t.replace(/"/g,'\\"');o.push(3,', "'+e+'"')})),o.push(2,");"),o.push(2,"%s.setEntity(new StringEntity(payload));",o.var("request")))}return n.withWrapper&&(o.push(2,"String "+o.var("response")+" = EntityUtils.toString(httpClient.execute(request).getEntity());"),o.blank(),o.push(2,"System.out.println(response);"),o.push(1,"}"),o.push("}")),o.join();function O(t,e){for(var a=0,s=Object.entries(t);a<s.length;a++){var r=s[a],i=r[0],p=r[1];isObject(p)?(o.push(e,'.put("%s", new JSONObject()',i),O(p,e+1),o.push(e,")")):o.push(e,'.put("%s", %s)',i,formatValue(p))}}};function addComments(t){t.push("/**"),t.push(" * Requires JDK >= 8"),t.push(" *"),t.push(" * Requires Apache HttpComponents Client >= 4.3.5"),t.push(" * See here for installation details:"),t.push(" * https://search.maven.org/artifact/org.apache.httpcomponents/httpcomponents-client"),t.push(" *"),t.push(' * Requires package "junit4"'),t.push(" * See here for installation details:"),t.push(" * https://junit.org/junit4"),t.push(" *"),t.push(' * Requires package "org.json" >= 20180130'),t.push(" * See here for installation details:"),t.push(" * https://search.maven.org/artifact/org.json/json"),t.push(" */"),t.blank()}function addImports(t,e){var a,s,r;t.push("import org.apache.http.util.EntityUtils;"),t.push("import org.apache.http.NameValuePair;"),t.push("import org.apache.http.client.HttpClient;"),t.push("import org.apache.http.client.entity.UrlEncodedFormEntity;"),e.method&&addHttpMethodImport(t,e.method),(null===(a=e.securityOAuth2ExtraCalls)||void 0===a?void 0:a.length)&&(null===(s=e.securityOAuth2ExtraCalls)||void 0===s?void 0:s[0].method.toLowerCase())!==e.method.toLowerCase()&&addHttpMethodImport(t,null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0].method),t.push("import org.apache.http.impl.client.HttpClientBuilder;"),t.push("import org.apache.http.message.BasicNameValuePair;"),t.push("import org.apache.http.entity.StringEntity;"),t.push("import org.json.JSONObject;"),t.push("import org.json.JSONArray;"),t.push("import java.util.ArrayList;"),t.push("import java.util.List;"),t.push("import org.apache.http.entity.mime.MultipartEntity;"),t.push("import org.apache.http.entity.mime.content.StringBody;"),e.basicAuth&&t.push("import java.util.Base64;"),t.blank()}function addHttpMethodImport(t,e){var a=formatHttpMethod(e);t.push("import org.apache.http.client.methods."+a+";")}function formatHttpMethod(t){return"Http"+(0,generator_1.capitalizeFirst)(t.toLowerCase())}function isString(t){return"[object String]"===Object.prototype.toString.call(t)}function isObject(t){var e=typeof t;return"function"===e||"object"===e&&!!t}function formatValue(t){return isString(t)?JSON.stringify(t):null==t?"JSONObject.NULL":t}exports.info={key:"apachehttp",title:"Apache http",link:"https://hc.apache.org/httpcomponents-client-4.5.x/",description:"Apache HttpClient"},exports.default=handler;
2
2
  //# sourceMappingURL=apachehttp.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),code_builder_1=require("../../helpers/code-builder"),stringify_object_1=(0,tslib_1.__importDefault)(require("stringify-object")),code_helpers_1=require("../../helpers/code-helpers"),utils_1=require("../../../../utils"),__1=require("../.."),constants_1=require("../../helpers/constants"),handler=function(e,t,a){var r,i,n,s,o,l=a.target,d=a.client,p=(0,tslib_1.__assign)({indent:" ",credentials:null},t),c=new code_builder_1.CodeBuilder({indentation:p.indent,variablesPrefix:p.variablesPrefix,capitalize:!0,lang:constants_1.Lang.JAVASCRIPT}),h={method:e.method.toUpperCase()};Object.keys(e.headersObj).length&&(h.headers=e.headersObj);var u=!1;if(p.withComments&&addComments(c),null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r.length){var _=new __1.HTTPSnippet(null===(i=e.securityOAuth2ExtraCalls)||void 0===i?void 0:i[0]).convert(l,d,(0,tslib_1.__assign)((0,tslib_1.__assign)({},p),{withImports:!1,withComments:!1,variablesPrefix:"oAuth2"}));c.push(_),c.blank(),h.headers=h.headers||{},h.headers.Authorization="'Bearer ' + oAuth2Data.access_token",u=!0}null!==p.credentials&&(h.credentials=p.credentials);var m=Object.getOwnPropertyNames(e.queryObj).length;if(m&&c.push("const "+c.var("query")+" = new URLSearchParams("+(0,stringify_object_1.default)(e.queryObj,{indent:p.indent,inlineCharacterLimit:25})+").toString();").blank(),e.postData)switch((0,utils_1.normalizeMimeType)(e.postData.mimeType)){case"application/x-www-form-urlencoded":h.body=e.postData.paramsObj?"new URLSearchParams("+c.var("formData")+").toString()":e.postData.text,e.postData.paramsObj&&c.push("const "+c.var("formData")+" = "+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(e.postData.paramsObj,{indent:p.indent,inlineCharacterLimit:25}),{level:0,firstLine:!1})+";").blank();break;case"application/json":e.postData.jsonObj&&(h.body="JSON.stringify("+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(e.postData.jsonObj,{indent:p.indent,inlineCharacterLimit:25}),{level:1,firstLine:!1})+")");break;case"multipart/form-data":c.push("const "+c.var("form")+" = new FormData();"),(null===(n=null==h?void 0:h.headers)||void 0===n?void 0:n["Content-Type"])&&(null===(s=h.headers)||void 0===s||delete s["Content-Type"]),e.postData.params.forEach((function(e){c.push(c.var("form")+".append(%s, %s);",JSON.stringify(e.name),JSON.stringify(e.value||e.fileName||""))})),h.body=c.var("form"),c.blank();break;default:e.postData.text&&(h.body="`"+(0,code_helpers_1.addIndentation)(e.postData.text,{level:2,indent:p.indent,firstLine:!1}).trim()+"`")}var b=h.headers&&h.headers.Accept&&"application/json"===(0,utils_1.normalizeMimeType)(h.headers.Accept)||"application/json"===(0,utils_1.normalizeMimeType)(null===(o=e.postData)||void 0===o?void 0:o.mimeType);e.basicAuth&&(h.headers=h.headers||{},h.headers.Authorization="'Basic ' + btoa('<username>:<password>')",u=!0),(0,code_helpers_1.printUrlVariablesDeclarations)(e,c);var f=(0,code_helpers_1.buildUrlExpression)(e,c);return c.push("const "+c.var("resp")+" = await fetch(").push(1,"`"+f+(m?"?${"+c.var("query")+"}":"")+"`,").push((0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(h,{indent:p.indent,inlineCharacterLimit:25,transform:(0,code_helpers_1.getPreserveTransformer)({body:!0,authorizationHeader:u})}),{level:1,indent:p.indent})).push(");").blank().push("const "+c.var("data")+" = await "+c.var("resp")+"."+(b?"json()":"text()")+";").push("console.log("+c.var("data")+");"),c.join()};function addComments(e){e.push("/**"),e.push(" * Requires ES8-compatible browser: https://caniuse.com/async-functions"),e.push(" */"),e.blank()}exports.info={key:"fetch",title:"fetch",link:"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch",description:"Perform asynchronous HTTP requests with the Fetch API"},exports.default=handler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),code_builder_1=require("../../helpers/code-builder"),stringify_object_1=(0,tslib_1.__importDefault)(require("stringify-object")),code_helpers_1=require("../../helpers/code-helpers"),utils_1=require("../../../../utils"),__1=require("../.."),constants_1=require("../../helpers/constants"),handler=function(e,t,a){var r,i,n,s,o,l=a.target,d=a.client,p=(0,tslib_1.__assign)({indent:" ",credentials:null},t),c=new code_builder_1.CodeBuilder({indentation:p.indent,variablesPrefix:p.variablesPrefix,capitalize:!0,lang:constants_1.Lang.JAVASCRIPT}),h={method:e.method.toUpperCase()};Object.keys(e.headersObj).length&&(h.headers=e.headersObj);var u=!1;if(p.withComments&&addComments(c),null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r.length){var _=new __1.HTTPSnippet(null===(i=e.securityOAuth2ExtraCalls)||void 0===i?void 0:i[0]).convert(l,d,(0,tslib_1.__assign)((0,tslib_1.__assign)({},p),{withImports:!1,withComments:!1,variablesPrefix:"oAuth2"}));c.push(_),c.blank(),h.headers=h.headers||{},h.headers.Authorization="'Bearer ' + oAuth2Data.access_token",u=!0}null!==p.credentials&&(h.credentials=p.credentials);var b=Object.getOwnPropertyNames(e.queryObj).length;if(b&&c.push("const "+c.var("query")+" = new URLSearchParams("+(0,stringify_object_1.default)(e.queryObj,{indent:p.indent,inlineCharacterLimit:25})+").toString();").blank(),e.postData)switch((0,utils_1.normalizeMimeType)(e.postData.mimeType)){case"application/x-www-form-urlencoded":h.body=e.postData.paramsObj?"new URLSearchParams("+c.var("formData")+").toString()":e.postData.text,e.postData.paramsObj&&c.push("const "+c.var("formData")+" = "+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(e.postData.paramsObj,{indent:p.indent,inlineCharacterLimit:25}),{level:0,firstLine:!1})+";").blank();break;case"application/json":e.postData.jsonObj&&(h.body="JSON.stringify("+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(e.postData.jsonObj,{indent:p.indent,inlineCharacterLimit:25}),{level:1,firstLine:!1})+")");break;case"multipart/form-data":c.push("const "+c.var("form")+" = new FormData();"),(null===(n=null==h?void 0:h.headers)||void 0===n?void 0:n["Content-Type"])&&(null===(s=h.headers)||void 0===s||delete s["Content-Type"]),e.postData.params.forEach((function(e){c.push(c.var("form")+".append(%s, %s);",JSON.stringify(e.name),JSON.stringify(e.value||e.fileName||""))})),h.body=c.var("form"),c.blank();break;default:e.postData.text&&(h.body="`"+(0,code_helpers_1.addIndentation)(e.postData.text,{level:2,indent:p.indent,firstLine:!1}).trim()+"`")}var m=h.headers&&h.headers.Accept&&"application/json"===(0,utils_1.normalizeMimeType)(h.headers.Accept)||"application/json"===(0,utils_1.normalizeMimeType)(null===(o=e.postData)||void 0===o?void 0:o.mimeType);if(e.basicAuth){var f=e.basicAuth,v=f.username,y=f.password;h.headers=h.headers||{},h.headers.Authorization="'Basic ' + btoa('"+v+":"+y+"')",u=!0}(0,code_helpers_1.printUrlVariablesDeclarations)(e,c);var g=(0,code_helpers_1.buildUrlExpression)(e,c);return c.push("const "+c.var("resp")+" = await fetch(").push(1,"`"+g+(b?"?${"+c.var("query")+"}":"")+"`,").push((0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(h,{indent:p.indent,inlineCharacterLimit:25,transform:(0,code_helpers_1.getPreserveTransformer)({body:!0,authorizationHeader:u})}),{level:1,indent:p.indent})).push(");").blank().push("const "+c.var("data")+" = await "+c.var("resp")+"."+(m?"json()":"text()")+";").push("console.log("+c.var("data")+");"),c.join()};function addComments(e){e.push("/**"),e.push(" * Requires ES8-compatible browser: https://caniuse.com/async-functions"),e.push(" */"),e.blank()}exports.info={key:"fetch",title:"fetch",link:"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch",description:"Perform asynchronous HTTP requests with the Fetch API"},exports.default=handler;
2
2
  //# sourceMappingURL=fetch.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),stringify_object_1=(0,tslib_1.__importDefault)(require("stringify-object")),code_builder_1=require("../../helpers/code-builder"),code_helpers_1=require("../../helpers/code-helpers"),constants_1=require("../../helpers/constants"),utils_1=require("../../../../utils"),__1=require("../.."),handler=function(e,t,a){var r,i,n,s,o,l=a.target,d=a.client,p=Object.assign({indent:" ",showBoilerplate:!0,level:1},t),h=p.level,c=!1,u=new code_builder_1.CodeBuilder({indentation:p.indent,variablesPrefix:p.variablesPrefix,capitalize:!0,lang:constants_1.Lang.NODEJS});p.withComments&&addComments(u),p.withImports&&(u.push("import fetch from 'node-fetch';"),u.blank()),p.showBoilerplate&&u.push("async function run() {");var m={method:e.method.toUpperCase()};Object.keys(e.headersObj).length&&(m.headers=e.headersObj);var f=!1;if(null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r.length){var _=new __1.HTTPSnippet(null===(i=e.securityOAuth2ExtraCalls)||void 0===i?void 0:i[0]).convert(l,d,(0,tslib_1.__assign)((0,tslib_1.__assign)({},p),{withImports:!1,withComments:!1,variablesPrefix:"oAuth2",showBoilerplate:!1,level:1}));u.push(_),u.blank(),m.headers=m.headers||{},m.headers.Authorization="'Bearer ' + oAuth2Data.access_token",f=!0}var b=Object.getOwnPropertyNames(e.queryObj).length;if(b&&u.push(h,"const "+u.var("query")+" = new URLSearchParams("+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(e.queryObj,{indent:p.indent,inlineCharacterLimit:25}),{level:h,indent:p.indent,firstLine:!1})+").toString();").blank(),e.postData)switch((0,utils_1.normalizeMimeType)(e.postData.mimeType)){case"application/x-www-form-urlencoded":m.body=e.postData.paramsObj?"new URLSearchParams("+u.var("formData")+").toString()":e.postData.text,e.postData.paramsObj&&u.push(h,"const "+u.var("formData")+" = "+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(e.postData.paramsObj,{indent:p.indent,inlineCharacterLimit:25}),{level:h,firstLine:!1})+";").blank();break;case"application/json":e.postData.jsonObj&&(m.body="JSON.stringify("+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(e.postData.jsonObj,{indent:p.indent,inlineCharacterLimit:25}),{level:h,firstLine:!1})+")");break;case"multipart/form-data":(null===(n=null==m?void 0:m.headers)||void 0===n?void 0:n["Content-Type"])&&(null===(s=m.headers)||void 0===s||delete s["Content-Type"]),p.withImports&&u.unshift("import FormData from 'form-data';"),u.push(h,"const "+u.var("form")+" = new FormData();"),e.postData.params.forEach((function(e){e.fileName||e.fileName||e.contentType?e.fileName&&(c=!0,u.blank(),u.push(h,u.var("form")+".append('\" + param.name + \"', fs.createReadStream('\" + param.fileName + \"'));")):u.push(h,"form.append('"+e.name+"','"+e.value+"');")})),m.body=u.var("form"),u.blank();break;default:e.postData.text&&(m.body="`"+(0,code_helpers_1.addIndentation)(e.postData.text,{level:h+1,indent:p.indent,firstLine:!1}).trim()+"`")}if(e.cookies.length){var v="";e.cookies.forEach((function(e){v=v+encodeURIComponent(e.name)+"="+encodeURIComponent(e.value)+"; "})),v=v.trim(),m.headers||(m.headers={}),m.headers.cookie=v}e.basicAuth&&(m.headers=m.headers||{},m.headers.Authorization="'Basic ' + Buffer.from('<username>:<password>').toString('base64')",f=!0),c&&p.withImports&&u.unshift("import fs from 'fs';");var y=m.headers&&m.headers.Accept&&"application/json"===(0,utils_1.normalizeMimeType)(m.headers.Accept)||"application/json"===(0,utils_1.normalizeMimeType)(null===(o=e.postData)||void 0===o?void 0:o.mimeType);(0,code_helpers_1.printUrlVariablesDeclarations)(e,u,h);var j=(0,code_helpers_1.buildUrlExpression)(e,u);return u.push(h,"const "+u.var("resp")+" = await fetch(").push(h+1,"`"+j+(b?"?${"+u.var("query")+"}":"")+"`,").push(h+1,(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(m,{indent:p.indent,inlineCharacterLimit:25,transform:(0,code_helpers_1.getPreserveTransformer)({body:!0,authorizationHeader:f})}),{level:h+1,indent:p.indent,firstLine:!1})).push(h,");").blank().push(h,"const "+u.var("data")+" = await "+u.var("resp")+"."+(y?"json()":"text()")+";").push(h,"console.log("+u.var("data")+");"),p.showBoilerplate&&u.push("}").blank().push("run();"),u.join().replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/,'fs.createReadStream("$1")')};function addComments(e){e.push("/**"),e.push(" * Requires Node.js >= 14"),e.push(" *"),e.push(' * Requires module "node-fetch" >= 2.6.1'),e.push(" * See here for installation details:"),e.push(" * https://www.npmjs.com/package/node-fetch"),e.push(" */"),e.blank()}exports.info={key:"fetch",title:"Fetch",link:"https://github.com/bitinn/node-fetch",description:"Simplified HTTP node-fetch client"},exports.default=handler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),stringify_object_1=(0,tslib_1.__importDefault)(require("stringify-object")),code_builder_1=require("../../helpers/code-builder"),code_helpers_1=require("../../helpers/code-helpers"),constants_1=require("../../helpers/constants"),utils_1=require("../../../../utils"),__1=require("../.."),handler=function(e,t,a){var r,i,n,s,o,l=a.target,d=a.client,p=Object.assign({indent:" ",showBoilerplate:!0,level:1},t),h=p.level,c=!1,u=new code_builder_1.CodeBuilder({indentation:p.indent,variablesPrefix:p.variablesPrefix,capitalize:!0,lang:constants_1.Lang.NODEJS});p.withComments&&addComments(u),p.withImports&&(u.push("import fetch from 'node-fetch';"),u.blank()),p.showBoilerplate&&u.push("async function run() {");var m={method:e.method.toUpperCase()};Object.keys(e.headersObj).length&&(m.headers=e.headersObj);var f=!1;if(null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r.length){var _=new __1.HTTPSnippet(null===(i=e.securityOAuth2ExtraCalls)||void 0===i?void 0:i[0]).convert(l,d,(0,tslib_1.__assign)((0,tslib_1.__assign)({},p),{withImports:!1,withComments:!1,variablesPrefix:"oAuth2",showBoilerplate:!1,level:1}));u.push(_),u.blank(),m.headers=m.headers||{},m.headers.Authorization="'Bearer ' + oAuth2Data.access_token",f=!0}var b=Object.getOwnPropertyNames(e.queryObj).length;if(b&&u.push(h,"const "+u.var("query")+" = new URLSearchParams("+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(e.queryObj,{indent:p.indent,inlineCharacterLimit:25}),{level:h,indent:p.indent,firstLine:!1})+").toString();").blank(),e.postData)switch((0,utils_1.normalizeMimeType)(e.postData.mimeType)){case"application/x-www-form-urlencoded":m.body=e.postData.paramsObj?"new URLSearchParams("+u.var("formData")+").toString()":e.postData.text,e.postData.paramsObj&&u.push(h,"const "+u.var("formData")+" = "+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(e.postData.paramsObj,{indent:p.indent,inlineCharacterLimit:25}),{level:h,firstLine:!1})+";").blank();break;case"application/json":e.postData.jsonObj&&(m.body="JSON.stringify("+(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(e.postData.jsonObj,{indent:p.indent,inlineCharacterLimit:25}),{level:h,firstLine:!1})+")");break;case"multipart/form-data":(null===(n=null==m?void 0:m.headers)||void 0===n?void 0:n["Content-Type"])&&(null===(s=m.headers)||void 0===s||delete s["Content-Type"]),p.withImports&&u.unshift("import FormData from 'form-data';"),u.push(h,"const "+u.var("form")+" = new FormData();"),e.postData.params.forEach((function(e){e.fileName||e.fileName||e.contentType?e.fileName&&(c=!0,u.blank(),u.push(h,u.var("form")+".append('\" + param.name + \"', fs.createReadStream('\" + param.fileName + \"'));")):u.push(h,"form.append('"+e.name+"','"+e.value+"');")})),m.body=u.var("form"),u.blank();break;default:e.postData.text&&(m.body="`"+(0,code_helpers_1.addIndentation)(e.postData.text,{level:h+1,indent:p.indent,firstLine:!1}).trim()+"`")}if(e.cookies.length){var v="";e.cookies.forEach((function(e){v=v+encodeURIComponent(e.name)+"="+encodeURIComponent(e.value)+"; "})),v=v.trim(),m.headers||(m.headers={}),m.headers.cookie=v}if(e.basicAuth){var y=e.basicAuth,j=y.username,w=y.password;m.headers=m.headers||{},m.headers.Authorization="'Basic ' + Buffer.from('"+j+":"+w+"').toString('base64')",f=!0}c&&p.withImports&&u.unshift("import fs from 'fs';");var g=m.headers&&m.headers.Accept&&"application/json"===(0,utils_1.normalizeMimeType)(m.headers.Accept)||"application/json"===(0,utils_1.normalizeMimeType)(null===(o=e.postData)||void 0===o?void 0:o.mimeType);(0,code_helpers_1.printUrlVariablesDeclarations)(e,u,h);var k=(0,code_helpers_1.buildUrlExpression)(e,u);return u.push(h,"const "+u.var("resp")+" = await fetch(").push(h+1,"`"+k+(b?"?${"+u.var("query")+"}":"")+"`,").push(h+1,(0,code_helpers_1.addIndentation)((0,stringify_object_1.default)(m,{indent:p.indent,inlineCharacterLimit:25,transform:(0,code_helpers_1.getPreserveTransformer)({body:!0,authorizationHeader:f})}),{level:h+1,indent:p.indent,firstLine:!1})).push(h,");").blank().push(h,"const "+u.var("data")+" = await "+u.var("resp")+"."+(g?"json()":"text()")+";").push(h,"console.log("+u.var("data")+");"),p.showBoilerplate&&u.push("}").blank().push("run();"),u.join().replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/,'fs.createReadStream("$1")')};function addComments(e){e.push("/**"),e.push(" * Requires Node.js >= 14"),e.push(" *"),e.push(' * Requires module "node-fetch" >= 2.6.1'),e.push(" * See here for installation details:"),e.push(" * https://www.npmjs.com/package/node-fetch"),e.push(" */"),e.blank()}exports.info={key:"fetch",title:"Fetch",link:"https://github.com/bitinn/node-fetch",description:"Simplified HTTP node-fetch client"},exports.default=handler;
2
2
  //# sourceMappingURL=fetch.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),util_1=require("util"),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),constants_1=require("../../helpers/constants"),code_helpers_1=require("../../helpers/code-helpers"),lodash_int_1=require("../../helpers/lodash-int"),utils_1=require("../../../../utils"),utils_2=require("./utils");function getVariableName(e,a){return a?"$"+a+(0,lodash_int_1.startCase)(e):"$"+e}var handler=function(e,a,r){var t,n,s=r.target,i=r.client,l=(0,tslib_1.__assign)({showBoilerplate:!0,checkErrors:!1,printBody:!0,indent:" ",noTags:!0,shortTags:!1,maxRedirects:10,namedErrors:!1,closingTag:!1},a),o=!1,u=new code_builder_1.CodeBuilder({indentation:l.indent,capitalize:!0,lang:constants_1.Lang.PHP}),p=null===(t=e.securityOAuth2ExtraCalls)||void 0===t?void 0:t[0],c=getVariableName("curl",l.variablesPrefix),h=getVariableName("response",l.variablesPrefix),d=getVariableName("error",l.variablesPrefix);if(l.noTags||u.push(l.shortTags?"<?":"<?php").blank(),p){var _="oAuth2",b=new __1.HTTPSnippet(p).convert(s,i,(0,tslib_1.__assign)((0,tslib_1.__assign)({},l),{showBoilerplate:!1,variablesPrefix:_}));u.push(b),u.blank(),e.allHeaders.Authorization='Bearer " . '+getVariableName("response",_)+".access_token"}var m=Object.keys(e.headersObj).sort().map((function(a){return"Authorization"===a&&p?(0,util_1.format)('"%s: %s',a,e.allHeaders.Authorization):(0,util_1.format)('"%s: %s"',a,e.headersObj[a])}));l.showBoilerplate&&u.push("/**").push(" * Requires libcurl").push(" */").blank(),(0,code_helpers_1.printUrlVariablesDeclarations)(e,u);var v="";if(Object.keys(e.queryObj||{}).length){var f=(0,utils_2.objectToPhpArray)(e.queryObj,{indent:l.indent});v="$query",u.push(v+" = "+f+";").blank()}if(u.push(c+" = curl_init();"),u.blank(),e.postData)switch((0,utils_1.normalizeMimeType)(e.postData.mimeType)){case"application/json":var T=(0,utils_2.objectToPhpArray)(e.postData.jsonObj,{indent:l.indent});o=!0,n="json_encode($payload)",u.push("$payload = "+T+";").blank();break;case"multipart/form-data":var g=e.postData.params.map((function(e){var a=e.name,r=e.value;return l.indent+'"'+a+'" => "'+r+'",\n'})).join("");o=!0,n="$payload",u.push("$payload = array(\n"+g+");").blank();break;case"application/x-www-form-urlencoded":var P=e.postData.params.map((function(e){return e.name+"="+e.value})).join("&");o=!0,n="$payload",u.push('$payload = "'+P+'";').blank();break;default:n=e.postData.text}var y=(0,code_helpers_1.buildUrlExpression)(e,u);v&&(y.endsWith('"')?y=y.slice(0,-1)+'?" . http_build_query('+v+")":y+=' . "?" . http_build_query('+v+")");var k=[{escape:!o,name:"CURLOPT_POSTFIELDS",value:n},{escape:!0,name:"CURLOPT_PORT",value:e.uriObj.port},{escape:!1,name:"CURLOPT_URL",value:y},{escape:!1,name:"CURLOPT_RETURNTRANSFER",value:"true"},{escape:!0,name:"CURLOPT_CUSTOMREQUEST",value:e.method.toUpperCase()}];u.push("curl_setopt_array("+c+", [");var O=new code_builder_1.CodeBuilder({indentation:l.indent,lineJoin:"\n"+l.indent,variablesPrefix:l.variablesPrefix,capitalize:!0,lang:constants_1.Lang.PHP});m.length&&O.push("CURLOPT_HTTPHEADER => [").push(1,m.join(",\n"+l.indent+l.indent)).push("],"),k.forEach((function(e){[null,void 0].includes(e.value)||O.push((0,util_1.format)("%s => %s,",e.name,e.escape?JSON.stringify(e.value):e.value))}));var R=e.cookies.map((function(e){return encodeURIComponent(e.name)+"="+encodeURIComponent(e.value)}));return R.length&&O.push((0,util_1.format)('CURLOPT_COOKIE => "%s",',R.join("; "))),u.push(1,O.join()).push("]);").blank().push(h+" = curl_exec("+c+");").push(d+" = curl_error("+c+");").blank().push("curl_close("+c+");").blank().push("if ("+d+") {"),l.namedErrors?u.push(1,'echo array_flip(get_defined_constants(true)["curl"])['+d+"];"):u.push(1,'echo "cURL Error #:" . '+d+";"),u.push("} else {").push(1,"echo "+h+";").push("}"),!l.noTags&&l.closingTag&&u.blank().push("?>"),u.join()};exports.info={key:"curl",title:"cURL",link:"http://php.net/manual/en/book.curl.php",description:"PHP with ext-curl"},exports.default=handler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),util_1=require("util"),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),constants_1=require("../../helpers/constants"),code_helpers_1=require("../../helpers/code-helpers"),lodash_int_1=require("../../helpers/lodash-int"),utils_1=require("../../../../utils"),utils_2=require("./utils");function getVariableName(e,a){return a?"$"+a+(0,lodash_int_1.startCase)(e):"$"+e}var handler=function(e,a,r){var s,t,n=r.target,i=r.client,l=(0,tslib_1.__assign)({showBoilerplate:!0,checkErrors:!1,printBody:!0,indent:" ",noTags:!0,shortTags:!1,maxRedirects:10,namedErrors:!1,closingTag:!1},a),o=!1,u=new code_builder_1.CodeBuilder({indentation:l.indent,capitalize:!0,lang:constants_1.Lang.PHP}),p=null===(s=e.securityOAuth2ExtraCalls)||void 0===s?void 0:s[0],c=getVariableName("curl",l.variablesPrefix),h=getVariableName("response",l.variablesPrefix),d=getVariableName("error",l.variablesPrefix);if(l.noTags||u.push(l.shortTags?"<?":"<?php").blank(),p){var _="oAuth2",b=new __1.HTTPSnippet(p).convert(n,i,(0,tslib_1.__assign)((0,tslib_1.__assign)({},l),{showBoilerplate:!1,variablesPrefix:_}));u.push(b),u.blank(),e.allHeaders.Authorization='Bearer " . '+getVariableName("response",_)+".access_token"}var m=Object.keys(e.headersObj).sort().map((function(a){return"Authorization"===a&&p?(0,util_1.format)('"%s: %s',a,e.allHeaders.Authorization):(0,util_1.format)('"%s: %s"',a,e.headersObj[a])}));if(e.basicAuth){var v=e.basicAuth,f=v.username,T=v.password;m.push('"Authorization: Basic " . base64_encode("'+f+":"+T+'")')}l.showBoilerplate&&u.push("/**").push(" * Requires libcurl").push(" */").blank(),(0,code_helpers_1.printUrlVariablesDeclarations)(e,u);var g="";if(Object.keys(e.queryObj||{}).length){var P=(0,utils_2.objectToPhpArray)(e.queryObj,{indent:l.indent});g="$query",u.push(g+" = "+P+";").blank()}if(u.push(c+" = curl_init();"),u.blank(),e.postData)switch((0,utils_1.normalizeMimeType)(e.postData.mimeType)){case"application/json":var y=(0,utils_2.objectToPhpArray)(e.postData.jsonObj,{indent:l.indent});o=!0,t="json_encode($payload)",u.push("$payload = "+y+";").blank();break;case"multipart/form-data":var k=e.postData.params.map((function(e){var a=e.name,r=e.value;return l.indent+'"'+a+'" => "'+r+'",\n'})).join("");o=!0,t="$payload",u.push("$payload = array(\n"+k+");").blank();break;case"application/x-www-form-urlencoded":var O=e.postData.params.map((function(e){return e.name+"="+e.value})).join("&");o=!0,t="$payload",u.push('$payload = "'+O+'";').blank();break;default:t=e.postData.text}var R=(0,code_helpers_1.buildUrlExpression)(e,u);g&&(R.endsWith('"')?R=R.slice(0,-1)+'?" . http_build_query('+g+")":R+=' . "?" . http_build_query('+g+")");var j=[{escape:!o,name:"CURLOPT_POSTFIELDS",value:t},{escape:!0,name:"CURLOPT_PORT",value:e.uriObj.port},{escape:!1,name:"CURLOPT_URL",value:R},{escape:!1,name:"CURLOPT_RETURNTRANSFER",value:"true"},{escape:!0,name:"CURLOPT_CUSTOMREQUEST",value:e.method.toUpperCase()}];u.push("curl_setopt_array("+c+", [");var U=new code_builder_1.CodeBuilder({indentation:l.indent,lineJoin:"\n"+l.indent,variablesPrefix:l.variablesPrefix,capitalize:!0,lang:constants_1.Lang.PHP});m.length&&U.push("CURLOPT_HTTPHEADER => [").push(1,m.join(",\n"+l.indent+l.indent)).push("],"),j.forEach((function(e){[null,void 0].includes(e.value)||U.push((0,util_1.format)("%s => %s,",e.name,e.escape?JSON.stringify(e.value):e.value))}));var x=e.cookies.map((function(e){return encodeURIComponent(e.name)+"="+encodeURIComponent(e.value)}));return x.length&&U.push((0,util_1.format)('CURLOPT_COOKIE => "%s",',x.join("; "))),u.push(1,U.join()).push("]);").blank().push(h+" = curl_exec("+c+");").push(d+" = curl_error("+c+");").blank().push("curl_close("+c+");").blank().push("if ("+d+") {"),l.namedErrors?u.push(1,'echo array_flip(get_defined_constants(true)["curl"])['+d+"];"):u.push(1,'echo "cURL Error #:" . '+d+";"),u.push("} else {").push(1,"echo "+h+";").push("}"),!l.noTags&&l.closingTag&&u.blank().push("?>"),u.join()};exports.info={key:"curl",title:"cURL",link:"http://php.net/manual/en/book.curl.php",description:"PHP with ext-curl"},exports.default=handler;
2
2
  //# sourceMappingURL=curl.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib"),util_1=require("util"),code_builder_1=require("../../helpers/code-builder"),utils_1=require("../../../../utils"),code_helpers_1=require("../../helpers/code-helpers"),__1=require("../.."),constants_1=require("../../helpers/constants"),handler=function(e,t,a){var s,r,o,n=a.target,i=a.client,l=Object.assign({indent:" "},t),u=new code_builder_1.CodeBuilder({indentation:l.indent,variablesPrefix:l.variablesPrefix,lang:constants_1.Lang.PYTHON});l.withComments&&addComments(u),l.withImports&&u.push("import requests").blank();var p,d,h=!1,_=e.allHeaders;if(null===(s=e.securityOAuth2ExtraCalls)||void 0===s?void 0:s.length){var c=new __1.HTTPSnippet(null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0]).convert(n,i,(0,tslib_1.__assign)((0,tslib_1.__assign)({},l),{withImports:!1,withComments:!1,variablesPrefix:"oauth2_"}));u.push(c),u.blank(),(_=_||{}).Authorization='"Bearer " + oauth2_data["access_token"]',h=!0}((0,code_helpers_1.printUrlVariablesDeclarations)(e,u),u.push(u.var("url").toLowerCase()+" = %s",(0,code_helpers_1.buildUrlExpression)(e,u)).blank(),Object.keys(e.queryObj||{}).length)&&(p="query = "+jsObjectToPythonDict(e.queryObj,l.indent),u.push(p).blank());var b,v=(0,utils_1.normalizeMimeType)(null===(o=e.postData)||void 0===o?void 0:o.mimeType);if(e.postData)switch(v){case"application/x-www-form-urlencoded":d=e.postData.paramsObj?""+(0,code_helpers_1.addIndentation)(jsObjectToPythonDict(e.postData.paramsObj,l.indent),{level:0,firstLine:!1}):e.postData.text;break;case"application/json":e.postData.jsonObj&&(d=(0,code_helpers_1.addIndentation)(jsObjectToPythonDict(e.postData.jsonObj,l.indent),{level:0,firstLine:!1}));break;case"multipart/form-data":u.unshift("# multipart/form-data is not supported yet\n");break;default:e.postData.text&&(console.log(e.postData.text),d="'''\n"+(0,code_helpers_1.addIndentation)(e.postData.text.trim(),{level:1,indent:l.indent,firstLine:!0})+"\n'''")}d&&u.push(u.var("payload").toLowerCase()+" = %s",d).blank();var f=Object.keys(_).length,m=function(e,t){return"Authorization"===e&&h?t:'"'+t+'"'};if(1===f)for(b in _)u.push(u.var("headers").toLowerCase()+' = {"'+b+'": '+m(b,_[b])+"}").blank();else if(f>1){var j=1;for(b in u.push(u.var("headers").toLowerCase()+" = {"),_)j++!==f?u.push(1,'"'+b+'": '+m(b,_[b])+","):u.push(1,'"'+b+'": '+m(b,_[b]));u.push(0,"}").blank()}var w=e.method.toLowerCase(),C=(0,util_1.format)(u.var("response").toLowerCase()+" = requests."+w+"("+u.var("url").toLowerCase());d&&(C+=", "+("application/json"===v?"json":"data")+"="+u.var("payload").toLowerCase());return f>0&&(C+=", headers="+u.var("headers").toLowerCase()),p&&(C+=", params="+u.var("query").toLowerCase()),e.basicAuth&&(C+=", auth=('<username>','<password>')"),C+=")",u.push(C).blank().push(u.var("data").toLowerCase()+" = "+u.var("response").toLowerCase()+".json()").push("print("+u.var("data").toLowerCase()+")"),u.join()};function addComments(e){e.push('"""'),e.push("Requires python >= 3"),e.blank(),e.push('Requires module "requests" >= 2.25.1'),e.push("See here for installation details:"),e.push(" https://requests.readthedocs.io/"),e.push('"""'),e.blank()}function jsObjectToPythonDict(e,t){return JSON.stringify(e,(function(e,t){return e&&"boolean"==typeof t?t?"__REDOCLY_<True>__":"__REDOCLY_<False>__":null===t?"__REDOCLY_<None>__":t}),t).replace(/"__REDOCLY_<(\w+)>__"/g,"$1")}exports.default=handler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var tslib_1=require("tslib"),util_1=require("util"),code_builder_1=require("../../helpers/code-builder"),utils_1=require("../../../../utils"),code_helpers_1=require("../../helpers/code-helpers"),__1=require("../.."),constants_1=require("../../helpers/constants"),handler=function(e,t,a){var s,r,o,n=a.target,i=a.client,l=Object.assign({indent:" "},t),u=new code_builder_1.CodeBuilder({indentation:l.indent,variablesPrefix:l.variablesPrefix,lang:constants_1.Lang.PYTHON});l.withComments&&addComments(u),l.withImports&&u.push("import requests").blank();var p,d,h=!1,_=e.allHeaders;if(null===(s=e.securityOAuth2ExtraCalls)||void 0===s?void 0:s.length){var c=new __1.HTTPSnippet(null===(r=e.securityOAuth2ExtraCalls)||void 0===r?void 0:r[0]).convert(n,i,(0,tslib_1.__assign)((0,tslib_1.__assign)({},l),{withImports:!1,withComments:!1,variablesPrefix:"oauth2_"}));u.push(c),u.blank(),(_=_||{}).Authorization='"Bearer " + oauth2_data["access_token"]',h=!0}((0,code_helpers_1.printUrlVariablesDeclarations)(e,u),u.push(u.var("url").toLowerCase()+" = %s",(0,code_helpers_1.buildUrlExpression)(e,u)).blank(),Object.keys(e.queryObj||{}).length)&&(p="query = "+jsObjectToPythonDict(e.queryObj,l.indent),u.push(p).blank());var b,v=(0,utils_1.normalizeMimeType)(null===(o=e.postData)||void 0===o?void 0:o.mimeType);if(e.postData)switch(v){case"application/x-www-form-urlencoded":d=e.postData.paramsObj?""+(0,code_helpers_1.addIndentation)(jsObjectToPythonDict(e.postData.paramsObj,l.indent),{level:0,firstLine:!1}):e.postData.text;break;case"application/json":e.postData.jsonObj&&(d=(0,code_helpers_1.addIndentation)(jsObjectToPythonDict(e.postData.jsonObj,l.indent),{level:0,firstLine:!1}));break;case"multipart/form-data":u.unshift("# multipart/form-data is not supported yet\n");break;default:e.postData.text&&(console.log(e.postData.text),d="'''\n"+(0,code_helpers_1.addIndentation)(e.postData.text.trim(),{level:1,indent:l.indent,firstLine:!0})+"\n'''")}d&&u.push(u.var("payload").toLowerCase()+" = %s",d).blank();var f=Object.keys(_).length,m=function(e,t){return"Authorization"===e&&h?t:'"'+t+'"'};if(1===f)for(b in _)u.push(u.var("headers").toLowerCase()+' = {"'+b+'": '+m(b,_[b])+"}").blank();else if(f>1){var j=1;for(b in u.push(u.var("headers").toLowerCase()+" = {"),_)j++!==f?u.push(1,'"'+b+'": '+m(b,_[b])+","):u.push(1,'"'+b+'": '+m(b,_[b]));u.push(0,"}").blank()}var w=e.method.toLowerCase(),C=(0,util_1.format)(u.var("response").toLowerCase()+" = requests."+w+"("+u.var("url").toLowerCase());d&&(C+=", "+("application/json"===v?"json":"data")+"="+u.var("payload").toLowerCase());return f>0&&(C+=", headers="+u.var("headers").toLowerCase()),p&&(C+=", params="+u.var("query").toLowerCase()),e.basicAuth&&(C+=", auth=('"+e.basicAuth.username+"','"+e.basicAuth.password+"')"),C+=")",u.push(C).blank().push(u.var("data").toLowerCase()+" = "+u.var("response").toLowerCase()+".json()").push("print("+u.var("data").toLowerCase()+")"),u.join()};function addComments(e){e.push('"""'),e.push("Requires python >= 3"),e.blank(),e.push('Requires module "requests" >= 2.25.1'),e.push("See here for installation details:"),e.push(" https://requests.readthedocs.io/"),e.push('"""'),e.blank()}function jsObjectToPythonDict(e,t){return JSON.stringify(e,(function(e,t){return e&&"boolean"==typeof t?t?"__REDOCLY_<True>__":"__REDOCLY_<False>__":null===t?"__REDOCLY_<None>__":t}),t).replace(/"__REDOCLY_<(\w+)>__"/g,"$1")}exports.default=handler;
2
2
  //# sourceMappingURL=requests.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),stringify_object_1=(0,tslib_1.__importDefault)(require("stringify-object")),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),constants_1=require("../../helpers/constants"),code_helpers_1=require("../../helpers/code-helpers"),utils_1=require("../../../../utils"),indent=1,contentType={X_FORM_URLENCODED:"application/x-www-form-urlencoded",JSON:"application/json",FORM_DATA:"multipart/form-data"};function hasMimeType(e,t){return void 0===e&&(e={}),(0,utils_1.normalizeMimeType)(e.mimeType)===t}var handler=function(e,t,r){var a,s,i,n,o,l=r.target,u=r.client,p=e.method.toUpperCase(),d=null===(a=e.securityOAuth2ExtraCalls)||void 0===a?void 0:a[0],c=(0,tslib_1.__assign)({capitalize:!0,showBoilerplate:!0,indent:" "},t),h=new code_builder_1.CodeBuilder({indentation:c.indent,variablesPrefix:c.variablesPrefix,capitalize:c.capitalize,lang:constants_1.Lang.RUBY});c.showBoilerplate&&(h.push("require 'uri'").push("require 'net/http'"),"https:"===e.uriObj.protocol&&h.push("require 'openssl'"),(hasMimeType(e.postData,contentType.JSON)||d)&&h.unshift("require 'json'"),h.blank()),Object.keys(e.allHeaders).length&&Object.keys(e.allHeaders).forEach((function(t){e.allHeaders[t]="'"+e.allHeaders[t]+"'"}));var _=p.charAt(0)+p.substring(1).toLowerCase();if(["GET","POST","HEAD","DELETE","PATCH","PUT","OPTIONS","COPY","LOCK","UNLOCK","MOVE","TRACE"].indexOf(p)<0&&h.push("class Net::HTTP::%s < Net::HTTPRequest",_).push(" METHOD = '%s'",p.toUpperCase()).push(" REQUEST_HAS_BODY = '%s'",(null===(s=e.postData)||void 0===s?void 0:s.text)?"true":"false").push(" RESPONSE_HAS_BODY = true").push("end").blank(),d){var b="oAuth2",v=new __1.HTTPSnippet(d).convert(l,u,(0,tslib_1.__assign)((0,tslib_1.__assign)({},c),{variablesPrefix:b,showBoilerplate:!1})),f="oAuth2"+(c.capitalize?"Response":"response");h.push(v).push("access_token = JSON.parse("+f+".body)['access_token']").blank(),e.allHeaders.Authorization='"Bearer " + access_token'}if((0,code_helpers_1.printUrlVariablesDeclarations)(e,h),h.push(h.var("url")+" = URI("+(0,code_helpers_1.buildUrlExpression)(e,h)+")"),Object.getOwnPropertyNames(e.queryObj).length&&(h.push(h.var("params")+" = "+(0,stringify_object_1.default)(e.queryObj,{indent:c.indent,inlineCharacterLimit:25})),h.push(h.var("url")+".query = URI.encode_www_form("+h.var("params")+")")),h.blank().push(h.var("http")+" = Net::HTTP.new("+h.var("url")+".host, "+h.var("url")+".port)"),"https:"===e.uriObj.protocol&&h.push(h.var("http")+".use_ssl = true"),h.blank().push(h.var("request")+" = Net::HTTP::%s.new("+h.var("url")+")",_),Object.keys(e.allHeaders).length&&Object.keys(e.allHeaders).forEach((function(t){e.allHeaders[t]!=="'"+contentType.FORM_DATA+"'"&&h.push(h.var("request")+"['%s'] = %s",t,e.allHeaders[t])})),null==e?void 0:e.postData){var T={};switch((0,utils_1.normalizeMimeType)(null===(i=null==e?void 0:e.postData)||void 0===i?void 0:i.mimeType)){case contentType.X_FORM_URLENCODED:e.postData.params.forEach((function(e){T[e.name]=e.value})),h.push(h.var("request")+".body = URI.encode_www_form("+(0,stringify_object_1.default)(T,{indent:c.indent,inlineCharacterLimit:25})+")");break;case contentType.JSON:h.push(h.var("request")+".body = "+(0,stringify_object_1.default)(e.postData.jsonObj,{indent:c.indent,inlineCharacterLimit:25}).replace(/null/g,"nil")+".to_json");break;case contentType.FORM_DATA:e.postData.params&&(h.push(h.var("form_data")+" = ["),e.postData.params.forEach((function(e){h.push(indent,"['"+e.name+"', '"+e.value+"'],")})),h.push("]")),h.push(h.var("request")+".set_form("+h.var("form_data")+", '"+contentType.FORM_DATA+"')");break;default:(null===(n=e.postData)||void 0===n?void 0:n.text)&&h.push(h.var("request")+".body = "+JSON.stringify(null===(o=e.postData)||void 0===o?void 0:o.text))}}return e.basicAuth&&h.push(h.var("request")+".basic_auth('<username>', '<password>')"),h.blank().push(h.var("response")+" = "+h.var("http")+".request("+h.var("request")+")").push("puts "+h.var("response")+".read_body").blank(),h.join()};exports.info={key:"native",title:"net::http",link:"http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html",description:"Ruby HTTP client"},exports.default=handler;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.info=void 0;var tslib_1=require("tslib"),stringify_object_1=(0,tslib_1.__importDefault)(require("stringify-object")),code_builder_1=require("../../helpers/code-builder"),__1=require("../.."),constants_1=require("../../helpers/constants"),code_helpers_1=require("../../helpers/code-helpers"),utils_1=require("../../../../utils"),indent=1,contentType={X_FORM_URLENCODED:"application/x-www-form-urlencoded",JSON:"application/json",FORM_DATA:"multipart/form-data"};function hasMimeType(e,t){return void 0===e&&(e={}),(0,utils_1.normalizeMimeType)(e.mimeType)===t}var handler=function(e,t,r){var a,s,i,n,o,l=r.target,u=r.client,p=e.method.toUpperCase(),c=null===(a=e.securityOAuth2ExtraCalls)||void 0===a?void 0:a[0],d=(0,tslib_1.__assign)({capitalize:!0,showBoilerplate:!0,indent:" "},t),h=new code_builder_1.CodeBuilder({indentation:d.indent,variablesPrefix:d.variablesPrefix,capitalize:d.capitalize,lang:constants_1.Lang.RUBY});d.showBoilerplate&&(h.push("require 'uri'").push("require 'net/http'"),"https:"===e.uriObj.protocol&&h.push("require 'openssl'"),(hasMimeType(e.postData,contentType.JSON)||c)&&h.unshift("require 'json'"),h.blank()),Object.keys(e.allHeaders).length&&Object.keys(e.allHeaders).forEach((function(t){e.allHeaders[t]="'"+e.allHeaders[t]+"'"}));var _=p.charAt(0)+p.substring(1).toLowerCase();if(["GET","POST","HEAD","DELETE","PATCH","PUT","OPTIONS","COPY","LOCK","UNLOCK","MOVE","TRACE"].indexOf(p)<0&&h.push("class Net::HTTP::%s < Net::HTTPRequest",_).push(" METHOD = '%s'",p.toUpperCase()).push(" REQUEST_HAS_BODY = '%s'",(null===(s=e.postData)||void 0===s?void 0:s.text)?"true":"false").push(" RESPONSE_HAS_BODY = true").push("end").blank(),c){var b="oAuth2",v=new __1.HTTPSnippet(c).convert(l,u,(0,tslib_1.__assign)((0,tslib_1.__assign)({},d),{variablesPrefix:b,showBoilerplate:!1})),f="oAuth2"+(d.capitalize?"Response":"response");h.push(v).push("access_token = JSON.parse("+f+".body)['access_token']").blank(),e.allHeaders.Authorization='"Bearer " + access_token'}if((0,code_helpers_1.printUrlVariablesDeclarations)(e,h),h.push(h.var("url")+" = URI("+(0,code_helpers_1.buildUrlExpression)(e,h)+")"),Object.getOwnPropertyNames(e.queryObj).length&&(h.push(h.var("params")+" = "+(0,stringify_object_1.default)(e.queryObj,{indent:d.indent,inlineCharacterLimit:25})),h.push(h.var("url")+".query = URI.encode_www_form("+h.var("params")+")")),h.blank().push(h.var("http")+" = Net::HTTP.new("+h.var("url")+".host, "+h.var("url")+".port)"),"https:"===e.uriObj.protocol&&h.push(h.var("http")+".use_ssl = true"),h.blank().push(h.var("request")+" = Net::HTTP::%s.new("+h.var("url")+")",_),Object.keys(e.allHeaders).length&&Object.keys(e.allHeaders).forEach((function(t){e.allHeaders[t]!=="'"+contentType.FORM_DATA+"'"&&h.push(h.var("request")+"['%s'] = %s",t,e.allHeaders[t])})),null==e?void 0:e.postData){var T={};switch((0,utils_1.normalizeMimeType)(null===(i=null==e?void 0:e.postData)||void 0===i?void 0:i.mimeType)){case contentType.X_FORM_URLENCODED:e.postData.params.forEach((function(e){T[e.name]=e.value})),h.push(h.var("request")+".body = URI.encode_www_form("+(0,stringify_object_1.default)(T,{indent:d.indent,inlineCharacterLimit:25})+")");break;case contentType.JSON:h.push(h.var("request")+".body = "+(0,stringify_object_1.default)(e.postData.jsonObj,{indent:d.indent,inlineCharacterLimit:25}).replace(/null/g,"nil")+".to_json");break;case contentType.FORM_DATA:e.postData.params&&(h.push(h.var("form_data")+" = ["),e.postData.params.forEach((function(e){h.push(indent,"['"+e.name+"', '"+e.value+"'],")})),h.push("]")),h.push(h.var("request")+".set_form("+h.var("form_data")+", '"+contentType.FORM_DATA+"')");break;default:(null===(n=e.postData)||void 0===n?void 0:n.text)&&h.push(h.var("request")+".body = "+JSON.stringify(null===(o=e.postData)||void 0===o?void 0:o.text))}}if(e.basicAuth){var O=e.basicAuth,y=O.username,m=O.password;h.push(h.var("request")+".basic_auth('"+y+"', '"+m+"')")}return h.blank().push(h.var("response")+" = "+h.var("http")+".request("+h.var("request")+")").push("puts "+h.var("response")+".read_body").blank(),h.join()};exports.info={key:"native",title:"net::http",link:"http://ruby-doc.org/stdlib-2.2.1/libdoc/net/http/rdoc/Net/HTTP.html",description:"Ruby HTTP client"},exports.default=handler;
2
2
  //# sourceMappingURL=native.js.map
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.extendTheme=void 0;var tslib_1=require("tslib"),redoc_lib_1=require("../redoc-lib"),deepmerge_1=(0,tslib_1.__importDefault)(require("deepmerge"));function extendTheme(e){var o,t,n,r,a,l,i,d,c,p,m,h;return e.theme?(e.theme=(0,deepmerge_1.default)(defaultProTheme,e.theme),e.theme.extensionsHook=extensionsHook,(null===(o=e.theme)||void 0===o?void 0:o.menu)&&!(null===(t=e.theme)||void 0===t?void 0:t.sidebar)&&(console.warn('Theme setting "menu" is deprecated. Rename to "sidebar"'),e.theme.sidebar=e.theme.menu),(null===(n=e.theme)||void 0===n?void 0:n.codeSample)&&(console.warn('Theme setting "codeSample" is deprecated. Rename to "codeBlock"'),Object.assign(null===(r=e.theme)||void 0===r?void 0:r.codeBlock,e.theme.codeSample)),(null===(i=null===(l=null===(a=e.theme)||void 0===a?void 0:a.typography)||void 0===l?void 0:l.code)||void 0===i?void 0:i.tokens)&&(console.warn('Theme setting "typography.code.tokens" is deprecated. Move to "codeBlock.tokens"'),e.theme.codeBlock=(null===(d=e.theme)||void 0===d?void 0:d.codeBlock)||{},Object.assign(null===(p=null===(c=e.theme)||void 0===c?void 0:c.codeBlock)||void 0===p?void 0:p.tokens,(null===(h=null===(m=e.theme)||void 0===m?void 0:m.typography)||void 0===h?void 0:h.code).tokens)),e):(e.theme=defaultProTheme,e)}exports.extendTheme=extendTheme;var defaultProTheme={overrides:{DownloadButton:{custom:""},NextSectionButton:{custom:""}},codeBlock:{borderRadius:function(e){return e.components.panels.borderRadius},tokens:{}},schema:{constraints:{},examples:{}},rightPanel:{textColor:"#eeeeee"},typography:{heading1:{},heading2:{},heading3:{},rightPanelHeading:{}}};function optional(e,o){return o?e+": "+o+";":""}function typography(e){return e?(0,redoc_lib_1.css)(templateObject_1||(templateObject_1=(0,tslib_1.__makeTemplateObject)(["\n ","\n "],["\n ","\n "])),(0,redoc_lib_1.mediaCSS)({fontSize:e.fontSize||"",fontWeight:e.fontWeight||"",fontFamily:e.fontFamily||"",lineHeight:e.lineHeight||"",color:e.color||"",textTransform:e.transform||""})):""}function genTokens(e){if(!e)return"";for(var o="",t=0,n=Object.keys(e);t<n.length;t++){var r=n[t];"default"!==r&&(o+=".token."+r+" { color: "+e[r].color+"; }\n")}return e.default?(0,redoc_lib_1.css)(templateObject_2||(templateObject_2=(0,tslib_1.__makeTemplateObject)(["\n pre& {\n ","\n }\n ","\n "],["\n pre& {\n ","\n }\n ","\n "])),typography(e.default),o):o}var templateObject_1,templateObject_2,templateObject_3,templateObject_4,templateObject_5,templateObject_6,EXTENSIONS={DownloadButton:function(e){var o=e.theme;return void 0!==o.overrides&&o.overrides.DownloadButton&&o.overrides.DownloadButton.custom||""},H1:function(e){return typography(e.theme.typography.heading1)},H2:function(e){return typography(e.theme.typography.heading2)},H3:function(e){return typography(e.theme.typography.heading3)},RightPanelHeader:function(e){return typography(e.theme.typography.rightPanelHeading)},PropertyNameCell:function(e){var o=e.theme;return o.schema.breakFieldNames?(0,redoc_lib_1.css)(templateObject_3||(templateObject_3=(0,tslib_1.__makeTemplateObject)(["\n ","\n ","\n "],["\n ","\n ","\n "])),typography(o.typography.fieldName),"\n && span:last-child {\n white-space: normal;\n word-break: break-word;\n vertical-align: top;\n max-width: calc(100% - 21px);\n display: inline-block;\n }\n "):typography(o.typography.fieldName)},Markdown:function(e){var o,t,n,r,a=e.theme;return(0,redoc_lib_1.css)(templateObject_4||(templateObject_4=(0,tslib_1.__makeTemplateObject)(["\n h1 {\n ","\n clear: both;\n }\n h2 {\n ","\n clear: both;\n }\n h3 {\n ","\n clear: both;\n }\n\n pre {\n border-radius: ",";\n }\n\n code {\n ","\n }\n "],["\n h1 {\n ","\n clear: both;\n }\n h2 {\n ","\n clear: both;\n }\n h3 {\n ","\n clear: both;\n }\n\n pre {\n border-radius: ",";\n }\n\n code {\n ","\n }\n "])),typography(a.typography.heading1),typography(a.typography.heading2),typography(a.typography.heading3),null!==(t=null===(o=a.codeBlock)||void 0===o?void 0:o.borderRadius)&&void 0!==t?t:0,optional("word-break",null===(r=null===(n=a.typography)||void 0===n?void 0:n.code)||void 0===r?void 0:r.wordBreak))},ConstraintItem:function(e){var o,t,n,r,a=e.theme;return(0,redoc_lib_1.css)(templateObject_5||(templateObject_5=(0,tslib_1.__makeTemplateObject)(["\n ",";\n ",";\n ","\n ","\n "],["\n ",";\n ",";\n ","\n ","\n "])),typography(a.schema.constraints),optional("background-color",null===(o=a.schema.constraints)||void 0===o?void 0:o.backgroundColor),optional("border",null===(t=a.schema.constraints)||void 0===t?void 0:t.border),optional("word-break",null===(r=null===(n=a.typography)||void 0===n?void 0:n.code)||void 0===r?void 0:r.wordBreak))},ExampleValue:function(e){var o,t,n,r,a=e.theme;return(0,redoc_lib_1.css)(templateObject_6||(templateObject_6=(0,tslib_1.__makeTemplateObject)(["\n ",";\n ",";\n ","\n ","\n "],["\n ",";\n ",";\n ","\n ","\n "])),typography(a.schema.examples),optional("background-color",null===(o=a.schema.examples)||void 0===o?void 0:o.backgroundColor),optional("border",null===(t=a.schema.examples)||void 0===t?void 0:t.border),optional("word-break",null===(r=null===(n=a.typography)||void 0===n?void 0:n.code)||void 0===r?void 0:r.wordBreak))},Prism:function(e){var o,t,n,r=e.theme;return genTokens(null===(o=null==r?void 0:r.codeBlock)||void 0===o?void 0:o.tokens)+optional("word-break",null===(n=null===(t=r.typography)||void 0===t?void 0:t.code)||void 0===n?void 0:n.wordBreak)}};function extensionsHook(e,o){return EXTENSIONS[e]&&EXTENSIONS[e](o)}
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.extendTheme=void 0;var tslib_1=require("tslib"),redoc_lib_1=require("../redoc-lib"),deepmerge_1=(0,tslib_1.__importDefault)(require("deepmerge"));function extendTheme(e){var t,n,o,r,a,l,i,d,c,p,m,h;return e.theme?(e.theme=(0,deepmerge_1.default)(defaultProTheme,e.theme),e.theme.extensionsHook=extensionsHook,(null===(t=e.theme)||void 0===t?void 0:t.menu)&&!(null===(n=e.theme)||void 0===n?void 0:n.sidebar)&&(console.warn('Theme setting "menu" is deprecated. Rename to "sidebar"'),e.theme.sidebar=e.theme.menu),(null===(o=e.theme)||void 0===o?void 0:o.codeSample)&&(console.warn('Theme setting "codeSample" is deprecated. Rename to "codeBlock"'),Object.assign(null===(r=e.theme)||void 0===r?void 0:r.codeBlock,e.theme.codeSample)),(null===(i=null===(l=null===(a=e.theme)||void 0===a?void 0:a.typography)||void 0===l?void 0:l.code)||void 0===i?void 0:i.tokens)&&(console.warn('Theme setting "typography.code.tokens" is deprecated. Move to "codeBlock.tokens"'),e.theme.codeBlock=(null===(d=e.theme)||void 0===d?void 0:d.codeBlock)||{},Object.assign(null===(p=null===(c=e.theme)||void 0===c?void 0:c.codeBlock)||void 0===p?void 0:p.tokens,(null===(h=null===(m=e.theme)||void 0===m?void 0:m.typography)||void 0===h?void 0:h.code).tokens)),e):(e.theme=defaultProTheme,e)}exports.extendTheme=extendTheme;var defaultProTheme={overrides:{DownloadButton:{custom:""},NextSectionButton:{custom:""}},codeBlock:{borderRadius:function(e){return e.components.panels.borderRadius},tokens:{}},schema:{constraints:{},examples:{}},rightPanel:{textColor:"#eeeeee"},typography:{heading1:{},heading2:{},heading3:{},rightPanelHeading:{}}};function optional(e,t){return t?e+": "+t+";":""}function typography(e){return e?(0,redoc_lib_1.css)(templateObject_1||(templateObject_1=(0,tslib_1.__makeTemplateObject)(["\n ","\n "],["\n ","\n "])),(0,redoc_lib_1.mediaCSS)({fontSize:e.fontSize||"",fontWeight:e.fontWeight||"",fontFamily:e.fontFamily||"",lineHeight:e.lineHeight||"",color:e.color||"",textTransform:e.transform||""})):""}function genTokens(e){if(!e)return"";for(var t="",n=0,o=Object.keys(e);n<o.length;n++){var r=o[n];"default"!==r&&(t+=".token."+r+" { color: "+e[r].color+"; }\n")}return e.default?(0,redoc_lib_1.css)(templateObject_2||(templateObject_2=(0,tslib_1.__makeTemplateObject)(["\n pre& {\n ","\n }\n ","\n "],["\n pre& {\n ","\n }\n ","\n "])),typography(e.default),t):t}var templateObject_1,templateObject_2,templateObject_3,templateObject_4,templateObject_5,templateObject_6,templateObject_7,EXTENSIONS={DownloadButton:function(e){var t=e.theme;return void 0!==t.overrides&&t.overrides.DownloadButton&&t.overrides.DownloadButton.custom||""},H1:function(e){return typography(e.theme.typography.heading1)},H2:function(e){return typography(e.theme.typography.heading2)},H3:function(e){return typography(e.theme.typography.heading3)},RightPanelHeader:function(e){return typography(e.theme.typography.rightPanelHeading)},PropertyNameCell:function(e){var t=e.theme;return t.schema.breakFieldNames?(0,redoc_lib_1.css)(templateObject_3||(templateObject_3=(0,tslib_1.__makeTemplateObject)(["\n ","\n ","\n "],["\n ","\n ","\n "])),typography(t.typography.fieldName),"\n && span:last-child {\n white-space: normal;\n word-break: break-word;\n vertical-align: top;\n max-width: calc(100% - 21px);\n display: inline-flex;\n }\n "):typography(t.typography.fieldName)},ClickablePropertyNameCell:function(e){var t=e.theme;return t.schema.breakFieldNames?(0,redoc_lib_1.css)(templateObject_4||(templateObject_4=(0,tslib_1.__makeTemplateObject)(["\n ","\n ","\n "],["\n ","\n ","\n "])),typography(t.typography.fieldName),"\n && button {\n max-width: calc(100% - 21px); /* left padding + toggle button width: 16px/2 + 13px */\n text-align: left;\n span {\n white-space: normal;\n word-break: break-word;\n vertical-align: top;\n display: inline-flex;\n }\n }\n "):typography(t.typography.fieldName)},Markdown:function(e){var t,n,o,r,a=e.theme;return(0,redoc_lib_1.css)(templateObject_5||(templateObject_5=(0,tslib_1.__makeTemplateObject)(["\n h1 {\n ","\n clear: both;\n }\n h2 {\n ","\n clear: both;\n }\n h3 {\n ","\n clear: both;\n }\n\n pre {\n border-radius: ",";\n }\n\n code {\n ","\n }\n "],["\n h1 {\n ","\n clear: both;\n }\n h2 {\n ","\n clear: both;\n }\n h3 {\n ","\n clear: both;\n }\n\n pre {\n border-radius: ",";\n }\n\n code {\n ","\n }\n "])),typography(a.typography.heading1),typography(a.typography.heading2),typography(a.typography.heading3),null!==(n=null===(t=a.codeBlock)||void 0===t?void 0:t.borderRadius)&&void 0!==n?n:0,optional("word-break",null===(r=null===(o=a.typography)||void 0===o?void 0:o.code)||void 0===r?void 0:r.wordBreak))},ConstraintItem:function(e){var t,n,o,r,a=e.theme;return(0,redoc_lib_1.css)(templateObject_6||(templateObject_6=(0,tslib_1.__makeTemplateObject)(["\n ",";\n ",";\n ","\n ","\n "],["\n ",";\n ",";\n ","\n ","\n "])),typography(a.schema.constraints),optional("background-color",null===(t=a.schema.constraints)||void 0===t?void 0:t.backgroundColor),optional("border",null===(n=a.schema.constraints)||void 0===n?void 0:n.border),optional("word-break",null===(r=null===(o=a.typography)||void 0===o?void 0:o.code)||void 0===r?void 0:r.wordBreak))},ExampleValue:function(e){var t,n,o,r,a=e.theme;return(0,redoc_lib_1.css)(templateObject_7||(templateObject_7=(0,tslib_1.__makeTemplateObject)(["\n ",";\n ",";\n ","\n ","\n "],["\n ",";\n ",";\n ","\n ","\n "])),typography(a.schema.examples),optional("background-color",null===(t=a.schema.examples)||void 0===t?void 0:t.backgroundColor),optional("border",null===(n=a.schema.examples)||void 0===n?void 0:n.border),optional("word-break",null===(r=null===(o=a.typography)||void 0===o?void 0:o.code)||void 0===r?void 0:r.wordBreak))},Prism:function(e){var t,n,o,r=e.theme;return genTokens(null===(t=null==r?void 0:r.codeBlock)||void 0===t?void 0:t.tokens)+optional("word-break",null===(o=null===(n=r.typography)||void 0===n?void 0:n.code)||void 0===o?void 0:o.wordBreak)}};function extensionsHook(e,t){return EXTENSIONS[e]&&EXTENSIONS[e](t)}
2
2
  //# sourceMappingURL=extendTheme.js.map
@@ -1,2 +1,2 @@
1
- import{__makeTemplateObject}from"tslib";import styled from"../../redoc-lib/src/styled-components";export var Path=styled.span(templateObject_1||(templateObject_1=__makeTemplateObject(["\n margin: 0 4px;\n color: ",";\n overflow-x: hidden;\n text-overflow: ellipsis;\n white-space: ",";\n overflow-wrap: ",";\n display: inline-block;\n"],["\n margin: 0 4px;\n color: ",";\n overflow-x: hidden;\n text-overflow: ellipsis;\n white-space: ",";\n overflow-wrap: ",";\n display: inline-block;\n"])),(function(e){return e.theme.colors.text.light}),(function(e){return e.wrap?"normal":"nowrap"}),(function(e){return e.wrap?"anywhere":"normal"}));export var PathWrapper=styled.div(templateObject_2||(templateObject_2=__makeTemplateObject(["\n display: inline-flex;\n align-items: center;\n overflow-x: hidden;\n"],["\n display: inline-flex;\n align-items: center;\n overflow-x: hidden;\n"])));var templateObject_1,templateObject_2;
1
+ import{__makeTemplateObject}from"tslib";import styled from"../../redoc-lib/src/styled-components";export var Path=styled.span(templateObject_1||(templateObject_1=__makeTemplateObject(["\n margin: 0 4px;\n color: ",";\n overflow-x: hidden;\n text-overflow: ellipsis;\n white-space: ",";\n overflow-wrap: ",";\n display: inline-block;\n"],["\n margin: 0 4px;\n color: ",";\n overflow-x: hidden;\n text-overflow: ellipsis;\n white-space: ",";\n overflow-wrap: ",";\n display: inline-block;\n"])),(function(e){return e.theme.colors.text.light}),(function(e){return e.wrap?"normal":"nowrap"}),(function(e){return e.wrap?"anywhere":"normal"}));export var PathWrapper=styled.div(templateObject_2||(templateObject_2=__makeTemplateObject(["\n display: inline-flex;\n align-items: center;\n overflow-x: hidden;\n padding-right: 4px;\n"],["\n display: inline-flex;\n align-items: center;\n overflow-x: hidden;\n padding-right: 4px;\n"])));var templateObject_1,templateObject_2;
2
2
  //# sourceMappingURL=Path.js.map
@@ -1,2 +1,2 @@
1
- import React from"react";import{expandDefaultServerVariables,getBasePath}from"../../redoc-lib/src/utils";import{Markdown}from"../../redoc-lib/src/components/Markdown/Markdown";import{CopyButton,SelectOnClick}from"../shared";import{ServerItem}from"./ServerItem";import{ServerUrl}from"./ServerUrl";import{CopyLink}from"./CopyLink";export var ServerList=function(e){var r=e.operation,t=e.expandVariables,a=e.hideHostname;return React.createElement(React.Fragment,null,r.servers.map((function(e){var o=t?expandDefaultServerVariables(e.url,e.variables):e.url,n=getBasePath(o),l=(a?"/"===n?"":n:o)+r.path;return React.createElement(ServerItem,{key:o},React.createElement(Markdown,{source:e.description||"",compact:!0}),React.createElement(CopyLink,null,React.createElement(SelectOnClick,null,React.createElement(ServerUrl,null,l)),React.createElement(CopyButton,{text:l})))})))};
1
+ import React from"react";import{expandDefaultServerVariables,getBasePath}from"../../redoc-lib/src/utils";import{Markdown}from"../../redoc-lib/src/components/Markdown/Markdown";import{SelectOnClick}from"../shared";import{ServerItem}from"./ServerItem";import{ServerUrl}from"./ServerUrl";import{CopyLink}from"./CopyLink";export var ServerList=function(e){var r=e.operation,t=e.expandVariables,a=e.hideHostname;return React.createElement(React.Fragment,null,r.servers.map((function(e){var n=t?expandDefaultServerVariables(e.url,e.variables):e.url,o=getBasePath(n),l=(a?"/"===o?"":o:n)+r.path;return React.createElement(ServerItem,{key:n},React.createElement(Markdown,{source:e.description||"",compact:!0}),React.createElement(CopyLink,null,React.createElement(SelectOnClick,null,React.createElement(ServerUrl,null,l))))})))};
2
2
  //# sourceMappingURL=ServerList.js.map
@@ -1,2 +1,2 @@
1
- import{__makeTemplateObject}from"tslib";import styled from"../../redoc-lib/src/styled-components";import{invertedInputStyles}from"../console/styled.components";export var ServerUrl=styled.div(templateObject_1||(templateObject_1=__makeTemplateObject(["\n ",";\n border-top-left-radius: ",";\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n border-bottom-left-radius: ",";\n padding: 7px 12px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n"],["\n ",";\n border-top-left-radius: ",";\n border-top-right-radius: 0;\n border-bottom-right-radius: 0;\n border-bottom-left-radius: ",";\n padding: 7px 12px;\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n"])),invertedInputStyles,(function(e){return e.theme.shape.borderRadius}),(function(e){return e.theme.shape.borderRadius}));var templateObject_1;
1
+ import{__makeTemplateObject}from"tslib";import styled from"../../redoc-lib/src/styled-components";import{invertedInputStyles}from"../console/styled.components";export var ServerUrl=styled.div(templateObject_1||(templateObject_1=__makeTemplateObject(["\n ",";\n border-radius: ",";\n padding: 7px 12px;\n overflow-wrap: break-word;\n"],["\n ",";\n border-radius: ",";\n padding: 7px 12px;\n overflow-wrap: break-word;\n"])),invertedInputStyles,(function(e){return e.theme.shape.borderRadius}));var templateObject_1;
2
2
  //# sourceMappingURL=ServerUrl.js.map
@@ -1,2 +1,2 @@
1
- import{__assign,__awaiter,__decorate,__extends,__generator,__makeTemplateObject}from"tslib";import*as React from"react";import{Form,useField}from"informed";import{observer}from"mobx-react";import{get,useDimensions,unescapeFormId}from"../../utils";import{CloseButton,ConsoleBody,ConsoleWrap}from"./styled.components";import{ServerChooser}from"./ServerDropdown";import{OperationParameters}from"./OperationParameters";import{ActionPanel}from"./ActionPanel";import{ResponsePanel}from"./ResponsePanel";import{RequestBody}from"./RequestBody";import{ConsoleBadges}from"./ConsoleBadges";import{AuthPanel,requiredValidator}from"./AuthPanel";import{AnalyticsEventType}from"../../services";import Swagger from"swagger-client";import{JsonPointer,ShelfIcon,CrossIcon,LockIcon}from"../../redoc-lib";import{RenderHook}from"../../redoc-lib/src/components/helper";import{l}from"../../redoc-lib/src/services/Labels";import styled from"../../redoc-lib/src/styled-components";import{CodeHeader,Panel,Header,Accordion,Trigger,Title}from"../Panel";import{OAuth2}from"../../services/OAuth2";import{PanelBody}from"../Panel/PanelBody";import{getParameters,updateStorage}from"./utils";import{isFileUploadMime}from"../common/FileUpload/helper";function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}var flexColumn={flex:1,display:"flex",flexDirection:"column"},Console=function(e){function t(t){var r=e.call(this,t)||this;return Object.defineProperty(r,"formApi",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(r,"setFormApi",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.formApi=e,setTimeout((function(){r.setState({form:r.formApi.getState()})}),0)}}),Object.defineProperty(r,"handleChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.setState({form:e}),updateStorage(e)}}),Object.defineProperty(r,"handleTabChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.setState({activeTab:e})}}),Object.defineProperty(r,"handleServerChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.setState({server:e}),r.props.operation.setActiveServer(e)}}),Object.defineProperty(r,"handleExecute",{enumerable:!0,configurable:!0,writable:!0,value:function(){return __awaiter(r,void 0,void 0,(function(){var e,t,r,o,n,a,s,i,l,c,u,p,d,m,h,f,v,g,y,b,_,P,R,S,C,I,E,w,A,T,k,x,O,B,q,j,F=this;return __generator(this,(function(H){switch(H.label){case 0:if(e=this.props,t=e.store,r=e.operation,o=e.onResponse,this.formApi.submitForm(),n=this.formApi.getState(),a=n.values,n.invalid)return this.setState({shaking:!0}),setTimeout((function(){return F.setState({shaking:!1})}),1e3),null===(k=null===(T=null==t?void 0:t.options.events)||void 0===T?void 0:T.tryItSent)||void 0===k||k.call(T,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"ValidationFailed",operationId:r.operationId,operationPath:r.path,operationHttpVerb:r.httpVerb,operationSummary:r.description}),[2];if(s=this.props.operation.requestBody,i=s&&s.content&&s.content.active&&s.content.active.name||"",l=a.body,/json/.test(i))try{l=JSON.parse(l)}catch(e){console.error(e)}if(this.setState({loading:!0}),c=this.state.resolvedRawSpec,!(u=get(c,["paths",r.path,(r.httpVerb||"").toLowerCase(),"servers"])||get(c,["paths",r.path,"servers"])||get(c,["servers"])))throw console.error("Servers are not specified in your OpenAPI file. You can't use Try It Out console without specifying servers. If you use OpenAPI 2, make sure you configured host and basepath"),new Error("Servers are not specified");p=u.find((function(e){return F.state.server.url.endsWith(e.url.endsWith("/")?e.url.substring(0,e.url.length-1):e.url)})),d=Date.now(),m=!!window.document.documentMode,f=a.auth,a.auth?(v=Object.keys(a.auth)[0],g=unescapeFormId(v),h=__assign(__assign({},c),{components:__assign(__assign({},c.components),{securitySchemes:__assign(__assign({},c.components.securitySchemes),(w={},w[g]=__assign(__assign({},c.components.securitySchemes[g]),{type:"openIdConnect"===c.components.securitySchemes[g].type?"oauth2":c.components.securitySchemes[g].type}),w))})}),f=__assign(__assign({},f),((A={})[g]=f[v],A))):h=__assign({},c),(y=t.options.corsProxyUrl)&&c.servers&&c.servers.length&&(h.servers=c.servers.map((function(e){return __assign(__assign({},e),{url:y+normalizeUrlProtocol(e.url)})}))),(b=(null===(O=null===(x=null==s?void 0:s.content)||void 0===x?void 0:x.active)||void 0===O?void 0:O.name)||null)&&l&&isFileUploadMime(b)&&(_=Object.values(l),l=_.length>1?_:_[0]),P=function(e,t){return function(r){return F.props.store.options.sendXUserAgentInTryIt&&(r.headers["X-User-Agent"]="Redocly Try it API console"),e?e(r,t):r}},R={userFetch:m&&require("cross-fetch").fetch,server:y?y+normalizeUrlProtocol(p.url):p.url,serverVariables:this.state.server.variables,spec:h,pathName:r.path,method:r.httpVerb,parameters:__assign(__assign(__assign(__assign({},a.path),a.query),a.header),a.cookie),securities:{authorized:f},requestBody:l,requestContentType:b,responseContentType:(null===(B=a.header)||void 0===B?void 0:B.Accept)||null,requestInterceptor:P(t.options.requestInterceptor,r)},H.label=1;case 1:return H.trys.push([1,5,8,9]),[4,Swagger.execute(R)];case 2:return(S=H.sent())&&S.data instanceof Blob?(C=S,[4,S.data.text()]):[3,4];case 3:C.data=H.sent(),H.label=4;case 4:return null==o||o({request:R,response:S}),this.setState({response:S,error:void 0}),[3,9];case 5:return(I=H.sent())&&I.response&&I.response.data instanceof Blob?(E=I.response,[4,I.response.data.text()]):[3,7];case 6:E.data=H.sent(),null==o||o({request:R,response:I.response}),H.label=7;case 7:return this.setState({response:void 0,error:I}),[3,9];case 8:return this.setState({loading:!1,activeTab:1,time:Date.now()-d}),null===(j=null===(q=null==t?void 0:t.options.events)||void 0===q?void 0:q.tryItSent)||void 0===j||j.call(q,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"Sent",operationId:r.operationId,operationPath:r.path,operationHttpVerb:r.httpVerb,operationSummary:r.description}),[7];case 9:return[2]}}))}))}}),r.state={form:{values:{path:getParameters(t.operation.parameters,"path"),cookie:getParameters(t.operation.parameters,"cookie"),header:getParameters(t.operation.parameters,"header"),query:getParameters(t.operation.parameters,"query")}},shaking:!1,loading:!1,activeTab:0,server:{}},r}return __extends(t,e),Object.defineProperty(t.prototype,"componentDidMount",{enumerable:!1,configurable:!0,writable:!0,value:function(){return __awaiter(this,void 0,void 0,(function(){var e,t,r,o,n;return __generator(this,(function(a){switch(a.label){case 0:return e=this.props,t=e.store,r=e.specIdx,o=e.operation,[4,t.dereferenceSpecForTryIt(r||0,o)];case 1:return n=a.sent(),this.setState({resolvedRawSpec:n}),this.formApi.setValues({}),[2]}}))}))}}),Object.defineProperty(t.prototype,"componentDidUpdate",{enumerable:!1,configurable:!0,writable:!0,value:function(e){e.operation!==this.props.operation&&this.setState({response:void 0,error:void 0,activeTab:0})}}),Object.defineProperty(t.prototype,"render",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.props,t=e.operation,r=e.className,o=e.rootElement,n=this.state,a=n.shaking,s=n.activeTab,i=n.form,l=n.response,c=n.loading,u=n.error,p=!(!l&&!u);return React.createElement(ConsoleWrapHook,{shaking:a,className:r,rootElement:o},React.createElement(CodeHeader,null,React.createElement(ConsoleBadges,{active:s,hasResponse:p,onChange:this.handleTabChange}),this.props.onClose&&React.createElement(CloseButton,{onClick:this.props.onClose}," ✕ ")),React.createElement(ConsoleBody,{hidden:0!==s},this.renderRequest()),React.createElement(ConsoleBody,{hidden:1!==s},this.renderResponse()),React.createElement(ActionPanel,{hasResponse:p,params:i.values&&__assign({},i.values),operation:t,loading:c,execute:this.handleExecute}))}}),Object.defineProperty(t.prototype,"renderRequest",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e,t=this.props,r=t.operation,o=t.store,n=t.properties,a=t.securityDefaults,s=this.state,i=s.form,c=s.resolvedRawSpec,u=s.server,p=i.errors||{},d=p.path||p.cookie||p.header||p.query,m=c&&JsonPointer.get(c,r.pointer),h=i.values&&i.values.auth&&Object.keys(i.values.auth)[0];h&&i.values.auth[h]||(h=void 0),!h||void 0===i.values.auth[h].token&&void 0===i.values.auth[h].client_id&&void 0===i.values.auth[h].client_secret||i.values.auth[h].token&&i.values.auth[h].token.access_token||(h=void 0),h&&null!=i.values.auth[h].username&&(i.values.auth[h].username&&i.values.auth[h].password||(h=void 0));var f=r.parameters||[],v=null===(e=null==o?void 0:o.options.hooks)||void 0===e?void 0:e.ReplaceTryItAuthPanel;return c?React.createElement(React.Fragment,null,React.createElement(Form,{onChange:this.handleChange,getApi:this.setFormApi,style:__assign(__assign({},flexColumn),{margin:0})},React.createElement(Accordion,{initialActiveIdx:r.security.length&&h?1:0},r.security.length&&React.createElement(TryItPanel,{header:l("tryItAuth"),"data-cy":"security-trigger",renderChildrenHidden:!0,error:!h&&!!p.auth,success:!!h},v?React.createElement(AuthPanelHook,{field:"auth",validate:requiredValidator},(function(e){return React.createElement(RenderHook,{Hook:v,props:{server:u,operation:r,onChange:e,OAuth2:OAuth2}})})):React.createElement(AuthPanel,{formApi:this.formApi,form:i,operation:r,activeServer:u.url,authCorsProxyUrl:o.options.authCorsProxyUrl,securityDefaults:a}))||null,r.requestBody&&React.createElement(TryItPanel,{header:l("tryItBody"),"data-cy":"body-trigger",renderChildrenHidden:!0,error:!!p.body},React.createElement(RequestBody,{validate:allowBodyErrors,console:this,body:r.requestBody,id:r.id,resolvedBody:m.requestBody,properties:n}))||null,f.length&&React.createElement(TryItPanel,{header:l("tryItParameters"),"data-cy":"parameters-trigger",error:d,renderChildrenHidden:!0},React.createElement(OperationParameters,{operation:r,values:i.values,errors:i.errors||{}}))||null)),React.createElement(ServerChooser,{operation:r,onChange:this.handleServerChange})):"Loading..."}}),Object.defineProperty(t.prototype,"renderResponse",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.state,t=e.response,r=e.error,o=e.time;return React.createElement(ResponsePanel,{response:t,error:r,time:o})}}),t=__decorate([observer],t)}(React.Component);export{Console};function allowBodyErrors(){}function ConsoleWrapHook(e){var t=e.shaking,r=e.className,o=e.children,n=e.rootElement,a=useDimensions(n)[0];return React.createElement(ConsoleWrap,{shaking:t,className:r,"data-cy":"console",fullWidth:null==a?void 0:a.width},o)}function AuthPanelHook(e){var t=useField(__assign({},e)),r=t.fieldApi,o=t.render,n=t.userProps,a=r.setValue,s=n.children;return o(React.createElement(React.Fragment,null,s(a)))}function TryItPanel(e){return React.createElement(StyledTryItPanel,__assign({},e,{header:function(t){var r=t.toggle,o=t.expanded;return React.createElement(Header,{onClick:r,isExpanded:o,"data-cy":e["data-cy"]},React.createElement(Trigger,null,React.createElement(Title,null,e.header),React.createElement(ShelfIcon,{direction:o?"down":"right"})),e.error&&React.createElement(CrossIcon,{size:"14px",color:"#ff908b"})||null,e.success&&React.createElement(LockIcon,{size:"14px",color:"#56ff26"})||null)}}))}var templateObject_1,StyledTryItPanel=styled(Panel)(templateObject_1||(templateObject_1=__makeTemplateObject(["\n "," {\n color: white;\n border: 1px solid ",";\n padding: 10px;\n }\n\n "," path {\n fill: white;\n }\n\n "," {\n padding: 15px 10px;\n background-color: #3e4c59;\n border: 1px solid ",";\n border-top: 0;\n }\n"],["\n "," {\n color: white;\n border: 1px solid ",";\n padding: 10px;\n }\n\n "," path {\n fill: white;\n }\n\n "," {\n padding: 15px 10px;\n background-color: #3e4c59;\n border: 1px solid ",";\n border-top: 0;\n }\n"])),Header,(function(e){return e.error?"#ff908b":"#89949f"}),ShelfIcon,PanelBody,(function(e){return e.error?"#ff908b":"#89949f"}));
1
+ import{__assign,__awaiter,__decorate,__extends,__generator,__makeTemplateObject}from"tslib";import*as React from"react";import{Form,useField}from"informed";import{observer}from"mobx-react";import{get,useDimensions,unescapeFormId}from"../../utils";import{CloseButton,ConsoleBody,ConsoleWrap}from"./styled.components";import{ServerChooser}from"./ServerDropdown";import{OperationParameters}from"./OperationParameters";import{ActionPanel}from"./ActionPanel";import{ResponsePanel}from"./ResponsePanel";import{RequestBody}from"./RequestBody";import{ConsoleBadges}from"./ConsoleBadges";import{AuthPanel,requiredValidator}from"./AuthPanel";import{AnalyticsEventType}from"../../services";import Swagger from"swagger-client";import{JsonPointer,ShelfIcon,CrossIcon,LockIcon}from"../../redoc-lib";import{RenderHook}from"../../redoc-lib/src/components/helper";import{l}from"../../redoc-lib/src/services/Labels";import styled from"../../redoc-lib/src/styled-components";import{CodeHeader,Panel,Header,Accordion,Trigger,Title}from"../Panel";import{OAuth2}from"../../services/OAuth2";import{PanelBody}from"../Panel/PanelBody";import{getParameters,updateStorage}from"./utils";import{isFileUploadMime}from"../common/FileUpload/helper";function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}var flexColumn={flex:1,display:"flex",flexDirection:"column"},Console=function(e){function t(t){var r=e.call(this,t)||this;return Object.defineProperty(r,"formApi",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(r,"setFormApi",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.formApi=e,setTimeout((function(){r.setState({form:r.formApi.getState()})}),0)}}),Object.defineProperty(r,"handleChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.setState({form:e}),updateStorage(e)}}),Object.defineProperty(r,"handleTabChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.setState({activeTab:e})}}),Object.defineProperty(r,"handleServerChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.setState({server:e}),r.props.operation.setActiveServer(e)}}),Object.defineProperty(r,"handleExecute",{enumerable:!0,configurable:!0,writable:!0,value:function(){return __awaiter(r,void 0,void 0,(function(){var e,t,r,o,n,a,s,i,l,c,u,p,d,m,h,f,v,g,y,b,_,P,R,S,C,I,E,w,A,T,k,x,O,B,q,j,F=this;return __generator(this,(function(H){switch(H.label){case 0:if(e=this.props,t=e.store,r=e.operation,o=e.onResponse,this.formApi.submitForm(),n=this.formApi.getState(),a=n.values,n.invalid)return this.setState({shaking:!0}),setTimeout((function(){return F.setState({shaking:!1})}),1e3),null===(k=null===(T=null==t?void 0:t.options.events)||void 0===T?void 0:T.tryItSent)||void 0===k||k.call(T,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"ValidationFailed",operationId:r.operationId,operationPath:r.path,operationHttpVerb:r.httpVerb,operationSummary:r.description}),[2];if(s=this.props.operation.requestBody,i=s&&s.content&&s.content.active&&s.content.active.name||"",l=a.body,/json/.test(i))try{l=JSON.parse(l)}catch(e){console.error(e)}if(this.setState({loading:!0}),c=this.state.resolvedRawSpec,!(u=get(c,["paths",r.path,(r.httpVerb||"").toLowerCase(),"servers"])||get(c,["paths",r.path,"servers"])||get(c,["servers"])))throw console.error("Servers are not specified in your OpenAPI file. You can't use Try It Out console without specifying servers. If you use OpenAPI 2, make sure you configured host and basepath"),new Error("Servers are not specified");p=u.find((function(e){return F.state.server.url.endsWith(e.url.endsWith("/")?e.url.substring(0,e.url.length-1):e.url)})),d=Date.now(),m=!!window.document.documentMode,f=a.auth,a.auth?(v=Object.keys(a.auth)[0],g=unescapeFormId(v),h=__assign(__assign({},c),{components:__assign(__assign({},c.components),{securitySchemes:__assign(__assign({},c.components.securitySchemes),(w={},w[g]=__assign(__assign({},c.components.securitySchemes[g]),{type:"openIdConnect"===c.components.securitySchemes[g].type?"oauth2":c.components.securitySchemes[g].type}),w))})}),f=__assign(__assign({},f),((A={})[g]=f[v],A))):h=__assign({},c),(y=t.options.corsProxyUrl)&&c.servers&&c.servers.length&&(h.servers=c.servers.map((function(e){return __assign(__assign({},e),{url:y+normalizeUrlProtocol(e.url)})}))),(b=(null===(O=null===(x=null==s?void 0:s.content)||void 0===x?void 0:x.active)||void 0===O?void 0:O.name)||null)&&l&&isFileUploadMime(b)&&(_=Object.values(l),l=_.length>1?_:_[0]),P=function(e,t){return function(r){return F.props.store.options.sendXUserAgentInTryIt&&(r.headers["X-User-Agent"]="Redocly Try it API console"),e?e(r,t):r}},R={userFetch:m&&require("cross-fetch").fetch,server:y?y+normalizeUrlProtocol(p.url):p.url,serverVariables:this.state.server.variables,spec:h,pathName:r.path,method:r.httpVerb,parameters:__assign(__assign(__assign(__assign({},a.path),a.query),a.header),a.cookie),securities:{authorized:f},requestBody:l,requestContentType:b,responseContentType:(null===(B=a.header)||void 0===B?void 0:B.Accept)||null,requestInterceptor:P(t.options.requestInterceptor,r)},H.label=1;case 1:return H.trys.push([1,5,8,9]),[4,Swagger.execute(R)];case 2:return(S=H.sent())&&S.data instanceof Blob?(C=S,[4,S.data.text()]):[3,4];case 3:C.data=H.sent(),H.label=4;case 4:return null==o||o({request:R,response:S}),this.setState({response:S,error:void 0}),[3,9];case 5:return(I=H.sent())&&I.response&&I.response.data instanceof Blob?(E=I.response,[4,I.response.data.text()]):[3,7];case 6:E.data=H.sent(),null==o||o({request:R,response:I.response}),H.label=7;case 7:return this.setState({response:void 0,error:I}),[3,9];case 8:return this.setState({loading:!1,activeTab:1,time:Date.now()-d}),null===(j=null===(q=null==t?void 0:t.options.events)||void 0===q?void 0:q.tryItSent)||void 0===j||j.call(q,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"Sent",operationId:r.operationId,operationPath:r.path,operationHttpVerb:r.httpVerb,operationSummary:r.description}),[7];case 9:return[2]}}))}))}}),r.state={form:{values:{path:getParameters(t.operation.parameters,"path"),cookie:getParameters(t.operation.parameters,"cookie"),header:getParameters(t.operation.parameters,"header"),query:getParameters(t.operation.parameters,"query")}},shaking:!1,loading:!1,activeTab:0,server:{}},r}return __extends(t,e),Object.defineProperty(t.prototype,"componentDidMount",{enumerable:!1,configurable:!0,writable:!0,value:function(){return __awaiter(this,void 0,void 0,(function(){var e,t,r,o,n;return __generator(this,(function(a){switch(a.label){case 0:return e=this.props,t=e.store,r=e.specIdx,o=e.operation,[4,t.dereferenceSpecForTryIt(r||0,o)];case 1:return n=a.sent(),this.setState({resolvedRawSpec:n}),this.formApi.setValues({}),[2]}}))}))}}),Object.defineProperty(t.prototype,"componentDidUpdate",{enumerable:!1,configurable:!0,writable:!0,value:function(e){e.operation!==this.props.operation&&this.setState({response:void 0,error:void 0,activeTab:0})}}),Object.defineProperty(t.prototype,"render",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.props,t=e.operation,r=e.className,o=e.rootElement,n=this.state,a=n.shaking,s=n.activeTab,i=n.form,l=n.response,c=n.loading,u=n.error,p=!(!l&&!u);return React.createElement(ConsoleWrapHook,{shaking:a,className:r,rootElement:o},React.createElement(CodeHeader,null,React.createElement(ConsoleBadges,{active:s,hasResponse:p,onChange:this.handleTabChange}),this.props.onClose&&React.createElement(CloseButton,{onClick:this.props.onClose}," ✕ ")),React.createElement(ConsoleBody,{hidden:0!==s},this.renderRequest()),React.createElement(ConsoleBody,{hidden:1!==s},this.renderResponse()),React.createElement(ActionPanel,{hasResponse:p,params:i.values&&__assign({},i.values),operation:t,loading:c,execute:this.handleExecute}))}}),Object.defineProperty(t.prototype,"renderRequest",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e,t=this.props,r=t.operation,o=t.store,n=t.properties,a=t.securityDefaults,s=this.state,i=s.form,c=s.resolvedRawSpec,u=s.server,p=i.errors||{},d=p.path||p.cookie||p.header||p.query,m=c&&JsonPointer.get(c,r.pointer),h=i.values&&i.values.auth&&Object.keys(i.values.auth)[0];h&&i.values.auth[h]||(h=void 0),!h||void 0===i.values.auth[h].token&&void 0===i.values.auth[h].client_id&&void 0===i.values.auth[h].client_secret||i.values.auth[h].token&&i.values.auth[h].token.access_token||(h=void 0),h&&null!=i.values.auth[h].username&&(i.values.auth[h].username&&i.values.auth[h].password||(h=void 0));var f=r.parameters||[],v=null===(e=null==o?void 0:o.options.hooks)||void 0===e?void 0:e.ReplaceTryItSecurityPanel;return c?React.createElement(React.Fragment,null,React.createElement(Form,{onChange:this.handleChange,getApi:this.setFormApi,style:__assign(__assign({},flexColumn),{margin:0})},React.createElement(Accordion,{initialActiveIdx:r.security.length&&h?1:0},r.security.length&&React.createElement(TryItPanel,{header:l("tryItAuth"),"data-cy":"security-trigger",renderChildrenHidden:!0,error:!h&&!!p.auth,success:!!h},v?React.createElement(AuthPanelHook,{field:"auth",validate:requiredValidator},(function(e){return React.createElement(RenderHook,{Hook:v,props:{server:u,operation:r,onChange:e,OAuth2:OAuth2}})})):React.createElement(AuthPanel,{formApi:this.formApi,form:i,operation:r,activeServer:u.url,authCorsProxyUrl:o.options.authCorsProxyUrl,securityDefaults:a}))||null,r.requestBody&&React.createElement(TryItPanel,{header:l("tryItBody"),"data-cy":"body-trigger",renderChildrenHidden:!0,error:!!p.body},React.createElement(RequestBody,{validate:allowBodyErrors,console:this,body:r.requestBody,id:r.id,resolvedBody:m.requestBody,properties:n}))||null,f.length&&React.createElement(TryItPanel,{header:l("tryItParameters"),"data-cy":"parameters-trigger",error:d,renderChildrenHidden:!0},React.createElement(OperationParameters,{operation:r,values:i.values,errors:i.errors||{}}))||null)),React.createElement(ServerChooser,{operation:r,onChange:this.handleServerChange})):"Loading..."}}),Object.defineProperty(t.prototype,"renderResponse",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.state,t=e.response,r=e.error,o=e.time;return React.createElement(ResponsePanel,{response:t,error:r,time:o})}}),t=__decorate([observer],t)}(React.Component);export{Console};function allowBodyErrors(){}function ConsoleWrapHook(e){var t=e.shaking,r=e.className,o=e.children,n=e.rootElement,a=useDimensions(n)[0];return React.createElement(ConsoleWrap,{shaking:t,className:r,"data-cy":"console",fullWidth:null==a?void 0:a.width},o)}function AuthPanelHook(e){var t=useField(__assign({},e)),r=t.fieldApi,o=t.render,n=t.userProps,a=r.setValue,s=n.children;return o(React.createElement(React.Fragment,null,s(a)))}function TryItPanel(e){return React.createElement(StyledTryItPanel,__assign({},e,{header:function(t){var r=t.toggle,o=t.expanded;return React.createElement(Header,{onClick:r,isExpanded:o,"data-cy":e["data-cy"]},React.createElement(Trigger,null,React.createElement(Title,null,e.header),React.createElement(ShelfIcon,{direction:o?"down":"right"})),e.error&&React.createElement(CrossIcon,{size:"14px",color:"#ff908b"})||null,e.success&&React.createElement(LockIcon,{size:"14px",color:"#56ff26"})||null)}}))}var templateObject_1,StyledTryItPanel=styled(Panel)(templateObject_1||(templateObject_1=__makeTemplateObject(["\n "," {\n color: white;\n border: 1px solid ",";\n padding: 10px;\n }\n\n "," path {\n fill: white;\n }\n\n "," {\n padding: 15px 10px;\n background-color: #3e4c59;\n border: 1px solid ",";\n border-top: 0;\n }\n"],["\n "," {\n color: white;\n border: 1px solid ",";\n padding: 10px;\n }\n\n "," path {\n fill: white;\n }\n\n "," {\n padding: 15px 10px;\n background-color: #3e4c59;\n border: 1px solid ",";\n border-top: 0;\n }\n"])),Header,(function(e){return e.error?"#ff908b":"#89949f"}),ShelfIcon,PanelBody,(function(e){return e.error?"#ff908b":"#89949f"}));
2
2
  //# sourceMappingURL=Console.js.map
@@ -1,2 +1,2 @@
1
- import{__makeTemplateObject}from"tslib";import styled from"../../redoc-lib/src/styled-components";export var HttpVerb=styled.span(templateObject_1||(templateObject_1=__makeTemplateObject(["\n display: inline-block;\n color: ",";\n text-transform: uppercase;\n text-align: center;\n font-family: ",";\n border-radius: ",";\n background-color: ",";\n min-width: 48px;\n padding: 0 8px;\n font-size: ",";\n line-height: ",";\n font-weight: ",";\n"],["\n display: inline-block;\n color: ",";\n text-transform: uppercase;\n text-align: center;\n font-family: ",";\n border-radius: ",";\n background-color: ",";\n min-width: 48px;\n padding: 0 8px;\n font-size: ",";\n line-height: ",";\n font-weight: ",";\n"])),(function(t){return t.theme.components.httpBadges.color}),(function(t){return t.theme.components.httpBadges.fontFamily}),(function(t){return t.theme.components.httpBadges.borderRadius}),(function(t){var e=t.type;return t.theme.colors.http[e]||"#707070"}),(function(t){return t.theme.components.httpBadges.sizes.medium.fontSize}),(function(t){return t.theme.components.httpBadges.sizes.medium.lineHeight}),(function(t){return t.theme.components.httpBadges.fontWeight}));var templateObject_1;
1
+ import{__makeTemplateObject}from"tslib";import styled from"../../redoc-lib/src/styled-components";export var HttpVerb=styled.span(templateObject_1||(templateObject_1=__makeTemplateObject(["\n display: inline-block;\n color: ",";\n text-transform: uppercase;\n text-align: center;\n font-family: ",";\n border-radius: ",";\n background-color: ",";\n min-width: 58px;\n padding: 0 8px;\n font-size: ",";\n line-height: ",";\n font-weight: ",";\n"],["\n display: inline-block;\n color: ",";\n text-transform: uppercase;\n text-align: center;\n font-family: ",";\n border-radius: ",";\n background-color: ",";\n min-width: 58px;\n padding: 0 8px;\n font-size: ",";\n line-height: ",";\n font-weight: ",";\n"])),(function(t){return t.theme.components.httpBadges.color}),(function(t){return t.theme.components.httpBadges.fontFamily}),(function(t){return t.theme.components.httpBadges.borderRadius}),(function(t){var e=t.type;return t.theme.colors.http[e]||"#707070"}),(function(t){return t.theme.components.httpBadges.sizes.medium.fontSize}),(function(t){return t.theme.components.httpBadges.sizes.medium.lineHeight}),(function(t){return t.theme.components.httpBadges.fontWeight}));var templateObject_1;
2
2
  //# sourceMappingURL=HttpVerb.js.map