@redocly/openapi-docs 3.12.0 → 3.12.2

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 +4 -4
@@ -1,3 +1,222 @@
1
- import{CodeBuilder as b}from"../../helpers/code-builder.js";import{HTTPSnippet as q}from"../../index.js";import{Lang as w}from"../../helpers/constants.js";import{buildUrlExpression as $,printUrlVariablesDeclarations as g}from"../../helpers/code-helpers.js";import{normalizeMimeType as m}from"../../../../utils.js";import{MediaTypes as p}from"../../../../../constants.js";const t=1;function l(s={},y){return m(s.mimeType)===y}const D=function(s,y,{target:c,client:d}){const i={capitalize:!0,showBoilerplate:!0,checkErrors:!0,printBody:!0,timeout:-1,indent:" ",...y},f=s.securityOAuth2ExtraCalls?.[0],n=i.checkErrors?"err":"_",h=s.method.toUpperCase(),e=new b({indentation:i.indent,variablesPrefix:i.variablesPrefix,capitalize:i.capitalize,lang:w.GO}),o=()=>{i.checkErrors&&e.push(t,"if err != nil {").push(t+1,"panic(err)").push(t,"}")};if(i.showBoilerplate&&(e.push("package main").blank().push("import (").push(t,'"fmt"'),i.timeout>0&&e.push(t,'"time"'),f&&e.push(t,'"encoding/json"'),l(s.postData,p.MULTIPART)&&(e.push(t,'"mime/multipart"'),e.push(t,'"io"'),e.push(t,'"bytes"')),(l(s.postData,p.URL_ENCODED)||l(s.securityOAuth2ExtraCalls?.[0]?.postData,p.URL_ENCODED))&&(e.push(t,'"net/url"'),e.push(t,'"strconv"')),(l(s.postData,p.JSON)||l(s.securityOAuth2ExtraCalls?.[0]?.postData,p.JSON))&&e.push(t,'"bytes"'),(s.postData&&!l(s.postData,p.JSON)||f)&&e.push(t,'"strings"'),e.push(t,'"net/http"'),i.printBody&&e.push(t,'"io/ioutil"'),e.push(")").blank().push("func main() {")),Object.keys(s.allHeaders).length&&Object.keys(s.allHeaders).forEach(r=>{s.allHeaders[r]=`"${s.allHeaders[r]}"`}),f){const r="oAuth2",a=i.checkErrors?`${n} := `:"",u=i.capitalize?"Res":"res",v=new q(f).convert(c,d,{...i,printBody:!1,variablesPrefix:r,showBoilerplate:!1});e.push(v).blank().push(t,`var ${r}${u}Body struct {`).push(t+1,"Access_token string").push(t,"}").push(t,`${a}json.NewDecoder(${r}${u}.Body).Decode(&${r}${u}Body)`).blank(),o(),s.allHeaders.Authorization=`"Bearer " + ${r}${u}Body.Access_token`}if(g(s,e,t),i.timeout>0&&(d=e.var("client"),e.push(t,"%s := http.Client{",d).push(t+1,"Timeout: time.Duration(%s * time.Second),",i.timeout).push(t,"}").blank()),e.push(t,`${e.var("reqUrl")} := ${$(s,e)}`),s.postData){let r;switch(m(s.postData.mimeType)){case p.URL_ENCODED:e.push(t,"%s := url.Values{}",e.var("data")),s.postData.params.forEach(a=>{e.push(t,'%s.Set("%s", "%s")',e.var("data"),a.name,a.value)}),e.push(t,'%s, %s := http.NewRequest("%s", %s, strings.NewReader(%s.Encode()))',e.var("req"),n,h,e.var("reqUrl"),e.var("data")),s.allHeaders["Content-Length"]=`strconv.Itoa(len(${e.var("data")}.Encode()))`;break;case p.JSON:r=JSON.stringify(s.postData.jsonObj,null,2).split(`
2
- `).map(a=>i.indent+a).join(`
3
- `).trim(),e.push(t,`var ${e.var("data")} = []byte(\`${r}\`)`),e.push(t,'%s, %s := http.NewRequest("%s", %s, bytes.NewBuffer(%s))',e.var("req"),n,h,e.var("reqUrl"),e.var("data"));break;case p.MULTIPART:e.push(t,"%s := &bytes.Buffer{}",e.var("data")).push(t,"writer := multipart.NewWriter(%s)",e.var("data")),s.postData.params.forEach(a=>{if(!a.fileName&&!a.contentType){e.push(t,'%s, _ := writer.CreateFormField("%s")',e.var(`${a.name}Fw`),a.name).push(t,'_, %s = io.Copy(%s, strings.NewReader("%s"))',n,e.var(`${a.name}Fw`),a.value),o();return}a.fileName&&(e.push(t,'%s, %s = writer.CreateFormFile("%s", "%s")',e.var(`${a.name}Fw`),n,a.name,a.fileName),o())}),e.push(t,"writer.Close()").blank().push(t,"%s := bytes.NewReader(%s.Bytes())",e.var("payload"),e.var("data")).push(t,'%s, %s := http.NewRequest("%s", %s, %s)',e.var("req"),n,h,e.var("reqUrl"),e.var("payload")),s.allHeaders["Content-Type"]="writer.FormDataContentType()";break;default:s.postData.text&&e.push(t,"%s := strings.NewReader(%s)",e.var("payload"),JSON.stringify(s.postData?.text)).push(t,'%s, %s := http.NewRequest("%s", %s, %s)',e.var("req"),n,h,e.var("reqUrl"),e.var("payload"))}}else e.push(t,'%s, %s := http.NewRequest("%s", %s, nil)',e.var("req"),n,h,e.var("reqUrl"));if(Object.getOwnPropertyNames(s.queryObj).length){e.blank().push(t,`${e.var("query")} := ${e.var("req")}.URL.Query()`);for(const r in s.queryObj){const a=s.queryObj[r],v=typeof a=="string"&&/^\[.*\]$/.test(a)?`\`${a}\``:`"${a}"`;e.push(t,`${e.var("query")}.Add("${r}", ${v})`)}e.push(t,`${e.var("req")}.URL.RawQuery = ${e.var("query")}.Encode()`).blank()}if(o(),s.basicAuth){const{username:r,password:a}=s.basicAuth;e.push(t,`%s.SetBasicAuth("${r}", "${a}")`,e.var("req"))}return Object.keys(s.allHeaders).length&&Object.keys(s.allHeaders).forEach(r=>{e.push(t,'%s.Header.Add("%s", %s)',e.var("req"),r,s.allHeaders[r])}),e.push(t,"%s, %s := %s.Do(%s)",e.var("res"),n,d,e.var("req")),o(),i.printBody&&(e.push(t,"defer %s.Body.Close()",e.var("res")).push(t,"%s, %s := ioutil.ReadAll(%s.Body)",e.var("body"),n,e.var("res")),o()),e.blank().push(t,"fmt.Println(%s)",e.var("res")),i.printBody&&e.push(t,"fmt.Println(string(%s))",e.var("body")),i.showBoilerplate&&e.push("}"),e.join()},A={key:"native",title:"NewRequest",link:"http://golang.org/pkg/net/http/#NewRequest",description:"Golang HTTP client request"};var T=D;export{T as default,A as info};
1
+ import { CodeBuilder } from '../../helpers/code-builder.js';
2
+ import { HTTPSnippet } from '../../index.js';
3
+ import { Lang } from '../../helpers/constants.js';
4
+ import { buildUrlExpression, printUrlVariablesDeclarations } from '../../helpers/code-helpers.js';
5
+ import { normalizeMimeType } from '../../../../utils.js';
6
+ import { MediaTypes } from '../../../../../constants.js';
7
+ const indent = 1;
8
+ function hasMimeType(postData = {}, mimeType) {
9
+ return normalizeMimeType(postData.mimeType) === mimeType;
10
+ }
11
+ const handler = function (source, originalOptions, { target, client }) {
12
+ const options = {
13
+ capitalize: true,
14
+ showBoilerplate: true,
15
+ checkErrors: true,
16
+ printBody: true,
17
+ timeout: -1,
18
+ indent: ' ',
19
+ ...originalOptions,
20
+ };
21
+ const securityOAuth2ExtraCalls = source.securityOAuth2ExtraCalls?.[0];
22
+ const errorPlaceholder = options.checkErrors ? 'err' : '_';
23
+ const reqMethod = source.method.toUpperCase();
24
+ const code = new CodeBuilder({
25
+ indentation: options.indent,
26
+ variablesPrefix: options.variablesPrefix,
27
+ capitalize: options.capitalize,
28
+ lang: Lang.GO,
29
+ });
30
+ const errorCheck = () => {
31
+ if (options.checkErrors) {
32
+ code
33
+ .push(indent, 'if err != nil {')
34
+ .push(indent + 1, 'panic(err)')
35
+ .push(indent, '}');
36
+ }
37
+ };
38
+ // Create boilerplate
39
+ if (options.showBoilerplate) {
40
+ code.push('package main').blank().push('import (').push(indent, '"fmt"');
41
+ if (options.timeout > 0) {
42
+ code.push(indent, '"time"');
43
+ }
44
+ if (securityOAuth2ExtraCalls) {
45
+ code.push(indent, '"encoding/json"');
46
+ }
47
+ if (hasMimeType(source.postData, MediaTypes.MULTIPART)) {
48
+ code.push(indent, '"mime/multipart"');
49
+ code.push(indent, '"io"');
50
+ code.push(indent, '"bytes"');
51
+ }
52
+ if (hasMimeType(source.postData, MediaTypes.URL_ENCODED) ||
53
+ hasMimeType(source.securityOAuth2ExtraCalls?.[0]?.postData, MediaTypes.URL_ENCODED)) {
54
+ code.push(indent, '"net/url"');
55
+ code.push(indent, '"strconv"');
56
+ }
57
+ if (hasMimeType(source.postData, MediaTypes.JSON) ||
58
+ hasMimeType(source.securityOAuth2ExtraCalls?.[0]?.postData, MediaTypes.JSON)) {
59
+ code.push(indent, '"bytes"');
60
+ }
61
+ if ((source.postData && !hasMimeType(source.postData, MediaTypes.JSON)) ||
62
+ securityOAuth2ExtraCalls) {
63
+ code.push(indent, '"strings"');
64
+ }
65
+ code.push(indent, '"net/http"');
66
+ if (options.printBody) {
67
+ code.push(indent, '"io/ioutil"');
68
+ }
69
+ code.push(')').blank().push('func main() {');
70
+ }
71
+ // put headers values into quotation marks
72
+ if (Object.keys(source.allHeaders).length) {
73
+ Object.keys(source.allHeaders).forEach((key) => {
74
+ source.allHeaders[key] = `"${source.allHeaders[key]}"`;
75
+ });
76
+ }
77
+ if (securityOAuth2ExtraCalls) {
78
+ const prefix = 'oAuth2';
79
+ const decoderErrorString = options.checkErrors ? `${errorPlaceholder} := ` : '';
80
+ const resString = options.capitalize ? 'Res' : 'res';
81
+ const oAuth2PrefixCode = new HTTPSnippet(securityOAuth2ExtraCalls).convert(target, client, {
82
+ ...options,
83
+ printBody: false,
84
+ variablesPrefix: prefix,
85
+ showBoilerplate: false,
86
+ });
87
+ code
88
+ .push(oAuth2PrefixCode)
89
+ .blank()
90
+ .push(indent, `var ${prefix}${resString}Body struct {`)
91
+ .push(indent + 1, 'Access_token string')
92
+ .push(indent, '}')
93
+ .push(indent, `${decoderErrorString}json.NewDecoder(${prefix}${resString}.Body).Decode(&${prefix}${resString}Body)`)
94
+ .blank();
95
+ errorCheck();
96
+ source.allHeaders.Authorization = `"Bearer " + ${prefix}${resString}Body.Access_token`;
97
+ }
98
+ printUrlVariablesDeclarations(source, code, indent);
99
+ // Create client
100
+ if (options.timeout > 0) {
101
+ client = code.var('client');
102
+ code
103
+ .push(indent, '%s := http.Client{', client)
104
+ .push(indent + 1, 'Timeout: time.Duration(%s * time.Second),', options.timeout)
105
+ .push(indent, '}')
106
+ .blank();
107
+ }
108
+ // Set URL
109
+ code.push(indent, `${code.var('reqUrl')} := ${buildUrlExpression(source, code)}`);
110
+ if (source.postData) {
111
+ let stringifiedData;
112
+ switch (normalizeMimeType(source.postData.mimeType)) {
113
+ case MediaTypes.URL_ENCODED:
114
+ code.push(indent, '%s := url.Values{}', code.var('data'));
115
+ source.postData.params.forEach((param) => {
116
+ code.push(indent, '%s.Set("%s", "%s")', code.var('data'), param.name, param.value);
117
+ });
118
+ code.push(indent, '%s, %s := http.NewRequest("%s", %s, strings.NewReader(%s.Encode()))', code.var('req'), errorPlaceholder, reqMethod, code.var('reqUrl'), code.var('data'));
119
+ source.allHeaders['Content-Length'] = `strconv.Itoa(len(${code.var('data')}.Encode()))`;
120
+ break;
121
+ case MediaTypes.JSON:
122
+ /*
123
+ Note about next stringify:
124
+ GO buffers only JSON object with double-quotes for both key and value,
125
+ that is why we are using there JSON.stringify instead of stringify-object package.
126
+ Also to be more readable we add an extra indentation for each stringified code line.
127
+ */
128
+ stringifiedData = JSON.stringify(source.postData.jsonObj, null, 2)
129
+ .split('\n')
130
+ .map((line) => options.indent + line)
131
+ .join('\n')
132
+ .trim(); // remove redundant spaces at the beginning
133
+ code.push(indent, `var ${code.var('data')} = []byte(\`${stringifiedData}\`)`);
134
+ code.push(indent, '%s, %s := http.NewRequest("%s", %s, bytes.NewBuffer(%s))', code.var('req'), errorPlaceholder, reqMethod, code.var('reqUrl'), code.var('data'));
135
+ break;
136
+ case MediaTypes.MULTIPART:
137
+ code
138
+ .push(indent, '%s := &bytes.Buffer{}', code.var('data'))
139
+ .push(indent, 'writer := multipart.NewWriter(%s)', code.var('data'));
140
+ source.postData.params.forEach((param) => {
141
+ if (!param.fileName && !param.contentType) {
142
+ code
143
+ .push(indent, '%s, _ := writer.CreateFormField("%s")', code.var(`${param.name}Fw`), param.name)
144
+ .push(indent, '_, %s = io.Copy(%s, strings.NewReader("%s"))', errorPlaceholder, code.var(`${param.name}Fw`), param.value);
145
+ errorCheck();
146
+ return;
147
+ }
148
+ if (param.fileName) {
149
+ code.push(indent, '%s, %s = writer.CreateFormFile("%s", "%s")', code.var(`${param.name}Fw`), errorPlaceholder, param.name, param.fileName);
150
+ errorCheck();
151
+ }
152
+ });
153
+ code
154
+ .push(indent, 'writer.Close()')
155
+ .blank()
156
+ .push(indent, '%s := bytes.NewReader(%s.Bytes())', code.var('payload'), code.var('data'))
157
+ .push(indent, '%s, %s := http.NewRequest("%s", %s, %s)', code.var('req'), errorPlaceholder, reqMethod, code.var('reqUrl'), code.var('payload'));
158
+ source.allHeaders['Content-Type'] = 'writer.FormDataContentType()';
159
+ break;
160
+ default:
161
+ if (source.postData.text) {
162
+ code
163
+ .push(indent, '%s := strings.NewReader(%s)', code.var('payload'), JSON.stringify(source.postData?.text))
164
+ .push(indent, '%s, %s := http.NewRequest("%s", %s, %s)', code.var('req'), errorPlaceholder, reqMethod, code.var('reqUrl'), code.var('payload'));
165
+ }
166
+ }
167
+ }
168
+ else {
169
+ code.push(indent, '%s, %s := http.NewRequest("%s", %s, nil)', code.var('req'), errorPlaceholder, reqMethod, code.var('reqUrl'));
170
+ }
171
+ // Print query variables if present
172
+ const hasQueryVariables = Object.getOwnPropertyNames(source.queryObj).length;
173
+ if (hasQueryVariables) {
174
+ code.blank().push(indent, `${code.var('query')} := ${code.var('req')}.URL.Query()`);
175
+ for (const name in source.queryObj) {
176
+ const value = source.queryObj[name];
177
+ const isArrayString = typeof value === 'string' && /^\[.*\]$/.test(value);
178
+ const queryValue = isArrayString ? `\`${value}\`` : `"${value}"`;
179
+ code.push(indent, `${code.var('query')}.Add("${name}", ${queryValue})`);
180
+ }
181
+ code.push(indent, `${code.var('req')}.URL.RawQuery = ${code.var('query')}.Encode()`).blank();
182
+ }
183
+ errorCheck();
184
+ if (source.basicAuth) {
185
+ const { username, password } = source.basicAuth;
186
+ code.push(indent, `%s.SetBasicAuth("${username}", "${password}")`, code.var('req'));
187
+ }
188
+ // Add headers
189
+ if (Object.keys(source.allHeaders).length) {
190
+ Object.keys(source.allHeaders).forEach((key) => {
191
+ code.push(indent, '%s.Header.Add("%s", %s)', code.var('req'), key, source.allHeaders[key]);
192
+ });
193
+ }
194
+ // Make request
195
+ code.push(indent, '%s, %s := %s.Do(%s)', code.var('res'), errorPlaceholder, client, code.var('req'));
196
+ errorCheck();
197
+ // Get Body
198
+ if (options.printBody) {
199
+ code
200
+ .push(indent, 'defer %s.Body.Close()', code.var('res'))
201
+ .push(indent, '%s, %s := ioutil.ReadAll(%s.Body)', code.var('body'), errorPlaceholder, code.var('res'));
202
+ errorCheck();
203
+ }
204
+ // Print it
205
+ code.blank().push(indent, 'fmt.Println(%s)', code.var('res'));
206
+ if (options.printBody) {
207
+ code.push(indent, 'fmt.Println(string(%s))', code.var('body'));
208
+ }
209
+ // End main block
210
+ if (options.showBoilerplate) {
211
+ code.push('}');
212
+ }
213
+ return code.join();
214
+ };
215
+ export const info = {
216
+ key: 'native',
217
+ title: 'NewRequest',
218
+ link: 'http://golang.org/pkg/net/http/#NewRequest',
219
+ description: 'Golang HTTP client request',
220
+ };
221
+ export default handler;
222
+ //# sourceMappingURL=native.js.map
@@ -1 +1,28 @@
1
- import o from"./javascript/index.js";import r from"./node/index.js";import m from"./python/index.js";import t from"./shell/index.js";import p from"./java8/index.js";import f from"./java/index.js";import i from"./csharp/index.js";import a from"./csharpNewtonsoft/index.js";import s from"./go/index.js";import e from"./php/index.js";import h from"./ruby/index.js";import c from"./r/index.js";const n={javascript:o,node:r,python:m,shell:t,java8:p,java:f,csharp:i,csharpNewtonsoft:a,go:s,php:e,ruby:h,r:c};var q=n;export{q as default};
1
+ import javascript from './javascript/index.js';
2
+ import node from './node/index.js';
3
+ import python from './python/index.js';
4
+ import shell from './shell/index.js';
5
+ import java8 from './java8/index.js';
6
+ import java from './java/index.js';
7
+ import csharp from './csharp/index.js';
8
+ import csharpNewtonsoft from './csharpNewtonsoft/index.js';
9
+ import go from './go/index.js';
10
+ import php from './php/index.js';
11
+ import ruby from './ruby/index.js';
12
+ import r from './r/index.js';
13
+ const targets = {
14
+ javascript,
15
+ node,
16
+ python,
17
+ shell,
18
+ java8,
19
+ java,
20
+ csharp,
21
+ csharpNewtonsoft,
22
+ go,
23
+ php,
24
+ ruby,
25
+ r,
26
+ };
27
+ export default targets;
28
+ //# sourceMappingURL=index.js.map
@@ -1,3 +1,184 @@
1
- import{CodeBuilder as f}from"../../helpers/code-builder.js";import{HTTPSnippet as b}from"../../index.js";import{normalizeMimeType as l}from"../../../../utils.js";import{addIndentation as y,buildUrlExpression as g,printUrlVariablesDeclarations as v}from"../../helpers/code-helpers.js";import{Lang as j}from"../../helpers/constants.js";import{MediaTypes as i}from"../../../../../constants.js";const r=t=>!!(t.uriObj.query&&Object.keys(t.uriObj.query).length),o=t=>t.postData&&t.postData.mimeType===i.URL_ENCODED?"HttpRequest.BodyPublishers.ofString(form)":t.postData?"HttpRequest.BodyPublishers.ofString(payload)":["POST","PUT","PATCH"].includes(t.method.toUpperCase())?'HttpRequest.BodyPublishers.ofString("some body text")':"",C=function(t,s,{target:u,client:m}){const p=Object.assign({indent:" ",withWrapper:!0},s),a=new f({indentation:p.indent,variablesPrefix:p.variablesPrefix,capitalize:!0,lang:j.JAVA});if(p.withComments&&k(a,t),p.withImports&&c(a,t),p.withWrapper&&(a.push("public class App {"),a.push(1,"public static void main(String[] args) throws Exception {"),a.push(2,"var httpClient = HttpClient.newBuilder().build();"),a.blank()),t.securityOAuth2ExtraCalls?.length){const e=new b(t.securityOAuth2ExtraCalls?.[0]).convert(u,m,{...p,withImports:!1,withWrapper:!1,withComments:!1,variablesPrefix:"oauth2"});a.push(e),a.blank(),a.push(2,"var oauth2Response = httpClient.send(oauth2Request, HttpResponse.BodyHandlers.ofString());"),a.push(2,'var accessToken = new JSONObject(oauth2Response.body()).getString("access_token");'),a.blank()}if(t.postData)switch(l(t.postData.mimeType)){case i.URL_ENCODED:t.postData.params&&(a.push(2,"HashMap<String, String> params = new HashMap<>();"),t.postData.params.forEach(e=>{a.push(2,'params.put("%s", "%s");',e.name,e.value)}),a.blank(),a.push(2,"var form = params.keySet().stream()"),a.push(3,'.map(key -> key + "=" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))'),a.push(3,'.collect(Collectors.joining("&"));'),a.blank());break;case i.JSON:t.postData.jsonObj&&(a.push(2,`var payload = String.join("\\n"
2
- ${y(JSON.stringify(t.postData.jsonObj,null,1).replace(/"/g,'\\"').replace(/^/gm,', "').replace(/$/gm,'"'),{level:3,indent:p.indent,firstLine:!1})}`),a.push(2,");"),a.blank());break;case i.XML:t.postData.text&&(a.push(2,'var payload = String.join("\\n"'),t.postData.text.trim().split(`
3
- `).forEach(e=>{const n=e.replace(/"/g,'\\"');a.push(3,`"${n}", `)}),a.push(2,");"),a.blank());break;case i.MULTIPART:t.postData.params&&(a.push(2,"var multipartBody = MultipartBodyPublisher.newBuilder();"),t.postData.params&&t.postData.params.forEach(e=>{a.push(2,'multipartBody.append("%s", "%s");',e.name,e.value)}),a.push(2,"var body = multipartBody.build();"),a.blank());break}if(r(t)){a.push(2,"HashMap<String, String> params = new HashMap<>();");for(const[e,n]of Object.entries(t.uriObj.query))a.push(2,'params.put("%s", "%s");',e,n);a.blank(),a.push(2,"var query = params.keySet().stream()"),a.push(3,'.map(key -> key + "=" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))'),a.push(3,'.collect(Collectors.joining("&"));'),a.blank()}a.push(2,`var ${a.var("host")} = "%s";`,t.uriObj.protocol+"//"+t.uriObj.host),v(t,a,2);const d={...t,pathname:t.uriObj.pathname};a.push(2,`var ${a.var("pathname")} = %s;`,g(d,a)),a.push(2,`var ${a.var("request")} = HttpRequest.newBuilder()`),t.method.toUpperCase()==="PATCH"?a.push(3,'.method("PATCH", %s)',o(t)):a.push(3,".%s(%s)",t.method.toUpperCase(),o(t)),a.push(3,`.uri(URI.create(${a.var("host")} + ${a.var("pathname")} %s))`,r(t)?"+ '?' + query":""),t.securityOAuth2ExtraCalls?.length&&(t.allHeaders.Authorization='"Bearer " + accessToken');const h=Object.keys(t.allHeaders);if(h.length&&h.forEach(e=>{a.push(3,'.header("%s", %s)',e,e==="Authorization"&&t.securityOAuth2ExtraCalls?.length?t.allHeaders[e]:`"${t.allHeaders[e]}"`)}),t.basicAuth){const{username:e,password:n}=t.basicAuth;a.push(3,`.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(("${e}:${n}").getBytes()))`)}return a.push(3,".build();"),p.withWrapper&&(a.blank(),a.push(2,"var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());"),a.blank(),a.push(2,"System.out.println(response.body());"),a.push(1,"}"),a.push("}")),a.join()},w={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 )"};var R=C;function k(t,s){t.push("/**"),t.push(" * Requires JDK >= 11"),s.securityOAuth2ExtraCalls?.length&&(t.push(" *"),t.push(' * Requires package "org.json" >= 20201115'),t.push(" * See here for installation details:"),t.push(" * https://search.maven.org/artifact/org.json/json")),t.push(" */"),t.blank()}function c(t,s){t.push("import java.net.*;"),t.push("import java.net.http.*;"),t.push("import java.util.*;"),(l(s.postData?.mimeType)===i.URL_ENCODED&&s.postData?.params||s.securityOAuth2ExtraCalls?.length||r(s))&&(t.push("import java.nio.charset.StandardCharsets;"),t.push("import java.util.stream.Collectors;")),s.securityOAuth2ExtraCalls?.length&&t.push("import org.json.JSONObject;"),t.blank()}export{R as default,w as info};
1
+ import { CodeBuilder } from '../../helpers/code-builder.js';
2
+ import { HTTPSnippet } from '../../index.js';
3
+ import { normalizeMimeType } from '../../../../utils.js';
4
+ import { addIndentation, buildUrlExpression, printUrlVariablesDeclarations, } from '../../helpers/code-helpers.js';
5
+ import { Lang } from '../../helpers/constants.js';
6
+ import { MediaTypes } from '../../../../../constants.js';
7
+ const hasQueryParams = (source) => !!(source.uriObj.query && Object.keys(source.uriObj.query).length);
8
+ const getBody = (source) => source.postData && source.postData.mimeType === MediaTypes.URL_ENCODED
9
+ ? 'HttpRequest.BodyPublishers.ofString(form)'
10
+ : source.postData
11
+ ? 'HttpRequest.BodyPublishers.ofString(payload)'
12
+ : ['POST', 'PUT', 'PATCH'].includes(source.method.toUpperCase())
13
+ ? 'HttpRequest.BodyPublishers.ofString("some body text")'
14
+ : '';
15
+ const handler = function (source, originalOptions, { target, client }) {
16
+ const options = Object.assign({ indent: ' ', withWrapper: true }, originalOptions);
17
+ const code = new CodeBuilder({
18
+ indentation: options.indent,
19
+ variablesPrefix: options.variablesPrefix,
20
+ capitalize: true,
21
+ lang: Lang.JAVA,
22
+ });
23
+ if (options.withComments) {
24
+ addComments(code, source);
25
+ }
26
+ if (options.withImports) {
27
+ addImports(code, source);
28
+ }
29
+ if (options.withWrapper) {
30
+ code.push('public class App {');
31
+ code.push(1, 'public static void main(String[] args) throws Exception {');
32
+ code.push(2, 'var httpClient = HttpClient.newBuilder().build();');
33
+ code.blank();
34
+ }
35
+ if (source.securityOAuth2ExtraCalls?.length) {
36
+ const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, {
37
+ ...options,
38
+ withImports: false,
39
+ withWrapper: false,
40
+ withComments: false,
41
+ variablesPrefix: 'oauth2',
42
+ });
43
+ code.push(oAuth2PrefixCode);
44
+ code.blank();
45
+ code.push(2, 'var oauth2Response = httpClient.send(oauth2Request, HttpResponse.BodyHandlers.ofString());');
46
+ code.push(2, 'var accessToken = new JSONObject(oauth2Response.body()).getString("access_token");');
47
+ code.blank();
48
+ }
49
+ if (source.postData) {
50
+ switch (normalizeMimeType(source.postData.mimeType)) {
51
+ case MediaTypes.URL_ENCODED:
52
+ if (source.postData.params) {
53
+ code.push(2, 'HashMap<String, String> params = new HashMap<>();');
54
+ source.postData.params.forEach((param) => {
55
+ code.push(2, 'params.put("%s", "%s");', param.name, param.value);
56
+ });
57
+ code.blank();
58
+ code.push(2, 'var form = params.keySet().stream()');
59
+ code.push(3, '.map(key -> key + "=" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))');
60
+ code.push(3, '.collect(Collectors.joining("&"));');
61
+ code.blank();
62
+ }
63
+ break;
64
+ case MediaTypes.JSON:
65
+ if (source.postData.jsonObj) {
66
+ code.push(2, `var payload = String.join("\\n"
67
+ ${addIndentation(JSON.stringify(source.postData.jsonObj, null, 1)
68
+ .replace(/"/g, '\\"')
69
+ .replace(/^/gm, ', "')
70
+ .replace(/$/gm, '"'), { level: 3, indent: options.indent, firstLine: false })}`);
71
+ code.push(2, ');');
72
+ code.blank();
73
+ }
74
+ break;
75
+ case MediaTypes.XML:
76
+ if (source.postData.text) {
77
+ code.push(2, 'var payload = String.join("\\n"');
78
+ source.postData.text
79
+ .trim()
80
+ .split('\n')
81
+ .forEach((item) => {
82
+ const line = item.replace(/"/g, '\\"');
83
+ code.push(3, `"${line}", `);
84
+ });
85
+ code.push(2, ');');
86
+ code.blank();
87
+ }
88
+ break;
89
+ case MediaTypes.MULTIPART:
90
+ if (source.postData.params) {
91
+ code.push(2, 'var multipartBody = MultipartBodyPublisher.newBuilder();');
92
+ if (source.postData.params) {
93
+ source.postData.params.forEach((param) => {
94
+ code.push(2, 'multipartBody.append("%s", "%s");', param.name, param.value);
95
+ });
96
+ }
97
+ code.push(2, 'var body = multipartBody.build();');
98
+ code.blank();
99
+ }
100
+ break;
101
+ }
102
+ }
103
+ if (hasQueryParams(source)) {
104
+ code.push(2, 'HashMap<String, String> params = new HashMap<>();');
105
+ for (const [key, value] of Object.entries(source.uriObj.query)) {
106
+ code.push(2, 'params.put("%s", "%s");', key, value);
107
+ }
108
+ code.blank();
109
+ code.push(2, 'var query = params.keySet().stream()');
110
+ code.push(3, '.map(key -> key + "=" + URLEncoder.encode(params.get(key), StandardCharsets.UTF_8))');
111
+ code.push(3, '.collect(Collectors.joining("&"));');
112
+ code.blank();
113
+ }
114
+ code.push(2, `var ${code.var('host')} = "%s";`, source.uriObj.protocol + '//' + source.uriObj.host);
115
+ printUrlVariablesDeclarations(source, code, 2);
116
+ const URLSource = { ...source, ...{ pathname: source.uriObj.pathname } };
117
+ code.push(2, `var ${code.var('pathname')} = %s;`, buildUrlExpression(URLSource, code));
118
+ code.push(2, `var ${code.var('request')} = HttpRequest.newBuilder()`);
119
+ if (source.method.toUpperCase() === 'PATCH')
120
+ code.push(3, '.method("PATCH", %s)', getBody(source));
121
+ else
122
+ code.push(3, '.%s(%s)', source.method.toUpperCase(), getBody(source));
123
+ code.push(3, `.uri(URI.create(${code.var('host')} + ${code.var('pathname')} %s))`, hasQueryParams(source) ? "+ '?' + query" : '');
124
+ if (source.securityOAuth2ExtraCalls?.length) {
125
+ source.allHeaders.Authorization = '"Bearer " + accessToken';
126
+ }
127
+ const headers = Object.keys(source.allHeaders);
128
+ if (headers.length) {
129
+ headers.forEach((key) => {
130
+ code.push(3, '.header("%s", %s)', key, key === 'Authorization' && source.securityOAuth2ExtraCalls?.length
131
+ ? source.allHeaders[key] // raw expression, not a string
132
+ : `"${source.allHeaders[key]}"`);
133
+ });
134
+ }
135
+ if (source.basicAuth) {
136
+ const { username, password } = source.basicAuth;
137
+ code.push(3, `.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(("${username}:${password}").getBytes()))`);
138
+ }
139
+ code.push(3, '.build();');
140
+ if (options.withWrapper) {
141
+ code.blank();
142
+ code.push(2, 'var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString());');
143
+ code.blank();
144
+ code.push(2, 'System.out.println(response.body());');
145
+ code.push(1, '}');
146
+ code.push('}');
147
+ }
148
+ return code.join();
149
+ };
150
+ export const info = {
151
+ key: 'httpclient',
152
+ title: 'HttpClient',
153
+ link: 'https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html',
154
+ description: 'HttpClient (Java SE 11 & JDK 11 )',
155
+ };
156
+ export default handler;
157
+ function addComments(code, source) {
158
+ code.push('/**');
159
+ code.push(' * Requires JDK >= 11');
160
+ if (source.securityOAuth2ExtraCalls?.length) {
161
+ code.push(' *');
162
+ code.push(' * Requires package "org.json" >= 20201115');
163
+ code.push(' * See here for installation details:');
164
+ code.push(' * https://search.maven.org/artifact/org.json/json');
165
+ }
166
+ code.push(' */');
167
+ code.blank();
168
+ }
169
+ function addImports(code, source) {
170
+ code.push('import java.net.*;');
171
+ code.push('import java.net.http.*;');
172
+ code.push('import java.util.*;');
173
+ if ((normalizeMimeType(source.postData?.mimeType) === MediaTypes.URL_ENCODED &&
174
+ source.postData?.params) ||
175
+ source.securityOAuth2ExtraCalls?.length ||
176
+ hasQueryParams(source)) {
177
+ code.push('import java.nio.charset.StandardCharsets;');
178
+ code.push('import java.util.stream.Collectors;');
179
+ }
180
+ if (source.securityOAuth2ExtraCalls?.length)
181
+ code.push('import org.json.JSONObject;');
182
+ code.blank();
183
+ }
184
+ //# sourceMappingURL=httpclient.js.map
@@ -1 +1,11 @@
1
- import t from"./httpclient.js";var e={info:{key:"java",title:"Java",extname:".java",default:"httpclient"},httpclient:t};export{e as default};
1
+ import httpclient from './httpclient.js';
2
+ export default {
3
+ info: {
4
+ key: 'java',
5
+ title: 'Java',
6
+ extname: '.java',
7
+ default: 'httpclient',
8
+ },
9
+ httpclient,
10
+ };
11
+ //# sourceMappingURL=index.js.map