@redocly/openapi-docs 3.12.0 → 3.12.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 (384) hide show
  1. package/dist/redocly-openapi-docs.min.js +753 -750
  2. package/lib/components/ApiInfo/ApiInfo.js +29 -1
  3. package/lib/components/ApiInfo/Metadata.js +29 -1
  4. package/lib/components/ApiInfo/index.js +2 -1
  5. package/lib/components/ApiInfo/styled.js +16 -8
  6. package/lib/components/CallbackSamples/CallbackSamples.js +25 -4
  7. package/lib/components/CallbackSamples/index.js +2 -1
  8. package/lib/components/Callbacks/CallbackDetails.js +17 -3
  9. package/lib/components/Callbacks/CallbackOperation.js +24 -3
  10. package/lib/components/Callbacks/CallbackSummary.js +19 -3
  11. package/lib/components/Callbacks/CallbacksList.js +16 -1
  12. package/lib/components/Callbacks/index.js +4 -1
  13. package/lib/components/Callbacks/styled.js +6 -3
  14. package/lib/components/Content/Content.js +10 -1
  15. package/lib/components/Content/index.js +2 -1
  16. package/lib/components/Content/useAutoScroll.js +50 -1
  17. package/lib/components/ContentItem/ContentItem.js +31 -1
  18. package/lib/components/ContentItem/index.js +2 -1
  19. package/lib/components/ContentItem/useIsExpanded.js +33 -1
  20. package/lib/components/ContentItems/ContentItems.js +19 -1
  21. package/lib/components/ContentItems/Items.js +13 -1
  22. package/lib/components/ContentItems/VirtualList.js +35 -1
  23. package/lib/components/ContentItems/helpers.js +49 -1
  24. package/lib/components/ContentItems/index.js +2 -1
  25. package/lib/components/ContentItems/useScrollOnRender.js +26 -1
  26. package/lib/components/Discriminator/Discriminator.js +27 -2
  27. package/lib/components/Discriminator/index.js +2 -1
  28. package/lib/components/Download/DownloadSpecification.js +46 -4
  29. package/lib/components/Download/index.js +2 -1
  30. package/lib/components/Download/types.js +2 -0
  31. package/lib/components/Download/useDownloadInfo.js +42 -1
  32. package/lib/components/ErrorBoundary/ErrorBoundary.js +22 -2
  33. package/lib/components/ErrorBoundary/index.js +2 -1
  34. package/lib/components/ExpandAllButton/ExpandAllButton.js +31 -2
  35. package/lib/components/ExpandAllButton/index.js +2 -1
  36. package/lib/components/ExternalDocumentation/ExternalDocumentation.js +18 -4
  37. package/lib/components/ExternalDocumentation/index.js +2 -1
  38. package/lib/components/Language/LanguageDropdown.js +21 -1
  39. package/lib/components/Language/LanguageItem.js +33 -1
  40. package/lib/components/Language/LanguageList.js +93 -1
  41. package/lib/components/Language/_tests_/LanguageDropdown.test.js +23 -1
  42. package/lib/components/Language/constants.js +3 -1
  43. package/lib/components/Language/index.js +4 -1
  44. package/lib/components/Language/styled.js +29 -15
  45. package/lib/components/Markdown/Markdown.js +64 -1
  46. package/lib/components/Markdown/index.js +3 -1
  47. package/lib/components/Markdown/types.js +2 -0
  48. package/lib/components/MediaTypeSwitch/MediaTypesSwitch.js +51 -1
  49. package/lib/components/MediaTypeSwitch/index.js +2 -1
  50. package/lib/components/OperationItem/Description.js +9 -1
  51. package/lib/components/OperationItem/OperationItem.js +70 -5
  52. package/lib/components/OperationItem/_tests_/OperationItem.test.js +70 -1
  53. package/lib/components/OperationItem/_tests_/__mocks__/mock-intersection-observer.js +40 -1
  54. package/lib/components/OperationItem/index.js +2 -1
  55. package/lib/components/OperationItem/types.js +2 -0
  56. package/lib/components/Overlay.js +48 -3
  57. package/lib/components/Overview/Overview.js +20 -1
  58. package/lib/components/Overview/index.js +2 -1
  59. package/lib/components/PageFooter/PageFooter.js +19 -1
  60. package/lib/components/PageFooter/index.js +2 -1
  61. package/lib/components/Panel/ResponsePanel.js +12 -6
  62. package/lib/components/Panel/Trigger.js +4 -2
  63. package/lib/components/Panel/index.js +3 -1
  64. package/lib/components/PanelItem/PanelItem.js +6 -1
  65. package/lib/components/PanelItem/index.js +3 -1
  66. package/lib/components/PanelItem/styled.js +20 -10
  67. package/lib/components/PayloadSamples/Example.js +6 -1
  68. package/lib/components/PayloadSamples/ExampleValue.js +30 -1
  69. package/lib/components/PayloadSamples/MediaTypeSamples.js +36 -2
  70. package/lib/components/PayloadSamples/PayloadSamples.js +26 -1
  71. package/lib/components/PayloadSamples/index.js +7 -1
  72. package/lib/components/PayloadSamples/styled.js +9 -4
  73. package/lib/components/PayloadSamples/types.js +2 -0
  74. package/lib/components/PropertyDetails/DescriptionEnums.js +19 -3
  75. package/lib/components/PropertyDetails/EnumValues.js +37 -1
  76. package/lib/components/PropertyDetails/Examples.js +26 -1
  77. package/lib/components/PropertyDetails/Extensions.js +17 -2
  78. package/lib/components/PropertyDetails/FieldDetail.js +15 -2
  79. package/lib/components/PropertyDetails/FieldDetails.js +51 -6
  80. package/lib/components/PropertyDetails/Pattern.js +21 -1
  81. package/lib/components/PropertyDetails/PlusCircleIcon.js +10 -4
  82. package/lib/components/PropertyDetails/PropertyDetails.js +22 -5
  83. package/lib/components/PropertyDetails/SchemaTypeInfo.js +10 -2
  84. package/lib/components/PropertyDetails/SimpleEnums.js +13 -2
  85. package/lib/components/PropertyDetails/cycleColorsByLevel.js +18 -1
  86. package/lib/components/PropertyDetails/index.js +4 -1
  87. package/lib/components/PropertyDetails/styled.js +15 -7
  88. package/lib/components/PropertyDetails/types.js +2 -0
  89. package/lib/components/RedoclyOpenAPIDocs/Providers.js +114 -1
  90. package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocs.js +57 -1
  91. package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocsStandalone.js +86 -1
  92. package/lib/components/RedoclyOpenAPIDocs/index.js +5 -1
  93. package/lib/components/RedoclyOpenAPIDocs/styled.js +4 -2
  94. package/lib/components/RedoclyOpenAPIDocs/types.js +2 -0
  95. package/lib/components/RedoclyOpenAPIDocs/utils.js +33 -1
  96. package/lib/components/RenderHook/RenderHook.js +17 -1
  97. package/lib/components/RenderHook/index.js +2 -1
  98. package/lib/components/Replay/EmbeddedReplay.js +41 -3
  99. package/lib/components/Replay/Replay.js +99 -1
  100. package/lib/components/Replay/index.js +3 -1
  101. package/lib/components/Replay/utils.js +208 -1
  102. package/lib/components/Request/RequestDetails.js +33 -2
  103. package/lib/components/Request/types.js +2 -0
  104. package/lib/components/RequestParameters/Body.js +8 -1
  105. package/lib/components/RequestParameters/ParametersGroup.js +19 -4
  106. package/lib/components/RequestParameters/RequestParameters.js +40 -1
  107. package/lib/components/RequestParameters/index.js +4 -1
  108. package/lib/components/RequestSamples/CodeSample.js +55 -2
  109. package/lib/components/RequestSamples/Example.js +37 -1
  110. package/lib/components/RequestSamples/RequestSamples.js +89 -5
  111. package/lib/components/RequestSamples/index.js +3 -1
  112. package/lib/components/RequestSamples/useCodeSamples.js +92 -1
  113. package/lib/components/ResponseSamples/ResponseSamples.js +47 -1
  114. package/lib/components/ResponseSamples/Summary.js +9 -1
  115. package/lib/components/ResponseSamples/index.js +2 -1
  116. package/lib/components/Responses/OperationResponseList.js +42 -2
  117. package/lib/components/Responses/ResponseDetails.js +18 -1
  118. package/lib/components/Responses/ResponseHeaders.js +15 -1
  119. package/lib/components/Responses/index.js +6 -1
  120. package/lib/components/Responses/styled.js +14 -6
  121. package/lib/components/Responses/types.js +2 -0
  122. package/lib/components/RightPanel/RightPanel.js +21 -1
  123. package/lib/components/RightPanel/index.js +2 -1
  124. package/lib/components/Samples/ExampleSwitch.js +33 -1
  125. package/lib/components/Samples/index.js +3 -1
  126. package/lib/components/Samples/use-example-key.js +12 -1
  127. package/lib/components/Schema/ArraySchema.js +45 -1
  128. package/lib/components/Schema/ObjectSchema.js +29 -1
  129. package/lib/components/Schema/OneOfSchema.js +47 -3
  130. package/lib/components/Schema/RecursiveSchema.js +10 -1
  131. package/lib/components/Schema/Schema.js +63 -2
  132. package/lib/components/Schema/SubSchema.js +20 -1
  133. package/lib/components/Schema/helpers.js +16 -1
  134. package/lib/components/Schema/index.js +5 -1
  135. package/lib/components/Schema/types.js +2 -0
  136. package/lib/components/Schema/useOneOfLocationIdx.js +11 -1
  137. package/lib/components/SchemaDefinition/SchemaDefinition.js +65 -2
  138. package/lib/components/SchemaDefinition/index.js +2 -1
  139. package/lib/components/SectionContent/SectionContent.js +49 -6
  140. package/lib/components/SectionContent/index.js +2 -1
  141. package/lib/components/SectionItem/SectionItem.js +14 -1
  142. package/lib/components/SectionItem/index.js +2 -1
  143. package/lib/components/Security/Divider.js +9 -2
  144. package/lib/components/Security/OAuthFlow.js +11 -1
  145. package/lib/components/Security/OAuthScopes.js +59 -9
  146. package/lib/components/Security/Security.js +15 -1
  147. package/lib/components/Security/SecurityButton.js +31 -7
  148. package/lib/components/Security/SecurityFlow.js +28 -4
  149. package/lib/components/Security/SecurityModal.js +34 -5
  150. package/lib/components/Security/SecuritySchemeItem.js +15 -4
  151. package/lib/components/Security/helper.js +16 -1
  152. package/lib/components/Security/index.js +11 -1
  153. package/lib/components/Security/styled.js +6 -3
  154. package/lib/components/SelectOrLabel/SelectOrLabel.js +12 -2
  155. package/lib/components/SelectOrLabel/index.js +2 -1
  156. package/lib/components/ServerList/ServerList.js +36 -10
  157. package/lib/components/ServerList/index.js +2 -1
  158. package/lib/components/ServerList/types.js +2 -0
  159. package/lib/components/ServerListDropdown/ServerListDropdown.js +54 -1
  160. package/lib/components/ServerListDropdown/index.js +2 -1
  161. package/lib/components/ServerListDropdown/styled.js +15 -6
  162. package/lib/components/SideMenu/SideMenu.js +13 -2
  163. package/lib/components/SideMenu/hooks/useMenuItems.js +110 -1
  164. package/lib/components/SideMenu/index.js +2 -1
  165. package/lib/components/SideMenu/types.js +2 -0
  166. package/lib/components/StickySidebar/SidebarActions.js +14 -2
  167. package/lib/components/StickySidebar/StickyResponsiveSidebar.js +37 -7
  168. package/lib/components/StickySidebar/index.js +2 -1
  169. package/lib/components/Tabs/Tabs.js +16 -5
  170. package/lib/components/Tabs/index.js +3 -1
  171. package/lib/components/Tabs/useTabsState.js +22 -1
  172. package/lib/components/TagItem/OperationNavigationItems.js +18 -4
  173. package/lib/components/TagItem/OperationsNavigation.js +46 -2
  174. package/lib/components/TagItem/TagItem.js +40 -7
  175. package/lib/components/TagItem/index.js +2 -1
  176. package/lib/components/TagItem/styled.js +5 -2
  177. package/lib/components/TagItem/types.js +2 -0
  178. package/lib/components/ViewNested/ViewNested.js +42 -9
  179. package/lib/components/ViewNested/index.js +2 -1
  180. package/lib/components/common/Badges.js +21 -5
  181. package/lib/components/common/BodyContent/BodyContent.js +31 -4
  182. package/lib/components/common/BodyContent/index.js +2 -1
  183. package/lib/components/common/ClearButton/ClearButton.js +5 -1
  184. package/lib/components/common/ClearButton/index.js +3 -1
  185. package/lib/components/common/ClearButton/styled.js +5 -2
  186. package/lib/components/common/ClearButton/types.js +2 -0
  187. package/lib/components/common/CodeBlockPanel.js +7 -3
  188. package/lib/components/common/ConstraintsView.js +14 -2
  189. package/lib/components/common/Dropdown/Dropdown.js +22 -4
  190. package/lib/components/common/Dropdown/index.js +2 -1
  191. package/lib/components/common/ExpandableExample/ExpandableExample.js +24 -3
  192. package/lib/components/common/ExpandableExample/index.js +2 -1
  193. package/lib/components/common/Extensions.js +17 -2
  194. package/lib/components/common/Fields/fields-layout.js +76 -51
  195. package/lib/components/common/Fields/fields.js +39 -17
  196. package/lib/components/common/Fields/index.js +3 -1
  197. package/lib/components/common/LinkToField.js +33 -6
  198. package/lib/components/common/OperationItemTitle.js +12 -6
  199. package/lib/components/common/SchemaSelection/SchemaSelection.js +51 -1
  200. package/lib/components/common/SchemaSelection/index.js +2 -1
  201. package/lib/components/common/Select/Select.js +21 -1
  202. package/lib/components/common/Select/index.js +3 -1
  203. package/lib/components/common/Select/styled.js +17 -9
  204. package/lib/components/common/Select/types.js +2 -0
  205. package/lib/components/common/Skeleton/LanguageListSkeleton.js +16 -6
  206. package/lib/components/common/Skeleton/Skeleton.js +15 -5
  207. package/lib/components/common/Skeleton/index.js +3 -1
  208. package/lib/components/common/headers.js +4 -2
  209. package/lib/components/common/index.js +14 -1
  210. package/lib/components/common/linkify.js +28 -4
  211. package/lib/components/common/mixins.js +4 -2
  212. package/lib/components/common/panels.js +52 -29
  213. package/lib/components/common/schema.js +16 -8
  214. package/lib/components/common/styled.js +15 -7
  215. package/lib/components/index.js +25 -1
  216. package/lib/components/pluggable/RedocExample.js +20 -1
  217. package/lib/components/pluggable/RedocSchema.js +22 -1
  218. package/lib/components/pluggable/index.js +3 -1
  219. package/lib/components/pluggable/styled.components.js +9 -4
  220. package/lib/constants.js +30 -1
  221. package/lib/empty.js +7 -1
  222. package/lib/events/codeSampleCopy.js +19 -1
  223. package/lib/events/creator.js +5 -1
  224. package/lib/events/index.js +8 -1
  225. package/lib/events/languageSwitch.js +18 -1
  226. package/lib/events/panelToggle.js +16 -1
  227. package/lib/events/serverSwitch.js +13 -1
  228. package/lib/events/tryItOpen.js +12 -1
  229. package/lib/events/tryItSent.js +12 -1
  230. package/lib/events/types.js +11 -1
  231. package/lib/hoc/types.js +2 -0
  232. package/lib/hoc/utils.js +4 -1
  233. package/lib/hoc/withRouter.js +17 -1
  234. package/lib/hoc/withStore.js +28 -1
  235. package/lib/hooks/index.js +9 -1
  236. package/lib/hooks/useActivateExample.js +35 -1
  237. package/lib/hooks/useActiveWithFallback.js +12 -1
  238. package/lib/hooks/useContentItems.js +10 -1
  239. package/lib/hooks/useLicense.js +17 -1
  240. package/lib/hooks/usePerformanceMetrics.js +26 -1
  241. package/lib/hooks/useRouter.js +17 -1
  242. package/lib/hooks/useTelemetry.js +5 -1
  243. package/lib/hooks/useTranslate.js +6 -1
  244. package/lib/hooks/useUppercase2LowercaseRedirect.js +12 -1
  245. package/lib/icons/CSharpIcon/CSharpIcon.js +7 -1
  246. package/lib/icons/CSharpIcon/index.js +2 -1
  247. package/lib/icons/CurlIcon/CurlIcon.js +8 -2
  248. package/lib/icons/CurlIcon/index.js +2 -1
  249. package/lib/icons/GOIcon/GOIcon.js +7 -1
  250. package/lib/icons/GOIcon/index.js +2 -1
  251. package/lib/icons/JavaIcon/JavaIcon.js +7 -1
  252. package/lib/icons/JavaIcon/index.js +2 -1
  253. package/lib/icons/JavaScriptIcon/JavaScriptIcon.js +7 -1
  254. package/lib/icons/JavaScriptIcon/index.js +2 -1
  255. package/lib/icons/NodeJSIcon/NodeJSIcon.js +7 -1
  256. package/lib/icons/NodeJSIcon/index.js +2 -1
  257. package/lib/icons/PHPIcon/PHPIcon.js +7 -1
  258. package/lib/icons/PHPIcon/index.js +2 -1
  259. package/lib/icons/PayloadIcon/PayloadIcon.js +7 -1
  260. package/lib/icons/PayloadIcon/index.js +2 -1
  261. package/lib/icons/PythonIcon/PythonIcon.js +7 -1
  262. package/lib/icons/PythonIcon/index.js +2 -1
  263. package/lib/icons/RIcon/RIcon.js +7 -1
  264. package/lib/icons/RIcon/index.js +2 -1
  265. package/lib/icons/RubyIcon/RubyIcon.js +7 -1
  266. package/lib/icons/RubyIcon/index.js +2 -1
  267. package/lib/index.js +49 -1
  268. package/lib/jotai/app.js +113 -1
  269. package/lib/jotai/operation.js +28 -1
  270. package/lib/jotai/replay.js +5 -1
  271. package/lib/jotai/store.js +8 -1
  272. package/lib/jotai/use-write-atom.js +9 -1
  273. package/lib/models/callback.js +28 -1
  274. package/lib/models/code-sample-options.js +2 -0
  275. package/lib/models/example.js +17 -1
  276. package/lib/models/field.js +109 -1
  277. package/lib/models/group.js +38 -1
  278. package/lib/models/index.js +14 -1
  279. package/lib/models/mediaContent.js +26 -1
  280. package/lib/models/mediaType.js +153 -1
  281. package/lib/models/operation.js +166 -1
  282. package/lib/models/request.js +25 -1
  283. package/lib/models/response.js +46 -1
  284. package/lib/models/schema.js +474 -2
  285. package/lib/models/security.js +84 -1
  286. package/lib/models/tab.js +2 -0
  287. package/lib/models/types.js +2 -0
  288. package/lib/services/OpenAPIParser.js +321 -1
  289. package/lib/services/check.js +104 -1
  290. package/lib/services/code-samples/constants.js +16 -1
  291. package/lib/services/code-samples/generator.js +540 -1
  292. package/lib/services/code-samples/httpsnippet/helpers/code-builder.js +252 -3
  293. package/lib/services/code-samples/httpsnippet/helpers/code-helpers.js +90 -2
  294. package/lib/services/code-samples/httpsnippet/helpers/constants.js +28 -1
  295. package/lib/services/code-samples/httpsnippet/helpers/lodash-int.js +173 -1
  296. package/lib/services/code-samples/httpsnippet/helpers/mocks/code-helpers-mock.js +76 -37
  297. package/lib/services/code-samples/httpsnippet/helpers/reducer.js +16 -1
  298. package/lib/services/code-samples/httpsnippet/helpers/shell.js +20 -1
  299. package/lib/services/code-samples/httpsnippet/helpers/string-utility.js +19 -1
  300. package/lib/services/code-samples/httpsnippet/index.js +166 -1
  301. package/lib/services/code-samples/httpsnippet/targets/__mocks__/mock.js +2340 -146
  302. package/lib/services/code-samples/httpsnippet/targets/csharp/httpclient.js +227 -2
  303. package/lib/services/code-samples/httpsnippet/targets/csharp/index.js +11 -1
  304. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/httpclient.js +185 -2
  305. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/index.js +11 -1
  306. package/lib/services/code-samples/httpsnippet/targets/go/index.js +11 -1
  307. package/lib/services/code-samples/httpsnippet/targets/go/native.js +222 -3
  308. package/lib/services/code-samples/httpsnippet/targets/index.js +28 -1
  309. package/lib/services/code-samples/httpsnippet/targets/java/httpclient.js +184 -3
  310. package/lib/services/code-samples/httpsnippet/targets/java/index.js +11 -1
  311. package/lib/services/code-samples/httpsnippet/targets/java8/apachehttp.js +223 -2
  312. package/lib/services/code-samples/httpsnippet/targets/java8/index.js +11 -1
  313. package/lib/services/code-samples/httpsnippet/targets/javascript/fetch.js +147 -1
  314. package/lib/services/code-samples/httpsnippet/targets/javascript/index.js +11 -1
  315. package/lib/services/code-samples/httpsnippet/targets/node/fetch.js +199 -1
  316. package/lib/services/code-samples/httpsnippet/targets/node/index.js +11 -1
  317. package/lib/services/code-samples/httpsnippet/targets/php/curl.js +203 -5
  318. package/lib/services/code-samples/httpsnippet/targets/php/index.js +11 -1
  319. package/lib/services/code-samples/httpsnippet/targets/php/types.js +2 -0
  320. package/lib/services/code-samples/httpsnippet/targets/php/utils.js +106 -5
  321. package/lib/services/code-samples/httpsnippet/targets/python/index.js +11 -1
  322. package/lib/services/code-samples/httpsnippet/targets/python/requests.js +185 -6
  323. package/lib/services/code-samples/httpsnippet/targets/r/httr.js +111 -1
  324. package/lib/services/code-samples/httpsnippet/targets/r/index.js +11 -1
  325. package/lib/services/code-samples/httpsnippet/targets/r/utils.js +18 -6
  326. package/lib/services/code-samples/httpsnippet/targets/ruby/index.js +11 -1
  327. package/lib/services/code-samples/httpsnippet/targets/ruby/native.js +169 -1
  328. package/lib/services/code-samples/httpsnippet/targets/shell/curl.js +94 -6
  329. package/lib/services/code-samples/httpsnippet/targets/shell/index.js +11 -1
  330. package/lib/services/code-samples/index.js +3 -1
  331. package/lib/services/code-samples/types.js +2 -0
  332. package/lib/services/config-options/helpers.js +49 -1
  333. package/lib/services/config-options/index.js +3 -1
  334. package/lib/services/config-options/normalizeOptions.js +83 -1
  335. package/lib/services/config-options/types.js +2 -0
  336. package/lib/services/history/helpers.js +63 -1
  337. package/lib/services/history/index.js +2 -1
  338. package/lib/services/index.js +9 -1
  339. package/lib/services/menu/builder.js +47 -1
  340. package/lib/services/menu/index.js +2 -1
  341. package/lib/services/menu/markdown.js +93 -1
  342. package/lib/services/menu/operation.js +50 -1
  343. package/lib/services/menu/tags.js +166 -1
  344. package/lib/services/types.js +2 -0
  345. package/lib/services/utils.js +83 -1
  346. package/lib/standalone.js +68 -1
  347. package/lib/styled-components.js +6 -1
  348. package/lib/types/app.js +2 -0
  349. package/lib/types/index.js +4 -1
  350. package/lib/types/open-api.js +2 -0
  351. package/lib/types/security.js +2 -0
  352. package/lib/utils/JsonPointer.js +84 -1
  353. package/lib/utils/areArraysEqual.js +4 -1
  354. package/lib/utils/argValuesHelpers.js +35 -1
  355. package/lib/utils/compose.js +2 -1
  356. package/lib/utils/configure-helpers.js +223 -1
  357. package/lib/utils/convertSwagger2OpenAPI.js +14 -1
  358. package/lib/utils/cookies.js +73 -1
  359. package/lib/utils/debounce.js +22 -1
  360. package/lib/utils/debug.js +11 -1
  361. package/lib/utils/dom.js +65 -1
  362. package/lib/utils/environments.js +13 -1
  363. package/lib/utils/helpers.js +222 -12
  364. package/lib/utils/index.js +25 -1
  365. package/lib/utils/isMobile.js +13 -1
  366. package/lib/utils/loadAndBundleSpec.js +32 -1
  367. package/lib/utils/local-storage.js +12 -1
  368. package/lib/utils/object.js +31 -1
  369. package/lib/utils/openapi.js +592 -1
  370. package/lib/utils/parameters.js +13 -1
  371. package/lib/utils/path.js +22 -1
  372. package/lib/utils/queryString.js +60 -1
  373. package/lib/utils/replaceVariables.js +14 -1
  374. package/lib/utils/saveTextBeforeHeading.js +35 -1
  375. package/lib/utils/security-details.js +49 -1
  376. package/lib/utils/session-storage.js +12 -1
  377. package/lib/utils/simplifyAstStructure.js +22 -1
  378. package/lib/utils/sort.js +21 -1
  379. package/lib/utils/string.js +65 -1
  380. package/lib/utils/telemetry.js +7 -1
  381. package/lib/utils/test-utils.js +26 -1
  382. package/lib/utils/theme-helpers.js +24 -3
  383. package/lib/utils/url.js +38 -1
  384. package/package.json +3 -3
@@ -1,2 +1,223 @@
1
- import{CodeBuilder as j}from"../../helpers/code-builder.js";import{HTTPSnippet as d}from"../../index.js";import{isEmptyObject as y,normalizeMimeType as w}from"../../../../utils.js";import{capitalizeFirst as A}from"../../../generator.js";import{Lang as C}from"../../helpers/constants.js";import{buildUrlExpression as v,printUrlVariablesDeclarations as k}from"../../helpers/code-helpers.js";import{MediaTypes as n}from"../../../../../constants.js";const N=function(t,i,{target:h,client:E}){const p=Object.assign({indent:" ",withWrapper:!0},i),e=new j({indentation:p.indent,variablesPrefix:p.variablesPrefix,capitalize:!0,lang:C.JAVA8}),c=b(t.method);if(p.withComments&&x(e),p.withImports&&q(e,t),p.withWrapper&&(e.push("public class App {"),e.push(1,"public static void main(String[] args ) throws java.io.IOException {"),e.push(2,"HttpClient httpClient = HttpClientBuilder.create().build();"),e.blank()),t.securityOAuth2ExtraCalls?.length){const a=new d(t.securityOAuth2ExtraCalls?.[0]).convert(h,E,{...p,withImports:!1,withWrapper:!1,withComments:!1,variablesPrefix:"oauth2"});e.push(a),e.push(2,"JSONObject %s = new JSONObject(EntityUtils.toString(httpClient.execute(%s).getEntity()));","oauth2Response","oauth2Request"),e.push(2,'String accessToken = %s.getString("access_token");',"oauth2Response"),e.blank()}k(t,e,2);const S=v(t,e);e.push(2,`%s ${e.var("request")} = new %s(%s);`,c,c,S);const f=Object.keys(t.allHeaders);if(f.length&&!(t.postData&&t.postData.mimeType==n.MULTIPART)&&f.forEach(a=>{e.push(2,'%s.setHeader("%s", %s);',e.var("request"),a,t.securityOAuth2ExtraCalls?.length?'"Bearer " + accessToken':`"${t.allHeaders[a]}"`)}),t.basicAuth){const{username:a,password:s}=t.basicAuth;e.push(2,`String encodedString = Base64.getEncoder().encodeToString("${a}:${s}".getBytes());`),e.push(2,'%s.setHeader("%s", "%s"+encodedString);',e.var("request"),"Authorization","Basic ")}if(t.postData)switch(w(t.postData.mimeType)){case n.URL_ENCODED:t.postData.params&&(e.blank(),e.push(2,"List<NameValuePair> params = new ArrayList<NameValuePair>();"),t.postData.params.forEach(a=>{e.push(2,'params.add(new BasicNameValuePair("%s", "%s"));',a.name,a.value)}),e.push(2,"%s.setEntity(new UrlEncodedFormEntity(params));",e.var("request")),e.blank());break;case n.MULTIPART:t.postData.params&&(e.push(2,"MultipartEntity reqEntity = new MultipartEntity();"),t.postData.params.forEach(a=>{e.push(2,'reqEntity.addPart("%s", %s);',a.name,O(a.value)?`new StringBody("${a.value}")`:a.value)}),e.push(2,"%s.setEntity(reqEntity);",e.var("request")));break;case n.JSON:if(t.postData.jsonObj){e.push(2,"JSONObject payload = new JSONObject();");for(const[a,s]of Object.entries(t.postData.jsonObj))Array.isArray(s)?(e.push(2,'payload.put("%s", new JSONArray()',a),s.forEach(r=>{l(r)?(e.push(3,".put(new JSONObject()"),o(r,4),e.push(3,")")):e.push(3,".put(%s)",m(r))}),e.push(2,");")):l(s)?(e.push(2,'payload.put("%s", new JSONObject()%s',a,y(s)?");":""),o(s,3),y(s)||e.push(2,");")):e.push(2,'payload.put("%s", %s);',a,m(s));e.push(2,"%s.setEntity(new StringEntity(payload.toString()));",e.var("request"))}break;case n.XML:t.postData.text&&(e.push(2,'String payload = String.join("\\n"'),t.postData.text.trim().split(`
2
- `).forEach(a=>{const s=a.replace(/"/g,'\\"');e.push(3,`"${s}", `)}),e.push(2,");"),e.push(2,"%s.setEntity(new StringEntity(payload));",e.var("request")));break}return p.withWrapper&&(e.push(2,`String ${e.var("response")} = EntityUtils.toString(httpClient.execute(request).getEntity());`),e.blank(),e.push(2,"System.out.println(response);"),e.push(1,"}"),e.push("}")),e.join();function o(a,s){for(const[r,u]of Object.entries(a))l(u)?(e.push(s,'.put("%s", new JSONObject()',r),o(u,s+1),e.push(s,")")):e.push(s,'.put("%s", %s)',r,m(u))}},U={key:"apachehttp",title:"Apache http",link:"https://hc.apache.org/httpcomponents-client-4.5.x/",description:"Apache HttpClient"};var R=N;function x(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 q(t,i){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;"),i.method&&g(t,i.method),i.securityOAuth2ExtraCalls?.length&&i.securityOAuth2ExtraCalls?.[0].method.toLowerCase()!==i.method.toLowerCase()&&g(t,i.securityOAuth2ExtraCalls?.[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;"),i.basicAuth&&t.push("import java.util.Base64;"),t.blank()}function g(t,i){const h=b(i);t.push(`import org.apache.http.client.methods.${h};`)}function b(t){return"Http"+A(t.toLowerCase())}function O(t){return Object.prototype.toString.call(t)==="[object String]"}function l(t){const i=typeof t;return i==="function"||i==="object"&&!!t}function m(t){return O(t)?JSON.stringify(t):t??"JSONObject.NULL"}export{R as default,U as info};
1
+ import { CodeBuilder } from '../../helpers/code-builder.js';
2
+ import { HTTPSnippet } from '../../index.js';
3
+ import { isEmptyObject, normalizeMimeType } from '../../../../utils.js';
4
+ import { capitalizeFirst } from '../../../generator.js';
5
+ import { Lang } from '../../helpers/constants.js';
6
+ import { buildUrlExpression, printUrlVariablesDeclarations } from '../../helpers/code-helpers.js';
7
+ import { MediaTypes } from '../../../../../constants.js';
8
+ const handler = function (source, originalOptions, { target, client }) {
9
+ const options = Object.assign({ indent: ' ', withWrapper: true }, originalOptions);
10
+ const code = new CodeBuilder({
11
+ indentation: options.indent,
12
+ variablesPrefix: options.variablesPrefix,
13
+ capitalize: true,
14
+ lang: Lang.JAVA8,
15
+ });
16
+ const methodFormatted = formatHttpMethod(source.method);
17
+ if (options.withComments) {
18
+ addComments(code);
19
+ }
20
+ if (options.withImports) {
21
+ addImports(code, source);
22
+ }
23
+ if (options.withWrapper) {
24
+ code.push('public class App {');
25
+ code.push(1, 'public static void main(String[] args ) throws java.io.IOException {');
26
+ code.push(2, 'HttpClient httpClient = HttpClientBuilder.create().build();');
27
+ code.blank();
28
+ }
29
+ if (source.securityOAuth2ExtraCalls?.length) {
30
+ const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, {
31
+ ...options,
32
+ withImports: false,
33
+ withWrapper: false,
34
+ withComments: false,
35
+ variablesPrefix: 'oauth2',
36
+ });
37
+ code.push(oAuth2PrefixCode);
38
+ code.push(2, 'JSONObject %s = new JSONObject(EntityUtils.toString(httpClient.execute(%s).getEntity()));', 'oauth2Response', 'oauth2Request');
39
+ code.push(2, 'String accessToken = %s.getString("access_token");', 'oauth2Response');
40
+ code.blank();
41
+ }
42
+ printUrlVariablesDeclarations(source, code, 2);
43
+ const URL = buildUrlExpression(source, code);
44
+ code.push(2, `%s ${code.var('request')} = new %s(%s);`, methodFormatted, methodFormatted, URL);
45
+ const headers = Object.keys(source.allHeaders);
46
+ if (headers.length && !(source.postData && source.postData.mimeType == MediaTypes.MULTIPART)) {
47
+ headers.forEach((key) => {
48
+ code.push(2, '%s.setHeader("%s", %s);', code.var('request'), key, source.securityOAuth2ExtraCalls?.length
49
+ ? '"Bearer " + accessToken'
50
+ : `"${source.allHeaders[key]}"`);
51
+ });
52
+ }
53
+ if (source.basicAuth) {
54
+ const { username, password } = source.basicAuth;
55
+ code.push(2, `String encodedString = Base64.getEncoder().encodeToString("${username}:${password}".getBytes());`);
56
+ code.push(2, '%s.setHeader("%s", "%s"+encodedString);', code.var('request'), 'Authorization', 'Basic ');
57
+ }
58
+ if (source.postData) {
59
+ switch (normalizeMimeType(source.postData.mimeType)) {
60
+ case MediaTypes.URL_ENCODED:
61
+ if (source.postData.params) {
62
+ code.blank();
63
+ code.push(2, 'List<NameValuePair> params = new ArrayList<NameValuePair>();');
64
+ source.postData.params.forEach((param) => {
65
+ code.push(2, 'params.add(new BasicNameValuePair("%s", "%s"));', param.name, param.value);
66
+ });
67
+ code.push(2, '%s.setEntity(new UrlEncodedFormEntity(params));', code.var('request'));
68
+ code.blank();
69
+ }
70
+ break;
71
+ case MediaTypes.MULTIPART:
72
+ if (source.postData.params) {
73
+ code.push(2, 'MultipartEntity reqEntity = new MultipartEntity();');
74
+ source.postData.params.forEach((param) => {
75
+ code.push(2, 'reqEntity.addPart("%s", %s);', param.name, isString(param.value) ? `new StringBody("${param.value}")` : param.value);
76
+ });
77
+ code.push(2, '%s.setEntity(reqEntity);', code.var('request'));
78
+ }
79
+ break;
80
+ case MediaTypes.JSON:
81
+ if (source.postData.jsonObj) {
82
+ code.push(2, 'JSONObject payload = new JSONObject();');
83
+ for (const [key, value] of Object.entries(source.postData.jsonObj)) {
84
+ if (Array.isArray(value)) {
85
+ code.push(2, 'payload.put("%s", new JSONArray()', key);
86
+ value.forEach((item) => {
87
+ if (isObject(item)) {
88
+ code.push(3, '.put(new JSONObject()');
89
+ iterateObject(item, 4);
90
+ code.push(3, ')');
91
+ }
92
+ else {
93
+ code.push(3, '.put(%s)', formatValue(item));
94
+ }
95
+ });
96
+ code.push(2, ');');
97
+ }
98
+ else if (isObject(value)) {
99
+ code.push(2, 'payload.put("%s", new JSONObject()%s', key, isEmptyObject(value) ? ');' : '');
100
+ iterateObject(value, 3);
101
+ if (!isEmptyObject(value)) {
102
+ code.push(2, ');');
103
+ }
104
+ }
105
+ else {
106
+ code.push(2, 'payload.put("%s", %s);', key, formatValue(value));
107
+ }
108
+ }
109
+ code.push(2, '%s.setEntity(new StringEntity(payload.toString()));', code.var('request'));
110
+ }
111
+ break;
112
+ case MediaTypes.XML:
113
+ if (source.postData.text) {
114
+ code.push(2, 'String payload = String.join("\\n"');
115
+ source.postData.text
116
+ .trim()
117
+ .split('\n')
118
+ .forEach((item) => {
119
+ const line = item.replace(/"/g, '\\"');
120
+ code.push(3, `"${line}", `);
121
+ });
122
+ code.push(2, ');');
123
+ code.push(2, '%s.setEntity(new StringEntity(payload));', code.var('request'));
124
+ }
125
+ break;
126
+ }
127
+ }
128
+ // TODO: Add default case to handle unsupported mimeType or data type
129
+ if (options.withWrapper) {
130
+ code.push(2, `String ${code.var('response')} = EntityUtils.toString(httpClient.execute(request).getEntity());`);
131
+ code.blank();
132
+ code.push(2, 'System.out.println(response);');
133
+ code.push(1, '}');
134
+ code.push('}');
135
+ }
136
+ return code.join();
137
+ function iterateObject(obj, indent) {
138
+ for (const [key, value] of Object.entries(obj)) {
139
+ if (isObject(value)) {
140
+ code.push(indent, '.put("%s", new JSONObject()', key);
141
+ iterateObject(value, indent + 1);
142
+ code.push(indent, ')');
143
+ }
144
+ else {
145
+ code.push(indent, '.put("%s", %s)', key, formatValue(value));
146
+ }
147
+ }
148
+ }
149
+ };
150
+ export const info = {
151
+ key: 'apachehttp',
152
+ title: 'Apache http',
153
+ link: 'https://hc.apache.org/httpcomponents-client-4.5.x/',
154
+ description: 'Apache HttpClient',
155
+ };
156
+ export default handler;
157
+ function addComments(code) {
158
+ code.push('/**');
159
+ code.push(' * Requires JDK >= 8');
160
+ code.push(' *');
161
+ code.push(' * Requires Apache HttpComponents Client >= 4.3.5');
162
+ code.push(' * See here for installation details:');
163
+ code.push(' * https://search.maven.org/artifact/org.apache.httpcomponents/httpcomponents-client');
164
+ code.push(' *');
165
+ code.push(' * Requires package "junit4"');
166
+ code.push(' * See here for installation details:');
167
+ code.push(' * https://junit.org/junit4');
168
+ code.push(' *');
169
+ code.push(' * Requires package "org.json" >= 20180130');
170
+ code.push(' * See here for installation details:');
171
+ code.push(' * https://search.maven.org/artifact/org.json/json');
172
+ code.push(' */');
173
+ code.blank();
174
+ }
175
+ function addImports(code, source) {
176
+ code.push('import org.apache.http.util.EntityUtils;');
177
+ code.push('import org.apache.http.NameValuePair;');
178
+ code.push('import org.apache.http.client.HttpClient;');
179
+ code.push('import org.apache.http.client.entity.UrlEncodedFormEntity;');
180
+ if (source.method) {
181
+ addHttpMethodImport(code, source.method);
182
+ }
183
+ if (source.securityOAuth2ExtraCalls?.length &&
184
+ source.securityOAuth2ExtraCalls?.[0].method.toLowerCase() !== source.method.toLowerCase()) {
185
+ addHttpMethodImport(code, source.securityOAuth2ExtraCalls?.[0].method);
186
+ }
187
+ code.push('import org.apache.http.impl.client.HttpClientBuilder;');
188
+ code.push('import org.apache.http.message.BasicNameValuePair;');
189
+ code.push('import org.apache.http.entity.StringEntity;');
190
+ code.push('import org.json.JSONObject;');
191
+ code.push('import org.json.JSONArray;');
192
+ code.push('import java.util.ArrayList;');
193
+ code.push('import java.util.List;');
194
+ code.push('import org.apache.http.entity.mime.MultipartEntity;');
195
+ code.push('import org.apache.http.entity.mime.content.StringBody;');
196
+ if (source.basicAuth) {
197
+ code.push('import java.util.Base64;');
198
+ }
199
+ code.blank();
200
+ }
201
+ function addHttpMethodImport(code, method) {
202
+ const methodFormatted = formatHttpMethod(method);
203
+ code.push(`import org.apache.http.client.methods.${methodFormatted};`);
204
+ }
205
+ function formatHttpMethod(method) {
206
+ return 'Http' + capitalizeFirst(method.toLowerCase());
207
+ }
208
+ function isString(str) {
209
+ return Object.prototype.toString.call(str) === '[object String]';
210
+ }
211
+ function isObject(obj) {
212
+ const type = typeof obj;
213
+ return type === 'function' || (type === 'object' && !!obj);
214
+ }
215
+ function formatValue(value) {
216
+ if (isString(value))
217
+ return JSON.stringify(value);
218
+ else if (value == null)
219
+ return 'JSONObject.NULL';
220
+ else
221
+ return value;
222
+ }
223
+ //# sourceMappingURL=apachehttp.js.map
@@ -1 +1,11 @@
1
- import a from"./apachehttp.js";var e={info:{key:"java8",title:"Java8+Apache",extname:".java",default:"apachehttp"},apachehttp:a};export{e as default};
1
+ import apachehttp from './apachehttp.js';
2
+ export default {
3
+ info: {
4
+ key: 'java8',
5
+ title: 'Java8+Apache',
6
+ extname: '.java',
7
+ default: 'apachehttp',
8
+ },
9
+ apachehttp,
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -1 +1,147 @@
1
- import r from"stringify-object";import{CodeBuilder as v}from"../../helpers/code-builder.js";import{addIndentation as o,getPreserveTransformer as y,buildUrlExpression as O,printUrlVariablesDeclarations as $}from"../../helpers/code-helpers.js";import{normalizeMimeType as p}from"../../../../utils.js";import{HTTPSnippet as g}from"../../index.js";import{Lang as D}from"../../helpers/constants.js";import{MediaTypes as i}from"../../../../../constants.js";const A=function(e,f,{target:m,client:c}){const n={indent:" ",credentials:null,...f},t=new v({indentation:n.indent,variablesPrefix:n.variablesPrefix,capitalize:!0,lang:D.JAVASCRIPT}),a={method:e.method.toUpperCase()};Object.keys(e.headersObj).length&&(a.headers=e.headersObj);let l=!1;if(n.withComments&&j(t),e.securityOAuth2ExtraCalls?.length){const s=new g(e.securityOAuth2ExtraCalls?.[0]).convert(m,c,{...n,withImports:!1,withComments:!1,variablesPrefix:"oAuth2"});t.push(s),t.blank(),a.headers=a.headers||{},a.headers.Authorization="'Bearer ' + oAuth2Data.access_token",l=!0}n.credentials!==null&&(a.credentials=n.credentials);const h=Object.getOwnPropertyNames(e.queryObj).length;if(h&&t.push(`const ${t.var("query")} = new URLSearchParams(${r(e.queryObj,{indent:n.indent,inlineCharacterLimit:25})}).toString();`).blank(),e.postData)switch(p(e.postData.mimeType)){case i.URL_ENCODED:a.body=e.postData.paramsObj?`new URLSearchParams(${t.var("formData")}).toString()`:e.postData.text,e.postData.paramsObj&&t.push(`const ${t.var("formData")} = ${o(r(e.postData.paramsObj,{indent:n.indent,inlineCharacterLimit:25}),{level:0,firstLine:!1})};`).blank();break;case i.JSON:e.postData.jsonObj&&(a.body=`JSON.stringify(${o(r(e.postData.jsonObj,{indent:n.indent,inlineCharacterLimit:25}),{level:1,firstLine:!1})})`);break;case i.MULTIPART:t.push(`const ${t.var("form")} = new FormData();`),delete a?.headers?.["Content-Type"],e.postData.params.forEach(function(s){t.push(`${t.var("form")}.append(%s, %s);`,JSON.stringify(s.name),JSON.stringify(s.value||s.fileName||""))}),a.body=t.var("form"),t.blank();break;default:e.postData.text&&(a.body=`\`${o(e.postData.text,{level:2,indent:n.indent,firstLine:!1}).trim()}\``)}const d=a.headers&&a.headers.Accept&&p(a.headers.Accept)===i.JSON||p(e.postData?.mimeType)===i.JSON;if(e.basicAuth){const{username:s,password:b}=e.basicAuth;a.headers=a.headers||{},a.headers.Authorization=`'Basic ' + btoa('${s}:${b}')`,l=!0}$(e,t);const u=O(e,t);return t.push(`const ${t.var("resp")} = await fetch(`).push(1,"`"+u+(h?"?${"+t.var("query")+"}":"")+"`,").push(o(r(a,{indent:n.indent,inlineCharacterLimit:25,transform:y({body:!0,authorizationHeader:l})}),{level:1,indent:n.indent})).push(");").blank(),e.allResponseCodes?.includes("204")?(t.push("if (resp.status === 204) {").push(1,"console.log('success');").push("} else {"),t.push(1,`const ${t.var("data")} = await ${t.var("resp")}.${d?"json()":"text()"};`).push(1,`console.log(${t.var("data")});`).push("}")):t.push(`const ${t.var("data")} = await ${t.var("resp")}.${d?"json()":"text()"};`).push(`console.log(${t.var("data")});`),t.join()};function j(e){e.push("/**"),e.push(" * Requires ES8-compatible browser: https://caniuse.com/async-functions"),e.push(" */"),e.blank()}const T={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"};var N=A;export{N as default,T as info};
1
+ import stringifyObject from 'stringify-object';
2
+ import { CodeBuilder } from '../../helpers/code-builder.js';
3
+ import { addIndentation, getPreserveTransformer, buildUrlExpression, printUrlVariablesDeclarations, } from '../../helpers/code-helpers.js';
4
+ import { normalizeMimeType } from '../../../../utils.js';
5
+ import { HTTPSnippet } from '../../index.js';
6
+ import { Lang } from '../../helpers/constants.js';
7
+ import { MediaTypes } from '../../../../../constants.js';
8
+ const handler = function (source, originalOptions, { target, client }) {
9
+ const options = {
10
+ indent: ' ',
11
+ credentials: null,
12
+ ...originalOptions,
13
+ };
14
+ const code = new CodeBuilder({
15
+ indentation: options.indent,
16
+ variablesPrefix: options.variablesPrefix,
17
+ capitalize: true,
18
+ lang: Lang.JAVASCRIPT,
19
+ });
20
+ const reqOpts = {
21
+ method: source.method.toUpperCase(),
22
+ };
23
+ // TODO: Should we also add cookies here (like in node.js fetch)?
24
+ if (Object.keys(source.headersObj).length) {
25
+ reqOpts.headers = source.headersObj;
26
+ }
27
+ let preserverOriginalAuthorizationHeader = false;
28
+ if (options.withComments) {
29
+ addComments(code);
30
+ }
31
+ if (source.securityOAuth2ExtraCalls?.length) {
32
+ const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, { ...options, withImports: false, withComments: false, variablesPrefix: 'oAuth2' });
33
+ code.push(oAuth2PrefixCode);
34
+ code.blank();
35
+ reqOpts.headers = reqOpts.headers || {};
36
+ reqOpts.headers.Authorization = `'Bearer ' + oAuth2Data.access_token`;
37
+ preserverOriginalAuthorizationHeader = true;
38
+ }
39
+ if (options.credentials !== null) {
40
+ reqOpts.credentials = options.credentials;
41
+ }
42
+ const hasQueryVariables = Object.getOwnPropertyNames(source.queryObj).length;
43
+ if (hasQueryVariables) {
44
+ code
45
+ .push(`const ${code.var('query')} = new URLSearchParams(${stringifyObject(source.queryObj, {
46
+ indent: options.indent,
47
+ inlineCharacterLimit: 25,
48
+ })}).toString();`)
49
+ .blank();
50
+ }
51
+ if (source.postData) {
52
+ switch (normalizeMimeType(source.postData.mimeType)) {
53
+ case MediaTypes.URL_ENCODED:
54
+ reqOpts.body = source.postData.paramsObj
55
+ ? `new URLSearchParams(${code.var('formData')}).toString()`
56
+ : source.postData.text;
57
+ if (source.postData.paramsObj) {
58
+ code
59
+ .push(`const ${code.var('formData')} = ${addIndentation(stringifyObject(source.postData.paramsObj, {
60
+ indent: options.indent,
61
+ inlineCharacterLimit: 25,
62
+ }), { level: 0, firstLine: false })};`)
63
+ .blank();
64
+ }
65
+ break;
66
+ case MediaTypes.JSON:
67
+ if (source.postData.jsonObj) {
68
+ reqOpts.body = `JSON.stringify(${addIndentation(stringifyObject(source.postData.jsonObj, {
69
+ indent: options.indent,
70
+ inlineCharacterLimit: 25,
71
+ }), { level: 1, firstLine: false })})`;
72
+ }
73
+ break;
74
+ // TODO: handle this mime type corectly!
75
+ case MediaTypes.MULTIPART:
76
+ code.push(`const ${code.var('form')} = new FormData();`);
77
+ // Content type with boundary should be set automatically
78
+ delete reqOpts?.headers?.['Content-Type'];
79
+ source.postData.params.forEach(function (param) {
80
+ code.push(`${code.var('form')}.append(%s, %s);`, JSON.stringify(param.name), JSON.stringify(param.value || param.fileName || ''));
81
+ });
82
+ reqOpts.body = code.var('form');
83
+ code.blank();
84
+ break;
85
+ default:
86
+ if (source.postData.text) {
87
+ reqOpts.body = `\`${addIndentation(source.postData.text, {
88
+ level: 2,
89
+ indent: options.indent,
90
+ firstLine: false,
91
+ }).trim()}\``;
92
+ }
93
+ }
94
+ }
95
+ const isJSON = (reqOpts.headers &&
96
+ reqOpts.headers.Accept &&
97
+ normalizeMimeType(reqOpts.headers.Accept) === MediaTypes.JSON) ||
98
+ normalizeMimeType(source.postData?.mimeType) === MediaTypes.JSON;
99
+ if (source.basicAuth) {
100
+ const { username, password } = source.basicAuth;
101
+ reqOpts.headers = reqOpts.headers || {};
102
+ reqOpts.headers.Authorization = `'Basic ' + btoa('${username}:${password}')`;
103
+ preserverOriginalAuthorizationHeader = true;
104
+ }
105
+ printUrlVariablesDeclarations(source, code);
106
+ const URL = buildUrlExpression(source, code);
107
+ code
108
+ .push(`const ${code.var('resp')} = await fetch(`)
109
+ .push(1, '`' + URL + (hasQueryVariables ? '?${' + code.var('query') + '}' : '') + '`,')
110
+ .push(addIndentation(stringifyObject(reqOpts, {
111
+ indent: options.indent,
112
+ inlineCharacterLimit: 25,
113
+ transform: getPreserveTransformer({
114
+ body: true,
115
+ authorizationHeader: preserverOriginalAuthorizationHeader,
116
+ }),
117
+ }), { level: 1, indent: options.indent }))
118
+ .push(');')
119
+ .blank();
120
+ if (source.allResponseCodes?.includes('204')) {
121
+ code.push(`if (resp.status === 204) {`).push(1, "console.log('success');").push('} else {');
122
+ code
123
+ .push(1, `const ${code.var('data')} = await ${code.var('resp')}.${isJSON ? 'json()' : 'text()'};`)
124
+ .push(1, `console.log(${code.var('data')});`)
125
+ .push('}');
126
+ }
127
+ else {
128
+ code
129
+ .push(`const ${code.var('data')} = await ${code.var('resp')}.${isJSON ? 'json()' : 'text()'};`)
130
+ .push(`console.log(${code.var('data')});`);
131
+ }
132
+ return code.join();
133
+ };
134
+ function addComments(code) {
135
+ code.push('/**');
136
+ code.push(' * Requires ES8-compatible browser: https://caniuse.com/async-functions');
137
+ code.push(' */');
138
+ code.blank();
139
+ }
140
+ export const info = {
141
+ key: 'fetch',
142
+ title: 'fetch',
143
+ link: 'https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch',
144
+ description: 'Perform asynchronous HTTP requests with the Fetch API',
145
+ };
146
+ export default handler;
147
+ //# sourceMappingURL=fetch.js.map
@@ -1 +1,11 @@
1
- import t from"./fetch.js";var a={info:{key:"javascript",title:"JavaScript",extname:".js",default:"fetch"},fetch:t};export{a as default};
1
+ import fetch from './fetch.js';
2
+ export default {
3
+ info: {
4
+ key: 'javascript',
5
+ title: 'JavaScript',
6
+ extname: '.js',
7
+ default: 'fetch',
8
+ },
9
+ fetch,
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -1 +1,199 @@
1
- import h from"stringify-object";import{CodeBuilder as w}from"../../helpers/code-builder.js";import{addIndentation as r,getPreserveTransformer as y,buildUrlExpression as $,printUrlVariablesDeclarations as k}from"../../helpers/code-helpers.js";import{Lang as D}from"../../helpers/constants.js";import{normalizeMimeType as f}from"../../../../utils.js";import{HTTPSnippet as g}from"../../index.js";import{MediaTypes as o}from"../../../../../constants.js";const j=function(t,c,{target:b,client:v}){const n=Object.assign({indent:" ",showBoilerplate:!0,level:1},c),{level:a}=n;let m=!1;const e=new w({indentation:n.indent,variablesPrefix:n.variablesPrefix,capitalize:!0,lang:D.NODEJS});n.withComments&&S(e),n.withImports&&(e.push("import fetch from 'node-fetch';"),e.blank()),n.showBoilerplate&&e.push("async function run() {");const i={method:t.method.toUpperCase()};Object.keys(t.headersObj).length&&(i.headers=t.headersObj);let l=!1;if(t.securityOAuth2ExtraCalls?.length){const s=new g(t.securityOAuth2ExtraCalls?.[0]).convert(b,v,{...n,withImports:!1,withComments:!1,variablesPrefix:"oAuth2",showBoilerplate:!1,level:1});e.push(s),e.blank(),i.headers=i.headers||{},i.headers.Authorization="'Bearer ' + oAuth2Data.access_token",l=!0}const d=Object.getOwnPropertyNames(t.queryObj).length;if(d&&e.push(a,`const ${e.var("query")} = new URLSearchParams(${r(h(t.queryObj,{indent:n.indent,inlineCharacterLimit:25}),{level:a,indent:n.indent,firstLine:!1})}).toString();`).blank(),t.postData)switch(f(t.postData.mimeType)){case o.URL_ENCODED:i.body=t.postData.paramsObj?`new URLSearchParams(${e.var("formData")}).toString()`:t.postData.text,t.postData.paramsObj&&e.push(a,`const ${e.var("formData")} = ${r(h(t.postData.paramsObj,{indent:n.indent,inlineCharacterLimit:25}),{level:a,firstLine:!1})};`).blank();break;case o.JSON:t.postData.jsonObj&&(i.body=`JSON.stringify(${r(h(t.postData.jsonObj,{indent:n.indent,inlineCharacterLimit:25}),{level:a,firstLine:!1})})`);break;case o.MULTIPART:delete i?.headers?.["Content-Type"],n.withImports&&e.unshift("import FormData from 'form-data';"),e.push(a,`const ${e.var("form")} = new FormData();`),t.postData.params.forEach(function(s){if(!s.fileName&&!s.fileName&&!s.contentType){e.push(a,"form.append('"+s.name+"','"+s.value+"');");return}s.fileName&&(m=!0,e.blank(),e.push(a,`${e.var("form")}.append('" + param.name + "', fs.createReadStream('" + param.fileName + "'));`))}),i.body=e.var("form"),e.blank();break;default:t.postData.text&&(i.body=`\`${r(t.postData.text,{level:a+1,indent:n.indent,firstLine:!1}).trim()}\``)}if(t.cookies.length){let s="";t.cookies.forEach(function(p){s=s+encodeURIComponent(p.name)+"="+encodeURIComponent(p.value)+"; "}),s=s.trim(),i.headers||(i.headers={}),i.headers.cookie=s}if(t.basicAuth){const{username:s,password:p}=t.basicAuth;i.headers=i.headers||{},i.headers.Authorization=`'Basic ' + Buffer.from('${s}:${p}').toString('base64')`,l=!0}m&&n.withImports&&e.unshift("import fs from 'fs';");const u=i.headers&&i.headers.Accept&&f(i.headers.Accept)===o.JSON||f(t.postData?.mimeType)===o.JSON;k(t,e,a);const O=$(t,e);return e.push(a,`const ${e.var("resp")} = await fetch(`).push(a+1,"`"+O+(d?"?${"+e.var("query")+"}":"")+"`,").push(a+1,r(h(i,{indent:n.indent,inlineCharacterLimit:25,transform:y({body:!0,authorizationHeader:l})}),{level:a+1,indent:n.indent,firstLine:!1})).push(a,");").blank(),t.allResponseCodes?.includes("204")?(e.push(a,"if (resp.status === 204) {").push(a+1,"console.log('success');").push(a,"} else {"),e.push(a+1,`const ${e.var("data")} = await ${e.var("resp")}.${u?"json()":"text()"};`).push(a+1,`console.log(${e.var("data")});`).push(a,"}")):e.push(a,`const ${e.var("data")} = await ${e.var("resp")}.${u?"json()":"text()"};`).push(a,`console.log(${e.var("data")});`),n.showBoilerplate&&e.push("}").blank().push("run();"),e.join().replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/,'fs.createReadStream("$1")')};function S(t){t.push("/**"),t.push(" * Requires Node.js >= 14"),t.push(" *"),t.push(' * Requires module "node-fetch" >= 2.6.1'),t.push(" * See here for installation details:"),t.push(" * https://www.npmjs.com/package/node-fetch"),t.push(" */"),t.blank()}const P={key:"fetch",title:"Fetch",link:"https://github.com/bitinn/node-fetch",description:"Simplified HTTP node-fetch client"};var U=j;export{U as default,P as info};
1
+ import stringifyObject from 'stringify-object';
2
+ import { CodeBuilder } from '../../helpers/code-builder.js';
3
+ import { addIndentation, getPreserveTransformer, buildUrlExpression, printUrlVariablesDeclarations, } from '../../helpers/code-helpers.js';
4
+ import { Lang } from '../../helpers/constants.js';
5
+ import { normalizeMimeType } from '../../../../utils.js';
6
+ import { HTTPSnippet } from '../../index.js';
7
+ import { MediaTypes } from '../../../../../constants.js';
8
+ const handler = function (source, originalOptions, { target, client }) {
9
+ const options = Object.assign({
10
+ indent: ' ',
11
+ showBoilerplate: true,
12
+ level: 1,
13
+ }, originalOptions);
14
+ const { level } = options;
15
+ let includeFS = false;
16
+ const code = new CodeBuilder({
17
+ indentation: options.indent,
18
+ variablesPrefix: options.variablesPrefix,
19
+ capitalize: true,
20
+ lang: Lang.NODEJS,
21
+ });
22
+ if (options.withComments) {
23
+ addComments(code);
24
+ }
25
+ if (options.withImports) {
26
+ code.push("import fetch from 'node-fetch';");
27
+ code.blank();
28
+ }
29
+ if (options.showBoilerplate) {
30
+ code.push('async function run() {');
31
+ }
32
+ const reqOpts = {
33
+ method: source.method.toUpperCase(),
34
+ };
35
+ if (Object.keys(source.headersObj).length) {
36
+ reqOpts.headers = source.headersObj;
37
+ }
38
+ let preserverOriginalAuthorizationHeader = false;
39
+ if (source.securityOAuth2ExtraCalls?.length) {
40
+ const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, {
41
+ ...options,
42
+ withImports: false,
43
+ withComments: false,
44
+ variablesPrefix: 'oAuth2',
45
+ showBoilerplate: false,
46
+ level: 1,
47
+ });
48
+ code.push(oAuth2PrefixCode);
49
+ code.blank();
50
+ reqOpts.headers = reqOpts.headers || {};
51
+ reqOpts.headers.Authorization = `'Bearer ' + oAuth2Data.access_token`;
52
+ preserverOriginalAuthorizationHeader = true;
53
+ }
54
+ const hasQueryVariables = Object.getOwnPropertyNames(source.queryObj).length;
55
+ if (hasQueryVariables) {
56
+ code
57
+ .push(level, `const ${code.var('query')} = new URLSearchParams(${addIndentation(stringifyObject(source.queryObj, {
58
+ indent: options.indent,
59
+ inlineCharacterLimit: 25,
60
+ }), { level, indent: options.indent, firstLine: false })}).toString();`)
61
+ .blank();
62
+ }
63
+ if (source.postData) {
64
+ switch (normalizeMimeType(source.postData.mimeType)) {
65
+ case MediaTypes.URL_ENCODED:
66
+ reqOpts.body = source.postData.paramsObj
67
+ ? `new URLSearchParams(${code.var('formData')}).toString()`
68
+ : source.postData.text;
69
+ if (source.postData.paramsObj) {
70
+ code
71
+ .push(level, `const ${code.var('formData')} = ${addIndentation(stringifyObject(source.postData.paramsObj, {
72
+ indent: options.indent,
73
+ inlineCharacterLimit: 25,
74
+ }), { level, firstLine: false })};`)
75
+ .blank();
76
+ }
77
+ break;
78
+ case MediaTypes.JSON:
79
+ if (source.postData.jsonObj) {
80
+ reqOpts.body = `JSON.stringify(${addIndentation(stringifyObject(source.postData.jsonObj, {
81
+ indent: options.indent,
82
+ inlineCharacterLimit: 25,
83
+ }), { level, firstLine: false })})`;
84
+ }
85
+ break;
86
+ // TODO: handle this mime type corectly!
87
+ case MediaTypes.MULTIPART:
88
+ // Content type with boundary should be set automatically
89
+ delete reqOpts?.headers?.['Content-Type'];
90
+ if (options.withImports) {
91
+ code.unshift("import FormData from 'form-data';");
92
+ }
93
+ code.push(level, `const ${code.var('form')} = new FormData();`);
94
+ source.postData.params.forEach(function (param) {
95
+ if (!param.fileName && !param.fileName && !param.contentType) {
96
+ code.push(level, "form.append('" + param.name + "','" + param.value + "');");
97
+ return;
98
+ }
99
+ if (param.fileName) {
100
+ includeFS = true;
101
+ code.blank();
102
+ code.push(level, `${code.var('form')}.append('" + param.name + "', fs.createReadStream('" + param.fileName + "'));`);
103
+ }
104
+ });
105
+ reqOpts.body = code.var('form');
106
+ code.blank();
107
+ break;
108
+ default:
109
+ if (source.postData.text) {
110
+ reqOpts.body = `\`${addIndentation(source.postData.text, {
111
+ level: level + 1,
112
+ indent: options.indent,
113
+ firstLine: false,
114
+ }).trim()}\``;
115
+ }
116
+ }
117
+ }
118
+ // construct cookies argument
119
+ if (source.cookies.length) {
120
+ let cookies = '';
121
+ source.cookies.forEach(function (cookie) {
122
+ cookies =
123
+ cookies + encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value) + '; ';
124
+ });
125
+ cookies = cookies.trim();
126
+ if (reqOpts.headers) {
127
+ reqOpts.headers.cookie = cookies;
128
+ }
129
+ else {
130
+ reqOpts.headers = {};
131
+ reqOpts.headers.cookie = cookies;
132
+ }
133
+ }
134
+ if (source.basicAuth) {
135
+ const { username, password } = source.basicAuth;
136
+ reqOpts.headers = reqOpts.headers || {};
137
+ reqOpts.headers.Authorization = `'Basic ' + Buffer.from('${username}:${password}').toString('base64')`;
138
+ preserverOriginalAuthorizationHeader = true;
139
+ }
140
+ if (includeFS && options.withImports) {
141
+ code.unshift("import fs from 'fs';");
142
+ }
143
+ const isJSON = (reqOpts.headers &&
144
+ reqOpts.headers.Accept &&
145
+ normalizeMimeType(reqOpts.headers.Accept) === MediaTypes.JSON) ||
146
+ normalizeMimeType(source.postData?.mimeType) === MediaTypes.JSON;
147
+ printUrlVariablesDeclarations(source, code, level);
148
+ const URL = buildUrlExpression(source, code);
149
+ code
150
+ .push(level, `const ${code.var('resp')} = await fetch(`)
151
+ .push(level + 1, '`' + URL + (hasQueryVariables ? '?${' + code.var('query') + '}' : '') + '`,')
152
+ .push(level + 1, addIndentation(stringifyObject(reqOpts, {
153
+ indent: options.indent,
154
+ inlineCharacterLimit: 25,
155
+ transform: getPreserveTransformer({
156
+ body: true,
157
+ authorizationHeader: preserverOriginalAuthorizationHeader,
158
+ }),
159
+ }), { level: level + 1, indent: options.indent, firstLine: false }))
160
+ .push(level, ');')
161
+ .blank();
162
+ if (source.allResponseCodes?.includes('204')) {
163
+ code
164
+ .push(level, `if (resp.status === 204) {`)
165
+ .push(level + 1, "console.log('success');")
166
+ .push(level, '} else {');
167
+ code
168
+ .push(level + 1, `const ${code.var('data')} = await ${code.var('resp')}.${isJSON ? 'json()' : 'text()'};`)
169
+ .push(level + 1, `console.log(${code.var('data')});`)
170
+ .push(level, '}');
171
+ }
172
+ else {
173
+ code
174
+ .push(level, `const ${code.var('data')} = await ${code.var('resp')}.${isJSON ? 'json()' : 'text()'};`)
175
+ .push(level, `console.log(${code.var('data')});`);
176
+ }
177
+ if (options.showBoilerplate) {
178
+ code.push('}').blank().push('run();');
179
+ }
180
+ return code.join().replace(/"fs\.createReadStream\(\\"(.+)\\"\)"/, 'fs.createReadStream("$1")');
181
+ };
182
+ function addComments(code) {
183
+ code.push('/**');
184
+ code.push(' * Requires Node.js >= 14');
185
+ code.push(' *');
186
+ code.push(' * Requires module "node-fetch" >= 2.6.1');
187
+ code.push(' * See here for installation details:');
188
+ code.push(' * https://www.npmjs.com/package/node-fetch');
189
+ code.push(' */');
190
+ code.blank();
191
+ }
192
+ export const info = {
193
+ key: 'fetch',
194
+ title: 'Fetch',
195
+ link: 'https://github.com/bitinn/node-fetch',
196
+ description: 'Simplified HTTP node-fetch client',
197
+ };
198
+ export default handler;
199
+ //# sourceMappingURL=fetch.js.map
@@ -1 +1,11 @@
1
- import e from"./fetch.js";var f={info:{key:"node",title:"Node.js",extname:".js",default:"fetch"},fetch:e};export{f as default};
1
+ import fetch from './fetch.js';
2
+ export default {
3
+ info: {
4
+ key: 'node',
5
+ title: 'Node.js',
6
+ extname: '.js',
7
+ default: 'fetch',
8
+ },
9
+ fetch,
10
+ };
11
+ //# sourceMappingURL=index.js.map