@redocly/openapi-docs 3.12.0-rc.7 → 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 (390) hide show
  1. package/dist/redocly-openapi-docs.min.js +2153 -1963
  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 +17 -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.d.ts +1 -4
  51. package/lib/components/OperationItem/Description.js +9 -1
  52. package/lib/components/OperationItem/OperationItem.js +70 -5
  53. package/lib/components/OperationItem/_tests_/OperationItem.test.js +70 -1
  54. package/lib/components/OperationItem/_tests_/__mocks__/mock-intersection-observer.js +40 -1
  55. package/lib/components/OperationItem/index.js +2 -1
  56. package/lib/components/OperationItem/types.js +2 -0
  57. package/lib/components/Overlay.js +48 -3
  58. package/lib/components/Overview/Overview.js +20 -1
  59. package/lib/components/Overview/index.js +2 -1
  60. package/lib/components/PageFooter/PageFooter.js +19 -1
  61. package/lib/components/PageFooter/index.js +2 -1
  62. package/lib/components/Panel/ResponsePanel.js +12 -6
  63. package/lib/components/Panel/Trigger.js +4 -2
  64. package/lib/components/Panel/index.js +3 -1
  65. package/lib/components/PanelItem/PanelItem.js +6 -1
  66. package/lib/components/PanelItem/index.js +3 -1
  67. package/lib/components/PanelItem/styled.js +20 -10
  68. package/lib/components/PayloadSamples/Example.js +6 -1
  69. package/lib/components/PayloadSamples/ExampleValue.js +30 -1
  70. package/lib/components/PayloadSamples/MediaTypeSamples.js +36 -2
  71. package/lib/components/PayloadSamples/PayloadSamples.js +26 -1
  72. package/lib/components/PayloadSamples/index.js +7 -1
  73. package/lib/components/PayloadSamples/styled.js +9 -4
  74. package/lib/components/PayloadSamples/types.js +2 -0
  75. package/lib/components/PropertyDetails/DescriptionEnums.js +19 -3
  76. package/lib/components/PropertyDetails/EnumValues.js +37 -1
  77. package/lib/components/PropertyDetails/Examples.js +26 -1
  78. package/lib/components/PropertyDetails/Extensions.js +17 -2
  79. package/lib/components/PropertyDetails/FieldDetail.js +15 -2
  80. package/lib/components/PropertyDetails/FieldDetails.js +51 -6
  81. package/lib/components/PropertyDetails/Pattern.js +21 -1
  82. package/lib/components/PropertyDetails/PlusCircleIcon.js +10 -4
  83. package/lib/components/PropertyDetails/PropertyDetails.js +22 -5
  84. package/lib/components/PropertyDetails/SchemaTypeInfo.js +10 -2
  85. package/lib/components/PropertyDetails/SimpleEnums.js +13 -2
  86. package/lib/components/PropertyDetails/cycleColorsByLevel.js +18 -1
  87. package/lib/components/PropertyDetails/index.js +4 -1
  88. package/lib/components/PropertyDetails/styled.js +15 -7
  89. package/lib/components/PropertyDetails/types.js +2 -0
  90. package/lib/components/RedoclyOpenAPIDocs/Providers.js +114 -1
  91. package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocs.js +57 -1
  92. package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocsStandalone.js +86 -1
  93. package/lib/components/RedoclyOpenAPIDocs/index.js +5 -1
  94. package/lib/components/RedoclyOpenAPIDocs/styled.js +4 -2
  95. package/lib/components/RedoclyOpenAPIDocs/types.js +2 -0
  96. package/lib/components/RedoclyOpenAPIDocs/utils.js +33 -1
  97. package/lib/components/RenderHook/RenderHook.js +17 -1
  98. package/lib/components/RenderHook/index.js +2 -1
  99. package/lib/components/Replay/EmbeddedReplay.js +41 -3
  100. package/lib/components/Replay/Replay.js +99 -1
  101. package/lib/components/Replay/index.js +3 -1
  102. package/lib/components/Replay/utils.js +208 -1
  103. package/lib/components/Request/RequestDetails.js +33 -2
  104. package/lib/components/Request/types.js +2 -0
  105. package/lib/components/RequestParameters/Body.js +8 -1
  106. package/lib/components/RequestParameters/ParametersGroup.js +19 -4
  107. package/lib/components/RequestParameters/RequestParameters.js +40 -1
  108. package/lib/components/RequestParameters/index.js +4 -1
  109. package/lib/components/RequestSamples/CodeSample.js +55 -2
  110. package/lib/components/RequestSamples/Example.js +37 -1
  111. package/lib/components/RequestSamples/RequestSamples.js +89 -5
  112. package/lib/components/RequestSamples/index.js +3 -1
  113. package/lib/components/RequestSamples/useCodeSamples.js +92 -1
  114. package/lib/components/ResponseSamples/ResponseSamples.js +47 -1
  115. package/lib/components/ResponseSamples/Summary.js +9 -1
  116. package/lib/components/ResponseSamples/index.js +2 -1
  117. package/lib/components/Responses/OperationResponseList.js +42 -2
  118. package/lib/components/Responses/ResponseDetails.js +18 -1
  119. package/lib/components/Responses/ResponseHeaders.js +15 -1
  120. package/lib/components/Responses/index.js +6 -1
  121. package/lib/components/Responses/styled.js +14 -6
  122. package/lib/components/Responses/types.js +2 -0
  123. package/lib/components/RightPanel/RightPanel.js +21 -1
  124. package/lib/components/RightPanel/index.js +2 -1
  125. package/lib/components/Samples/ExampleSwitch.js +33 -1
  126. package/lib/components/Samples/index.js +3 -1
  127. package/lib/components/Samples/use-example-key.js +12 -1
  128. package/lib/components/Schema/ArraySchema.js +45 -1
  129. package/lib/components/Schema/ObjectSchema.js +29 -1
  130. package/lib/components/Schema/OneOfSchema.js +47 -3
  131. package/lib/components/Schema/RecursiveSchema.js +10 -1
  132. package/lib/components/Schema/Schema.js +63 -2
  133. package/lib/components/Schema/SubSchema.js +20 -1
  134. package/lib/components/Schema/helpers.js +16 -1
  135. package/lib/components/Schema/index.js +5 -1
  136. package/lib/components/Schema/types.js +2 -0
  137. package/lib/components/Schema/useOneOfLocationIdx.js +11 -1
  138. package/lib/components/SchemaDefinition/SchemaDefinition.js +65 -2
  139. package/lib/components/SchemaDefinition/index.js +2 -1
  140. package/lib/components/SectionContent/SectionContent.js +49 -6
  141. package/lib/components/SectionContent/index.js +2 -1
  142. package/lib/components/SectionItem/SectionItem.js +14 -1
  143. package/lib/components/SectionItem/index.js +2 -1
  144. package/lib/components/Security/Divider.js +9 -2
  145. package/lib/components/Security/OAuthFlow.js +11 -1
  146. package/lib/components/Security/OAuthScopes.js +59 -9
  147. package/lib/components/Security/Security.js +15 -1
  148. package/lib/components/Security/SecurityButton.js +31 -7
  149. package/lib/components/Security/SecurityFlow.js +28 -4
  150. package/lib/components/Security/SecurityModal.js +34 -5
  151. package/lib/components/Security/SecuritySchemeItem.js +15 -4
  152. package/lib/components/Security/helper.js +16 -1
  153. package/lib/components/Security/index.js +11 -1
  154. package/lib/components/Security/styled.js +6 -3
  155. package/lib/components/SelectOrLabel/SelectOrLabel.js +12 -2
  156. package/lib/components/SelectOrLabel/index.js +2 -1
  157. package/lib/components/ServerList/ServerList.js +36 -10
  158. package/lib/components/ServerList/index.js +2 -1
  159. package/lib/components/ServerList/types.js +2 -0
  160. package/lib/components/ServerListDropdown/ServerListDropdown.js +54 -1
  161. package/lib/components/ServerListDropdown/index.js +2 -1
  162. package/lib/components/ServerListDropdown/styled.js +15 -6
  163. package/lib/components/SideMenu/SideMenu.js +13 -2
  164. package/lib/components/SideMenu/hooks/useMenuItems.js +110 -1
  165. package/lib/components/SideMenu/index.js +2 -1
  166. package/lib/components/SideMenu/types.js +2 -0
  167. package/lib/components/StickySidebar/SidebarActions.js +14 -2
  168. package/lib/components/StickySidebar/StickyResponsiveSidebar.js +37 -7
  169. package/lib/components/StickySidebar/index.js +2 -1
  170. package/lib/components/Tabs/Tabs.js +16 -5
  171. package/lib/components/Tabs/index.js +3 -1
  172. package/lib/components/Tabs/useTabsState.js +22 -1
  173. package/lib/components/TagItem/OperationNavigationItems.js +18 -4
  174. package/lib/components/TagItem/OperationsNavigation.js +46 -2
  175. package/lib/components/TagItem/TagItem.js +41 -8
  176. package/lib/components/TagItem/index.js +2 -1
  177. package/lib/components/TagItem/styled.js +5 -2
  178. package/lib/components/TagItem/types.js +2 -0
  179. package/lib/components/ViewNested/ViewNested.js +42 -9
  180. package/lib/components/ViewNested/index.js +2 -1
  181. package/lib/components/common/Badges.js +21 -5
  182. package/lib/components/common/BodyContent/BodyContent.js +31 -4
  183. package/lib/components/common/BodyContent/index.js +2 -1
  184. package/lib/components/common/ClearButton/ClearButton.js +5 -1
  185. package/lib/components/common/ClearButton/index.js +3 -1
  186. package/lib/components/common/ClearButton/styled.js +5 -2
  187. package/lib/components/common/ClearButton/types.js +2 -0
  188. package/lib/components/common/CodeBlockPanel.js +7 -3
  189. package/lib/components/common/ConstraintsView.js +14 -2
  190. package/lib/components/common/Dropdown/Dropdown.js +22 -4
  191. package/lib/components/common/Dropdown/index.js +2 -1
  192. package/lib/components/common/ExpandableExample/ExpandableExample.js +24 -3
  193. package/lib/components/common/ExpandableExample/index.js +2 -1
  194. package/lib/components/common/Extensions.js +17 -2
  195. package/lib/components/common/Fields/fields-layout.js +76 -51
  196. package/lib/components/common/Fields/fields.js +39 -17
  197. package/lib/components/common/Fields/index.js +3 -1
  198. package/lib/components/common/LinkToField.js +33 -6
  199. package/lib/components/common/OperationItemTitle.d.ts +1 -0
  200. package/lib/components/common/OperationItemTitle.js +16 -5
  201. package/lib/components/common/SchemaSelection/SchemaSelection.js +51 -1
  202. package/lib/components/common/SchemaSelection/index.js +2 -1
  203. package/lib/components/common/Select/Select.js +21 -1
  204. package/lib/components/common/Select/index.js +3 -1
  205. package/lib/components/common/Select/styled.js +17 -9
  206. package/lib/components/common/Select/types.js +2 -0
  207. package/lib/components/common/Skeleton/LanguageListSkeleton.js +16 -6
  208. package/lib/components/common/Skeleton/Skeleton.js +15 -5
  209. package/lib/components/common/Skeleton/index.js +3 -1
  210. package/lib/components/common/headers.js +4 -2
  211. package/lib/components/common/index.js +14 -1
  212. package/lib/components/common/linkify.js +28 -4
  213. package/lib/components/common/mixins.js +4 -2
  214. package/lib/components/common/panels.js +58 -33
  215. package/lib/components/common/schema.js +16 -8
  216. package/lib/components/common/styled.js +15 -7
  217. package/lib/components/index.js +25 -1
  218. package/lib/components/pluggable/RedocExample.js +20 -1
  219. package/lib/components/pluggable/RedocSchema.js +22 -1
  220. package/lib/components/pluggable/index.js +3 -1
  221. package/lib/components/pluggable/styled.components.js +9 -4
  222. package/lib/constants.js +30 -1
  223. package/lib/empty.js +7 -1
  224. package/lib/events/codeSampleCopy.js +19 -1
  225. package/lib/events/creator.js +5 -1
  226. package/lib/events/index.js +8 -1
  227. package/lib/events/languageSwitch.js +18 -1
  228. package/lib/events/panelToggle.js +16 -1
  229. package/lib/events/serverSwitch.js +13 -1
  230. package/lib/events/tryItOpen.js +12 -1
  231. package/lib/events/tryItSent.js +12 -1
  232. package/lib/events/types.js +11 -1
  233. package/lib/hoc/types.js +2 -0
  234. package/lib/hoc/utils.js +4 -1
  235. package/lib/hoc/withRouter.js +17 -1
  236. package/lib/hoc/withStore.js +28 -1
  237. package/lib/hooks/index.js +9 -1
  238. package/lib/hooks/useActivateExample.js +35 -1
  239. package/lib/hooks/useActiveWithFallback.js +12 -1
  240. package/lib/hooks/useContentItems.js +10 -1
  241. package/lib/hooks/useLicense.js +17 -1
  242. package/lib/hooks/usePerformanceMetrics.js +26 -1
  243. package/lib/hooks/useRouter.js +17 -1
  244. package/lib/hooks/useTelemetry.js +5 -1
  245. package/lib/hooks/useTranslate.js +6 -1
  246. package/lib/hooks/useUppercase2LowercaseRedirect.js +12 -1
  247. package/lib/icons/CSharpIcon/CSharpIcon.js +7 -1
  248. package/lib/icons/CSharpIcon/index.js +2 -1
  249. package/lib/icons/CurlIcon/CurlIcon.js +8 -2
  250. package/lib/icons/CurlIcon/index.js +2 -1
  251. package/lib/icons/GOIcon/GOIcon.js +7 -1
  252. package/lib/icons/GOIcon/index.js +2 -1
  253. package/lib/icons/JavaIcon/JavaIcon.js +7 -1
  254. package/lib/icons/JavaIcon/index.js +2 -1
  255. package/lib/icons/JavaScriptIcon/JavaScriptIcon.js +7 -1
  256. package/lib/icons/JavaScriptIcon/index.js +2 -1
  257. package/lib/icons/NodeJSIcon/NodeJSIcon.js +7 -1
  258. package/lib/icons/NodeJSIcon/index.js +2 -1
  259. package/lib/icons/PHPIcon/PHPIcon.js +7 -1
  260. package/lib/icons/PHPIcon/index.js +2 -1
  261. package/lib/icons/PayloadIcon/PayloadIcon.js +7 -1
  262. package/lib/icons/PayloadIcon/index.js +2 -1
  263. package/lib/icons/PythonIcon/PythonIcon.js +7 -1
  264. package/lib/icons/PythonIcon/index.js +2 -1
  265. package/lib/icons/RIcon/RIcon.js +7 -1
  266. package/lib/icons/RIcon/index.js +2 -1
  267. package/lib/icons/RubyIcon/RubyIcon.js +7 -1
  268. package/lib/icons/RubyIcon/index.js +2 -1
  269. package/lib/index.js +49 -1
  270. package/lib/jotai/app.js +113 -1
  271. package/lib/jotai/operation.js +28 -1
  272. package/lib/jotai/replay.js +5 -1
  273. package/lib/jotai/store.js +8 -1
  274. package/lib/jotai/use-write-atom.js +9 -1
  275. package/lib/models/callback.js +28 -1
  276. package/lib/models/code-sample-options.js +2 -0
  277. package/lib/models/example.js +17 -1
  278. package/lib/models/field.js +109 -1
  279. package/lib/models/group.js +38 -1
  280. package/lib/models/index.js +14 -1
  281. package/lib/models/mediaContent.js +26 -1
  282. package/lib/models/mediaType.js +153 -1
  283. package/lib/models/operation.js +166 -1
  284. package/lib/models/request.js +25 -1
  285. package/lib/models/response.js +46 -1
  286. package/lib/models/schema.js +474 -2
  287. package/lib/models/security.js +84 -1
  288. package/lib/models/tab.js +2 -0
  289. package/lib/models/types.js +2 -0
  290. package/lib/services/OpenAPIParser.js +321 -1
  291. package/lib/services/check.js +104 -1
  292. package/lib/services/code-samples/constants.js +16 -1
  293. package/lib/services/code-samples/generator.js +540 -1
  294. package/lib/services/code-samples/httpsnippet/helpers/code-builder.d.ts +5 -1
  295. package/lib/services/code-samples/httpsnippet/helpers/code-builder.js +252 -3
  296. package/lib/services/code-samples/httpsnippet/helpers/code-helpers.d.ts +2 -2
  297. package/lib/services/code-samples/httpsnippet/helpers/code-helpers.js +90 -2
  298. package/lib/services/code-samples/httpsnippet/helpers/constants.js +28 -1
  299. package/lib/services/code-samples/httpsnippet/helpers/lodash-int.js +173 -1
  300. package/lib/services/code-samples/httpsnippet/helpers/mocks/code-helpers-mock.js +76 -37
  301. package/lib/services/code-samples/httpsnippet/helpers/reducer.js +16 -1
  302. package/lib/services/code-samples/httpsnippet/helpers/shell.js +20 -1
  303. package/lib/services/code-samples/httpsnippet/helpers/string-utility.js +19 -1
  304. package/lib/services/code-samples/httpsnippet/index.js +166 -1
  305. package/lib/services/code-samples/httpsnippet/targets/__mocks__/mock.js +2340 -146
  306. package/lib/services/code-samples/httpsnippet/targets/csharp/httpclient.js +227 -2
  307. package/lib/services/code-samples/httpsnippet/targets/csharp/index.js +11 -1
  308. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/httpclient.js +185 -2
  309. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/index.js +11 -1
  310. package/lib/services/code-samples/httpsnippet/targets/go/index.js +11 -1
  311. package/lib/services/code-samples/httpsnippet/targets/go/native.js +222 -3
  312. package/lib/services/code-samples/httpsnippet/targets/index.js +28 -1
  313. package/lib/services/code-samples/httpsnippet/targets/java/httpclient.js +184 -3
  314. package/lib/services/code-samples/httpsnippet/targets/java/index.js +11 -1
  315. package/lib/services/code-samples/httpsnippet/targets/java8/apachehttp.js +223 -2
  316. package/lib/services/code-samples/httpsnippet/targets/java8/index.js +11 -1
  317. package/lib/services/code-samples/httpsnippet/targets/javascript/fetch.js +147 -1
  318. package/lib/services/code-samples/httpsnippet/targets/javascript/index.js +11 -1
  319. package/lib/services/code-samples/httpsnippet/targets/node/fetch.js +199 -1
  320. package/lib/services/code-samples/httpsnippet/targets/node/index.js +11 -1
  321. package/lib/services/code-samples/httpsnippet/targets/php/curl.js +203 -5
  322. package/lib/services/code-samples/httpsnippet/targets/php/index.js +11 -1
  323. package/lib/services/code-samples/httpsnippet/targets/php/types.js +2 -0
  324. package/lib/services/code-samples/httpsnippet/targets/php/utils.js +106 -5
  325. package/lib/services/code-samples/httpsnippet/targets/python/index.js +11 -1
  326. package/lib/services/code-samples/httpsnippet/targets/python/requests.js +185 -6
  327. package/lib/services/code-samples/httpsnippet/targets/r/httr.js +111 -1
  328. package/lib/services/code-samples/httpsnippet/targets/r/index.js +11 -1
  329. package/lib/services/code-samples/httpsnippet/targets/r/utils.js +18 -6
  330. package/lib/services/code-samples/httpsnippet/targets/ruby/index.js +11 -1
  331. package/lib/services/code-samples/httpsnippet/targets/ruby/native.js +169 -1
  332. package/lib/services/code-samples/httpsnippet/targets/shell/curl.js +94 -6
  333. package/lib/services/code-samples/httpsnippet/targets/shell/index.js +11 -1
  334. package/lib/services/code-samples/index.js +3 -1
  335. package/lib/services/code-samples/types.js +2 -0
  336. package/lib/services/config-options/helpers.js +49 -1
  337. package/lib/services/config-options/index.js +3 -1
  338. package/lib/services/config-options/normalizeOptions.js +83 -1
  339. package/lib/services/config-options/types.js +2 -0
  340. package/lib/services/history/helpers.js +63 -1
  341. package/lib/services/history/index.js +2 -1
  342. package/lib/services/index.js +9 -1
  343. package/lib/services/menu/builder.js +47 -1
  344. package/lib/services/menu/index.js +2 -1
  345. package/lib/services/menu/markdown.js +93 -1
  346. package/lib/services/menu/operation.js +50 -1
  347. package/lib/services/menu/tags.js +166 -1
  348. package/lib/services/types.d.ts +0 -3
  349. package/lib/services/types.js +2 -0
  350. package/lib/services/utils.js +83 -1
  351. package/lib/standalone.js +68 -1
  352. package/lib/styled-components.js +6 -1
  353. package/lib/types/app.js +2 -0
  354. package/lib/types/index.js +4 -1
  355. package/lib/types/open-api.d.ts +1 -0
  356. package/lib/types/open-api.js +2 -0
  357. package/lib/types/security.js +2 -0
  358. package/lib/utils/JsonPointer.js +84 -1
  359. package/lib/utils/areArraysEqual.js +4 -1
  360. package/lib/utils/argValuesHelpers.js +35 -1
  361. package/lib/utils/compose.js +2 -1
  362. package/lib/utils/configure-helpers.js +223 -1
  363. package/lib/utils/convertSwagger2OpenAPI.js +14 -1
  364. package/lib/utils/cookies.js +73 -1
  365. package/lib/utils/debounce.js +22 -1
  366. package/lib/utils/debug.js +11 -1
  367. package/lib/utils/dom.js +65 -1
  368. package/lib/utils/environments.js +13 -1
  369. package/lib/utils/helpers.js +222 -12
  370. package/lib/utils/index.js +25 -1
  371. package/lib/utils/isMobile.js +13 -1
  372. package/lib/utils/loadAndBundleSpec.js +32 -1
  373. package/lib/utils/local-storage.js +12 -1
  374. package/lib/utils/object.js +31 -1
  375. package/lib/utils/openapi.js +592 -1
  376. package/lib/utils/parameters.js +13 -1
  377. package/lib/utils/path.js +22 -1
  378. package/lib/utils/queryString.js +60 -1
  379. package/lib/utils/replaceVariables.js +14 -1
  380. package/lib/utils/saveTextBeforeHeading.js +35 -1
  381. package/lib/utils/security-details.js +49 -1
  382. package/lib/utils/session-storage.js +12 -1
  383. package/lib/utils/simplifyAstStructure.js +22 -1
  384. package/lib/utils/sort.js +21 -1
  385. package/lib/utils/string.js +65 -1
  386. package/lib/utils/telemetry.js +7 -1
  387. package/lib/utils/test-utils.js +26 -1
  388. package/lib/utils/theme-helpers.js +24 -3
  389. package/lib/utils/url.js +38 -1
  390. package/package.json +5 -5
@@ -1,5 +1,203 @@
1
- import{format as d}from"util";import{CodeBuilder as O}from"../../helpers/code-builder.js";import{HTTPSnippet as g}from"../../index.js";import{Lang as R}from"../../helpers/constants.js";import{buildUrlExpression as E,printUrlVariablesDeclarations as j}from"../../helpers/code-helpers.js";import{startCase as v}from"../../helpers/lodash-int.js";import{normalizeMimeType as x}from"../../../../utils.js";import{MediaTypes as T}from"../../../../../constants.js";import{objectToPhpArray as _}from"./utils.js";function f(a,p){return p?`$${p}${v(a)}`:`$${a}`}const L=function(a,p,{target:k,client:U}){const t={showBoilerplate:!0,checkErrors:!1,printBody:!0,indent:" ",noTags:!0,shortTags:!1,maxRedirects:10,namedErrors:!1,closingTag:!1,...p};let s,u=!1;const n=new O({indentation:t.indent,capitalize:!0,lang:R.PHP}),m=a.securityOAuth2ExtraCalls?.[0],i=f("curl",t.variablesPrefix),y=f("response",t.variablesPrefix),h=f("error",t.variablesPrefix);if(t.noTags||n.push(t.shortTags?"<?":"<?php").blank(),m){const e="oAuth2",r=new g(m).convert(k,U,{...t,showBoilerplate:!1,variablesPrefix:e});n.push(r),n.blank(),a.allHeaders.Authorization=`Bearer " . ${f("response",e)}.access_token`}const b=Object.keys(a.headersObj).sort().map(function(e){return e==="Authorization"&&m?d('"%s: %s',e,a.allHeaders.Authorization):d('"%s: %s"',e,a.headersObj[e])});if(a.basicAuth){const{username:e,password:r}=a.basicAuth;b.push(`"Authorization: Basic " . base64_encode("${e}:${r}")`)}t.showBoilerplate&&n.push("/**").push(" * Requires libcurl").push(" */").blank(),j(a,n);let o="";if(Object.keys(a.queryObj||{}).length){const e=_(a.queryObj||{},{indent:t.indent});o="$query",n.push(`${o} = ${e};`).blank()}if(n.push(`${i} = curl_init();`),n.blank(),a.postData)switch(x(a.postData.mimeType)){case T.JSON:{const e=_(a.postData.jsonObj||{},{indent:t.indent});u=!0,s="json_encode($payload)",n.push(`$payload = ${e};`).blank();break}case T.MULTIPART:{const e=a.postData.params.map(({name:r,value:$})=>`${t.indent}"${r}" => "${$}",
2
- `).join("");u=!0,s="$payload",n.push(`$payload = array(
3
- ${e});`).blank();break}case T.URL_ENCODED:{const e=a.postData.params.map(({name:r,value:$})=>`${r}=${$}`).join("&");u=!0,s="$payload",n.push(`$payload = "${e}";`).blank();break}default:s=a.postData.text;break}let l=E(a,n);o&&(l.endsWith('"')?l=l.slice(0,-1)+`?" . http_build_query(${o})`:l+=` . "?" . http_build_query(${o})`);const C=[{escape:!u,name:"CURLOPT_POSTFIELDS",value:s},{escape:!0,name:"CURLOPT_PORT",value:a.uriObj.port},{escape:!1,name:"CURLOPT_URL",value:l},{escape:!1,name:"CURLOPT_RETURNTRANSFER",value:"true"},{escape:!0,name:"CURLOPT_CUSTOMREQUEST",value:a.method.toUpperCase()}];n.push(`curl_setopt_array(${i}, [`);const c=new O({indentation:t.indent,lineJoin:`
4
- ${t.indent}`,variablesPrefix:t.variablesPrefix,capitalize:!0,lang:R.PHP});b.length&&c.push("CURLOPT_HTTPHEADER => [").push(1,b.join(`,
5
- `+t.indent+t.indent)).push("],"),C.forEach(function(e){[null,void 0,""].includes(e.value)||c.push(d("%s => %s,",e.name,e.escape?JSON.stringify(e.value):e.value))});const P=a.cookies.map(function(e){return encodeURIComponent(e.name)+"="+encodeURIComponent(e.value)});return P.length&&c.push(d('CURLOPT_COOKIE => "%s",',P.join("; "))),n.push(1,c.join()).push("]);").blank().push(`${y} = curl_exec(${i});`).push(`${h} = curl_error(${i});`).blank().push(`curl_close(${i});`).blank().push(`if (${h}) {`),t.namedErrors?n.push(1,`echo array_flip(get_defined_constants(true)["curl"])[${h}];`):n.push(1,`echo "cURL Error #:" . ${h};`),n.push("} else {").push(1,`echo ${y};`).push("}"),!t.noTags&&t.closingTag&&n.blank().push("?>"),n.join()},V={key:"curl",title:"cURL",link:"http://php.net/manual/en/book.curl.php",description:"PHP with ext-curl"};var I=L;export{I as default,V as info};
1
+ import { format } from 'util';
2
+ import { CodeBuilder } from '../../helpers/code-builder.js';
3
+ import { HTTPSnippet } from '../../index.js';
4
+ import { Lang } from '../../helpers/constants.js';
5
+ import { buildUrlExpression, printUrlVariablesDeclarations } from '../../helpers/code-helpers.js';
6
+ import { startCase } from '../../helpers/lodash-int.js';
7
+ import { normalizeMimeType } from '../../../../utils.js';
8
+ import { MediaTypes } from '../../../../../constants.js';
9
+ import { objectToPhpArray } from './utils.js';
10
+ function getVariableName(name, prefix) {
11
+ return prefix ? `$${prefix}${startCase(name)}` : `$${name}`;
12
+ }
13
+ const handler = function (source, originalOptions, { target, client }) {
14
+ const options = {
15
+ showBoilerplate: true,
16
+ checkErrors: false,
17
+ printBody: true,
18
+ indent: ' ',
19
+ noTags: true,
20
+ shortTags: false,
21
+ maxRedirects: 10,
22
+ namedErrors: false,
23
+ closingTag: false,
24
+ ...originalOptions,
25
+ };
26
+ let postData;
27
+ let isPayloadVariable = false;
28
+ const code = new CodeBuilder({
29
+ indentation: options.indent,
30
+ capitalize: true,
31
+ lang: Lang.PHP,
32
+ });
33
+ const securityOAuth2ExtraCalls = source.securityOAuth2ExtraCalls?.[0];
34
+ const curlVariableName = getVariableName('curl', options.variablesPrefix);
35
+ const responseVariableName = getVariableName('response', options.variablesPrefix);
36
+ const errorVariableName = getVariableName('error', options.variablesPrefix);
37
+ if (!options.noTags) {
38
+ code.push(options.shortTags ? '<?' : '<?php').blank();
39
+ }
40
+ if (securityOAuth2ExtraCalls) {
41
+ const variablesPrefix = 'oAuth2';
42
+ const oAuth2PrefixCode = new HTTPSnippet(securityOAuth2ExtraCalls).convert(target, client, {
43
+ ...options,
44
+ showBoilerplate: false,
45
+ variablesPrefix,
46
+ });
47
+ code.push(oAuth2PrefixCode);
48
+ code.blank();
49
+ source.allHeaders.Authorization = `Bearer " . ${getVariableName('response', variablesPrefix)}.access_token`;
50
+ }
51
+ const headers = Object.keys(source.headersObj)
52
+ .sort()
53
+ .map(function (key) {
54
+ if (key === 'Authorization' && securityOAuth2ExtraCalls) {
55
+ return format('"%s: %s', key, source.allHeaders.Authorization);
56
+ }
57
+ return format('"%s: %s"', key, source.headersObj[key]);
58
+ });
59
+ if (source.basicAuth) {
60
+ const { username, password } = source.basicAuth;
61
+ headers.push(`"Authorization: Basic " . base64_encode("${username}:${password}")`);
62
+ }
63
+ if (options.showBoilerplate) {
64
+ code.push('/**').push(' * Requires libcurl').push(' */').blank();
65
+ }
66
+ printUrlVariablesDeclarations(source, code);
67
+ let queryVariableName = '';
68
+ if (Object.keys(source.queryObj || {}).length) {
69
+ const queryCode = objectToPhpArray(source.queryObj || {}, { indent: options.indent });
70
+ queryVariableName = '$query';
71
+ code.push(`${queryVariableName} = ${queryCode};`).blank();
72
+ }
73
+ code.push(`${curlVariableName} = curl_init();`);
74
+ code.blank();
75
+ if (source.postData) {
76
+ switch (normalizeMimeType(source.postData.mimeType)) {
77
+ case MediaTypes.JSON: {
78
+ const array = objectToPhpArray(source.postData.jsonObj || {}, { indent: options.indent });
79
+ isPayloadVariable = true;
80
+ postData = 'json_encode($payload)';
81
+ code.push(`$payload = ${array};`).blank();
82
+ break;
83
+ }
84
+ case MediaTypes.MULTIPART: {
85
+ const payloadData = source.postData.params
86
+ .map(({ name, value }) => {
87
+ return `${options.indent}"${name}" => "${value}",\n`;
88
+ })
89
+ .join('');
90
+ isPayloadVariable = true;
91
+ postData = '$payload';
92
+ code.push(`$payload = array(\n${payloadData});`).blank();
93
+ break;
94
+ }
95
+ case MediaTypes.URL_ENCODED: {
96
+ const payloadForm = source.postData.params
97
+ .map(({ name, value }) => {
98
+ return `${name}=${value}`;
99
+ })
100
+ .join('&');
101
+ isPayloadVariable = true;
102
+ postData = '$payload';
103
+ code.push(`$payload = "${payloadForm}";`).blank();
104
+ break;
105
+ }
106
+ default:
107
+ postData = source.postData.text;
108
+ break;
109
+ }
110
+ }
111
+ let URL = buildUrlExpression(source, code);
112
+ if (queryVariableName) {
113
+ if (URL.endsWith('"')) {
114
+ //URL ends with string. `"https://httpbin.org/" . "?" . variable` should be `"https://httpbin.org/?" . variable`
115
+ URL = URL.slice(0, -1) + `?" . http_build_query(${queryVariableName})`;
116
+ }
117
+ else {
118
+ //URL ends with variable
119
+ URL += ` . "?" . http_build_query(${queryVariableName})`;
120
+ }
121
+ }
122
+ const curlOptions = [
123
+ {
124
+ escape: !isPayloadVariable,
125
+ name: 'CURLOPT_POSTFIELDS',
126
+ value: postData,
127
+ },
128
+ {
129
+ escape: true,
130
+ name: 'CURLOPT_PORT',
131
+ value: source.uriObj.port,
132
+ },
133
+ {
134
+ escape: false,
135
+ name: 'CURLOPT_URL',
136
+ value: URL,
137
+ },
138
+ {
139
+ escape: false,
140
+ name: 'CURLOPT_RETURNTRANSFER',
141
+ value: 'true',
142
+ },
143
+ {
144
+ escape: true,
145
+ name: 'CURLOPT_CUSTOMREQUEST',
146
+ value: source.method.toUpperCase(),
147
+ },
148
+ ];
149
+ code.push(`curl_setopt_array(${curlVariableName}, [`);
150
+ const curlopts = new CodeBuilder({
151
+ indentation: options.indent,
152
+ lineJoin: `\n${options.indent}`,
153
+ variablesPrefix: options.variablesPrefix,
154
+ capitalize: true,
155
+ lang: Lang.PHP,
156
+ });
157
+ if (headers.length) {
158
+ curlopts
159
+ .push('CURLOPT_HTTPHEADER => [')
160
+ .push(1, headers.join(',\n' + options.indent + options.indent))
161
+ .push('],');
162
+ }
163
+ curlOptions.forEach(function (option) {
164
+ if (![null, undefined, ''].includes(option.value)) {
165
+ curlopts.push(format('%s => %s,', option.name, option.escape ? JSON.stringify(option.value) : option.value));
166
+ }
167
+ });
168
+ const cookies = source.cookies.map(function (cookie) {
169
+ return encodeURIComponent(cookie.name) + '=' + encodeURIComponent(cookie.value);
170
+ });
171
+ if (cookies.length) {
172
+ curlopts.push(format('CURLOPT_COOKIE => "%s",', cookies.join('; ')));
173
+ }
174
+ code
175
+ .push(1, curlopts.join())
176
+ .push(']);')
177
+ .blank()
178
+ .push(`${responseVariableName} = curl_exec(${curlVariableName});`)
179
+ .push(`${errorVariableName} = curl_error(${curlVariableName});`)
180
+ .blank()
181
+ .push(`curl_close(${curlVariableName});`)
182
+ .blank()
183
+ .push(`if (${errorVariableName}) {`);
184
+ if (options.namedErrors) {
185
+ code.push(1, `echo array_flip(get_defined_constants(true)["curl"])[${errorVariableName}];`);
186
+ }
187
+ else {
188
+ code.push(1, `echo "cURL Error #:" . ${errorVariableName};`);
189
+ }
190
+ code.push('} else {').push(1, `echo ${responseVariableName};`).push('}');
191
+ if (!options.noTags && options.closingTag) {
192
+ code.blank().push('?>');
193
+ }
194
+ return code.join();
195
+ };
196
+ export const info = {
197
+ key: 'curl',
198
+ title: 'cURL',
199
+ link: 'http://php.net/manual/en/book.curl.php',
200
+ description: 'PHP with ext-curl',
201
+ };
202
+ export default handler;
203
+ //# sourceMappingURL=curl.js.map
@@ -1 +1,11 @@
1
- import e from"./curl.js";var p={info:{key:"php",title:"PHP",extname:".php",default:"curl"},curl:e};export{p as default};
1
+ import curl from './curl.js';
2
+ export default {
3
+ info: {
4
+ key: 'php',
5
+ title: 'PHP',
6
+ extname: '.php',
7
+ default: 'curl',
8
+ },
9
+ curl,
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -1,5 +1,106 @@
1
- const h=["number","boolean","function","symbol"];function x(c){return Object.prototype.toString.call(c)==="[object RegExp]"}function j(c){const s=typeof c;return c!==null&&(s==="object"||s==="function")}function O(c,s,b=""){const i=[];return function y(e,r={},f=""){r.indent=r.indent||" ";const n={newLine:`
2
- `,newLineOrSpace:`
3
- `,pad:f,indent:f+r.indent},w=t=>{if(r.inlineCharacterLimit===void 0)return t;const l=t.replace(new RegExp(n.newLine,"g"),"").replace(new RegExp(n.newLineOrSpace,"g")," ").replace(new RegExp(n.pad+"|"+n.indent,"g"),"");return l.length<=r.inlineCharacterLimit?l:t.replace(new RegExp(n.newLine+"|"+n.newLineOrSpace,"g"),`
4
- `).replace(new RegExp(n.pad,"g"),f).replace(new RegExp(n.indent,"g"),f+r.indent)};if(i.indexOf(e)!==-1)return'"Circular"';if(e===null)return"NULL";if(e===void 0||h.includes(typeof e)||x(e))return String(e);if(e instanceof Date)return`date('${e.toISOString()}')`;if(Array.isArray(e)){if(e.length===0)return"array()";i.push(e);const t="array("+n.newLine+e.map((l,a)=>{const d=e.length-1===a?n.newLine:","+n.newLineOrSpace;let g=y(l,r,f+r.indent);return r.transform&&(g=r.transform(e,a,g)),n.indent+g+d}).join("")+n.pad+")";return i.pop(),w(t)}if(j(e)){let t=Object.keys(e);if(r.filter&&(t=t.filter(a=>r.filter?.(e,a))),t.length===0)return Array.isArray(e)?"array()":"(object)[]";i.push(e);const l="array("+n.newLine+t.map((a,d)=>{const g=t.length-1===d?n.newLine:","+n.newLineOrSpace,L=typeof a=="symbol",m=!L&&/^[a-z$_][a-z$_0-9]*$/i.test(a),S=L||m?a:y(a,r);let o=y(e[a],r,f+r.indent);return r.transform&&(o=r.transform(e,a,o)),`${n.indent}"${String(S)}" => ${o}${g}`}).join("")+n.pad+")";return i.pop(),w(l)}return e=String(e).replace(/[\r\n]/g,t=>t===`
5
- `?"\\n":"\\r"),r.singleQuotes===!1?(e=e.replace(/"/g,'\\"'),`"${e}"`):(e=e.replace(/\\?'/g,"\\'"),`"${e}"`)}(c,s,b)}export{O as objectToPhpArray};
1
+ const simpleTypes = ['number', 'boolean', 'function', 'symbol'];
2
+ function isRegexp(value) {
3
+ return Object.prototype.toString.call(value) === '[object RegExp]';
4
+ }
5
+ function isObject(value) {
6
+ const type = typeof value;
7
+ return value !== null && (type === 'object' || type === 'function');
8
+ }
9
+ export function objectToPhpArray(input, options, pad = '') {
10
+ const seen = [];
11
+ return (function stringify(input, options = {}, pad = '') {
12
+ options.indent = options.indent || '\t';
13
+ const tokens = {
14
+ newLine: '\n',
15
+ newLineOrSpace: '\n',
16
+ pad,
17
+ indent: pad + options.indent,
18
+ };
19
+ const expandWhiteSpace = (string) => {
20
+ if (options.inlineCharacterLimit === undefined) {
21
+ return string;
22
+ }
23
+ const oneLined = string
24
+ .replace(new RegExp(tokens.newLine, 'g'), '')
25
+ .replace(new RegExp(tokens.newLineOrSpace, 'g'), ' ')
26
+ .replace(new RegExp(tokens.pad + '|' + tokens.indent, 'g'), '');
27
+ if (oneLined.length <= options.inlineCharacterLimit) {
28
+ return oneLined;
29
+ }
30
+ return string
31
+ .replace(new RegExp(tokens.newLine + '|' + tokens.newLineOrSpace, 'g'), '\n')
32
+ .replace(new RegExp(tokens.pad, 'g'), pad)
33
+ .replace(new RegExp(tokens.indent, 'g'), pad + options.indent);
34
+ };
35
+ if (seen.indexOf(input) !== -1) {
36
+ return '"Circular"';
37
+ }
38
+ if (input === null)
39
+ return 'NULL';
40
+ if (input === undefined || simpleTypes.includes(typeof input) || isRegexp(input)) {
41
+ return String(input);
42
+ }
43
+ if (input instanceof Date) {
44
+ return `date('${input.toISOString()}')`;
45
+ }
46
+ if (Array.isArray(input)) {
47
+ if (input.length === 0) {
48
+ return 'array()';
49
+ }
50
+ seen.push(input);
51
+ const ret = 'array(' +
52
+ tokens.newLine +
53
+ input
54
+ .map((el, i) => {
55
+ const eol = input.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace;
56
+ let value = stringify(el, options, pad + options.indent);
57
+ if (options.transform) {
58
+ value = options.transform(input, i, value);
59
+ }
60
+ return tokens.indent + value + eol;
61
+ })
62
+ .join('') +
63
+ tokens.pad +
64
+ ')';
65
+ seen.pop();
66
+ return expandWhiteSpace(ret);
67
+ }
68
+ if (isObject(input)) {
69
+ let objKeys = Object.keys(input);
70
+ if (options.filter) {
71
+ objKeys = objKeys.filter((el) => options.filter?.(input, el));
72
+ }
73
+ if (objKeys.length === 0) {
74
+ return Array.isArray(input) ? `array()` : `(object)[]`;
75
+ }
76
+ seen.push(input);
77
+ const ret = 'array(' +
78
+ tokens.newLine +
79
+ objKeys
80
+ .map((el, i) => {
81
+ const eol = objKeys.length - 1 === i ? tokens.newLine : ',' + tokens.newLineOrSpace;
82
+ const isSymbol = typeof el === 'symbol';
83
+ const isClassic = !isSymbol && /^[a-z$_][a-z$_0-9]*$/i.test(el);
84
+ const key = isSymbol || isClassic ? el : stringify(el, options);
85
+ let value = stringify(input[el], options, pad + options.indent);
86
+ if (options.transform) {
87
+ value = options.transform(input, el, value);
88
+ }
89
+ return `${tokens.indent}"${String(key)}" => ${value}${eol}`;
90
+ })
91
+ .join('') +
92
+ tokens.pad +
93
+ ')';
94
+ seen.pop();
95
+ return expandWhiteSpace(ret);
96
+ }
97
+ input = String(input).replace(/[\r\n]/g, (x) => (x === '\n' ? '\\n' : '\\r'));
98
+ if (options.singleQuotes === false) {
99
+ input = input.replace(/"/g, '\\"');
100
+ return `"${input}"`;
101
+ }
102
+ input = input.replace(/\\?'/g, "\\'");
103
+ return `"${input}"`;
104
+ })(input, options, pad);
105
+ }
106
+ //# sourceMappingURL=utils.js.map
@@ -1 +1,11 @@
1
- import t from"./requests.js";var o={info:{key:"python",title:"Python",extname:".py",default:"python3"},requests:t};export{o as default};
1
+ import requests from './requests.js';
2
+ export default {
3
+ info: {
4
+ key: 'python',
5
+ title: 'Python',
6
+ extname: '.py',
7
+ default: 'python3',
8
+ },
9
+ requests,
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -1,6 +1,185 @@
1
- import{format as v}from"util";import{CodeBuilder as j}from"../../helpers/code-builder.js";import{normalizeMimeType as k}from"../../../../utils.js";import{addIndentation as L,buildUrlExpression as c,printUrlVariablesDeclarations as T}from"../../helpers/code-helpers.js";import{HTTPSnippet as g}from"../../index.js";import{Lang as q}from"../../helpers/constants.js";import{MediaTypes as l}from"../../../../../constants.js";const x=function(t,u,{target:_,client:d}){const a=Object.assign({indent:" "},u),{level:m=0}=a,e=new j({indentation:a.indent,variablesPrefix:a.variablesPrefix,lang:q.PYTHON});a.withComments&&A(e),a.withImports&&e.push("import requests").blank();let y=!1,n=t.allHeaders;if(t.securityOAuth2ExtraCalls?.length){const s=new g(t.securityOAuth2ExtraCalls?.[0]).convert(_,d,{...a,withImports:!1,withComments:!1,variablesPrefix:"oauth2_"});e.push(s),e.blank(),n=n||{},n.Authorization='"Bearer " + oauth2_data["access_token"]',y=!0}T(t,e),e.push(`${e.var("url").toLowerCase()} = %s`,c(t,e)).blank();let b;Object.keys(t.queryObj||{}).length&&(b="query = "+w(t.queryObj,a.indent),e.push(b).blank());let o,f;const $=k(t.postData?.mimeType);if(t.postData)switch($){case l.URL_ENCODED:o=t.postData.paramsObj?`${L(w(t.postData.paramsObj,a.indent),{level:0,firstLine:!1})}`:t.postData.text;break;case l.JSON:t.postData.jsonObj&&(o=L(w(t.postData.jsonObj,a.indent),{level:0,firstLine:!1}));break;case l.MULTIPART:const s=[];if(t.postData.params)for(const p of t.postData.params)s.push(`"${p.name}": "${p.value}"`);s.length&&(f=`data = {
2
- ${s.map(O=>` ${O}`).join(`,
3
- `)}
4
- }`),f&&e.push(f).blank();break;default:t.postData.text&&(o=`'''
5
- ${L(t.postData.text.trim(),{level:1,indent:a.indent,firstLine:!0})}
6
- '''`)}o&&e.push(`${e.var("payload").toLowerCase()} = %s`,o).blank();let r;const h=Object.keys(n).length,C=(s,p)=>s==="Authorization"&&y?p:`"${p}"`;if(h===1)for(r in n)e.push(`${e.var("headers").toLowerCase()} = {"${r}": ${C(r,n[r])}}`).blank();else if(h>1){let s=1;e.push(`${e.var("headers").toLowerCase()} = {`);for(r in n)s++!==h?e.push(1,`"${r}": ${C(r,n[r])},`):e.push(1,`"${r}": ${C(r,n[r])}`);e.push(0,"}").blank()}const D=t.method.toLowerCase();let i=v(`${e.var("response").toLowerCase()} = requests.${D}(${e.var("url").toLowerCase()}`);if($===l.MULTIPART&&f&&(i+=", data=data"),o){const s=$===l.JSON?"json":"data";i+=`, ${s}=${e.var("payload").toLowerCase()}`}return h>0&&(i+=`, headers=${e.var("headers").toLowerCase()}`),b&&(i+=`, params=${e.var("query").toLowerCase()}`),t.basicAuth&&(i+=`, auth=('${t.basicAuth.username}','${t.basicAuth.password}')`),i+=")",e.push(i).blank(),t.allResponseCodes?.includes("204")?e.push("if response.status_code == 204:").push(m+1,'print("success")').push("else:").push(m+1,`${e.var("data").toLowerCase()} = ${e.var("response").toLowerCase()}.json()`).push(m+1,`print(${e.var("data").toLowerCase()})`):e.push(`${e.var("data").toLowerCase()} = ${e.var("response").toLowerCase()}.json()`).push(`print(${e.var("data").toLowerCase()})`),e.join()};var I=x;function A(t){t.push('"""'),t.push("Requires python >= 3"),t.blank(),t.push('Requires module "requests" >= 2.25.1'),t.push("See here for installation details:"),t.push(" https://requests.readthedocs.io/"),t.push('"""'),t.blank()}function w(t,u){return JSON.stringify(t,function(d,a){return d&&typeof a=="boolean"?a?"__REDOCLY_<True>__":"__REDOCLY_<False>__":a===null?"__REDOCLY_<None>__":a},u).replace(/"__REDOCLY_<(\w+)>__"/g,"$1")}export{I as default};
1
+ import { format } from 'util';
2
+ import { CodeBuilder } from '../../helpers/code-builder.js';
3
+ import { normalizeMimeType } from '../../../../utils.js';
4
+ import { addIndentation, buildUrlExpression, printUrlVariablesDeclarations, } from '../../helpers/code-helpers.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 = Object.assign({ indent: ' ' }, originalOptions);
10
+ const { level = 0 } = options;
11
+ const code = new CodeBuilder({
12
+ indentation: options.indent,
13
+ variablesPrefix: options.variablesPrefix,
14
+ lang: Lang.PYTHON,
15
+ });
16
+ if (options.withComments) {
17
+ addComments(code);
18
+ }
19
+ if (options.withImports) {
20
+ code.push('import requests').blank();
21
+ }
22
+ let preserverOriginalAuthorizationHeader = false;
23
+ let headers = source.allHeaders;
24
+ if (source.securityOAuth2ExtraCalls?.length) {
25
+ const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, { ...options, withImports: false, withComments: false, variablesPrefix: 'oauth2_' });
26
+ code.push(oAuth2PrefixCode);
27
+ code.blank();
28
+ headers = headers || {};
29
+ headers.Authorization = `"Bearer " + oauth2_data["access_token"]`;
30
+ preserverOriginalAuthorizationHeader = true;
31
+ }
32
+ printUrlVariablesDeclarations(source, code);
33
+ // Set URL
34
+ code.push(`${code.var('url').toLowerCase()} = %s`, buildUrlExpression(source, code)).blank();
35
+ let qs;
36
+ // Construct query string
37
+ if (Object.keys(source.queryObj || {}).length) {
38
+ const stringifiedQuery = jsObjectToPythonDict(source.queryObj, options.indent);
39
+ qs = 'query = ' + stringifiedQuery; // TODO: handle inlineCharacterLimit: 25 as for stringifyQueryString
40
+ code.push(qs).blank();
41
+ }
42
+ // Construct payload
43
+ let payload;
44
+ let dataStr;
45
+ const normalizedMimeType = normalizeMimeType(source.postData?.mimeType);
46
+ if (source.postData) {
47
+ switch (normalizedMimeType) {
48
+ case MediaTypes.URL_ENCODED:
49
+ payload = source.postData.paramsObj
50
+ ? `${addIndentation(jsObjectToPythonDict(source.postData.paramsObj, options.indent), {
51
+ level: 0,
52
+ firstLine: false,
53
+ })}`
54
+ : source.postData.text;
55
+ break;
56
+ case MediaTypes.JSON:
57
+ if (source.postData.jsonObj) {
58
+ payload = addIndentation(jsObjectToPythonDict(source.postData.jsonObj, options.indent), {
59
+ level: 0,
60
+ firstLine: false,
61
+ });
62
+ }
63
+ break;
64
+ case MediaTypes.MULTIPART:
65
+ const multipartData = [];
66
+ if (source.postData.params) {
67
+ for (const param of source.postData.params) {
68
+ multipartData.push(`"${param.name}": "${param.value}"`);
69
+ }
70
+ }
71
+ if (multipartData.length) {
72
+ const formattedData = multipartData.map((entry) => ` ${entry}`).join(',\n');
73
+ dataStr = `data = {\n${formattedData}\n}`;
74
+ }
75
+ if (dataStr) {
76
+ code.push(dataStr).blank();
77
+ }
78
+ break;
79
+ default:
80
+ if (source.postData.text) {
81
+ payload = `'''\n${addIndentation(source.postData.text.trim(), {
82
+ level: 1,
83
+ indent: options.indent,
84
+ firstLine: true,
85
+ })}\n'''`;
86
+ }
87
+ }
88
+ }
89
+ if (payload) {
90
+ code.push(`${code.var('payload').toLowerCase()} = %s`, payload).blank();
91
+ }
92
+ // Construct headers
93
+ let header;
94
+ const headerCount = Object.keys(headers).length;
95
+ const formatHeader = (header, value) => {
96
+ if (header === 'Authorization' && preserverOriginalAuthorizationHeader) {
97
+ return value;
98
+ }
99
+ return `"${value}"`;
100
+ };
101
+ if (headerCount === 1) {
102
+ for (header in headers) {
103
+ // code.push('headers = { "%s": "%s" }', header, headers[header]).blank();
104
+ code
105
+ .push(`${code.var('headers').toLowerCase()} = {"${header}": ${formatHeader(header, headers[header])}}`)
106
+ .blank();
107
+ }
108
+ }
109
+ else if (headerCount > 1) {
110
+ let count = 1;
111
+ code.push(`${code.var('headers').toLowerCase()} = {`);
112
+ for (header in headers) {
113
+ if (count++ !== headerCount) {
114
+ code.push(1, `"${header}": ${formatHeader(header, headers[header])},`);
115
+ }
116
+ else {
117
+ code.push(1, `"${header}": ${formatHeader(header, headers[header])}`);
118
+ }
119
+ }
120
+ code.push(0, '}').blank();
121
+ }
122
+ // Construct request
123
+ const method = source.method.toLowerCase();
124
+ let request = format(`${code.var('response').toLowerCase()} = requests.${method}(${code.var('url').toLowerCase()}`);
125
+ if (normalizedMimeType === MediaTypes.MULTIPART && dataStr) {
126
+ request += `, data=data`;
127
+ }
128
+ if (payload) {
129
+ const dataType = normalizedMimeType === MediaTypes.JSON ? 'json' : 'data';
130
+ request += `, ${dataType}=${code.var('payload').toLowerCase()}`;
131
+ }
132
+ if (headerCount > 0) {
133
+ request += `, headers=${code.var('headers').toLowerCase()}`;
134
+ }
135
+ if (qs) {
136
+ request += `, params=${code.var('query').toLowerCase()}`;
137
+ }
138
+ if (source.basicAuth) {
139
+ request += `, auth=('${source.basicAuth.username}','${source.basicAuth.password}')`;
140
+ }
141
+ request += ')';
142
+ code.push(request).blank();
143
+ // Print response
144
+ if (source.allResponseCodes?.includes('204')) {
145
+ code
146
+ .push(`if response.status_code == 204:`)
147
+ .push(level + 1, 'print("success")')
148
+ .push('else:')
149
+ .push(level + 1, `${code.var('data').toLowerCase()} = ${code.var('response').toLowerCase()}.json()`)
150
+ .push(level + 1, `print(${code.var('data').toLowerCase()})`);
151
+ }
152
+ else {
153
+ code
154
+ .push(`${code.var('data').toLowerCase()} = ${code.var('response').toLowerCase()}.json()`)
155
+ .push(`print(${code.var('data').toLowerCase()})`);
156
+ }
157
+ return code.join();
158
+ };
159
+ export default handler;
160
+ function addComments(code) {
161
+ code.push('"""');
162
+ code.push('Requires python >= 3');
163
+ code.blank();
164
+ code.push('Requires module "requests" >= 2.25.1');
165
+ code.push('See here for installation details:');
166
+ code.push(' https://requests.readthedocs.io/');
167
+ code.push('"""');
168
+ code.blank();
169
+ }
170
+ function jsObjectToPythonDict(input, indent) {
171
+ // TODO: add inlineCharacterLimit: 25 as for stringifyObject
172
+ return JSON.stringify(input, function replacer(key, value) {
173
+ if (key && typeof value === 'boolean') {
174
+ if (value) {
175
+ return '__REDOCLY_<True>__';
176
+ }
177
+ return '__REDOCLY_<False>__';
178
+ }
179
+ if (value === null) {
180
+ return '__REDOCLY_<None>__';
181
+ }
182
+ return value;
183
+ }, indent).replace(/"__REDOCLY_<(\w+)>__"/g, '$1');
184
+ }
185
+ //# sourceMappingURL=requests.js.map