@redocly/openapi-docs 3.12.0 → 3.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (384) hide show
  1. package/dist/redocly-openapi-docs.min.js +753 -750
  2. package/lib/components/ApiInfo/ApiInfo.js +29 -1
  3. package/lib/components/ApiInfo/Metadata.js +29 -1
  4. package/lib/components/ApiInfo/index.js +2 -1
  5. package/lib/components/ApiInfo/styled.js +16 -8
  6. package/lib/components/CallbackSamples/CallbackSamples.js +25 -4
  7. package/lib/components/CallbackSamples/index.js +2 -1
  8. package/lib/components/Callbacks/CallbackDetails.js +17 -3
  9. package/lib/components/Callbacks/CallbackOperation.js +24 -3
  10. package/lib/components/Callbacks/CallbackSummary.js +19 -3
  11. package/lib/components/Callbacks/CallbacksList.js +16 -1
  12. package/lib/components/Callbacks/index.js +4 -1
  13. package/lib/components/Callbacks/styled.js +6 -3
  14. package/lib/components/Content/Content.js +10 -1
  15. package/lib/components/Content/index.js +2 -1
  16. package/lib/components/Content/useAutoScroll.js +50 -1
  17. package/lib/components/ContentItem/ContentItem.js +31 -1
  18. package/lib/components/ContentItem/index.js +2 -1
  19. package/lib/components/ContentItem/useIsExpanded.js +33 -1
  20. package/lib/components/ContentItems/ContentItems.js +19 -1
  21. package/lib/components/ContentItems/Items.js +13 -1
  22. package/lib/components/ContentItems/VirtualList.js +35 -1
  23. package/lib/components/ContentItems/helpers.js +49 -1
  24. package/lib/components/ContentItems/index.js +2 -1
  25. package/lib/components/ContentItems/useScrollOnRender.js +26 -1
  26. package/lib/components/Discriminator/Discriminator.js +27 -2
  27. package/lib/components/Discriminator/index.js +2 -1
  28. package/lib/components/Download/DownloadSpecification.js +46 -4
  29. package/lib/components/Download/index.js +2 -1
  30. package/lib/components/Download/types.js +2 -0
  31. package/lib/components/Download/useDownloadInfo.js +42 -1
  32. package/lib/components/ErrorBoundary/ErrorBoundary.js +22 -2
  33. package/lib/components/ErrorBoundary/index.js +2 -1
  34. package/lib/components/ExpandAllButton/ExpandAllButton.js +31 -2
  35. package/lib/components/ExpandAllButton/index.js +2 -1
  36. package/lib/components/ExternalDocumentation/ExternalDocumentation.js +18 -4
  37. package/lib/components/ExternalDocumentation/index.js +2 -1
  38. package/lib/components/Language/LanguageDropdown.js +21 -1
  39. package/lib/components/Language/LanguageItem.js +33 -1
  40. package/lib/components/Language/LanguageList.js +93 -1
  41. package/lib/components/Language/_tests_/LanguageDropdown.test.js +23 -1
  42. package/lib/components/Language/constants.js +3 -1
  43. package/lib/components/Language/index.js +4 -1
  44. package/lib/components/Language/styled.js +29 -15
  45. package/lib/components/Markdown/Markdown.js +64 -1
  46. package/lib/components/Markdown/index.js +3 -1
  47. package/lib/components/Markdown/types.js +2 -0
  48. package/lib/components/MediaTypeSwitch/MediaTypesSwitch.js +51 -1
  49. package/lib/components/MediaTypeSwitch/index.js +2 -1
  50. package/lib/components/OperationItem/Description.js +9 -1
  51. package/lib/components/OperationItem/OperationItem.js +70 -5
  52. package/lib/components/OperationItem/_tests_/OperationItem.test.js +70 -1
  53. package/lib/components/OperationItem/_tests_/__mocks__/mock-intersection-observer.js +40 -1
  54. package/lib/components/OperationItem/index.js +2 -1
  55. package/lib/components/OperationItem/types.js +2 -0
  56. package/lib/components/Overlay.js +48 -3
  57. package/lib/components/Overview/Overview.js +20 -1
  58. package/lib/components/Overview/index.js +2 -1
  59. package/lib/components/PageFooter/PageFooter.js +19 -1
  60. package/lib/components/PageFooter/index.js +2 -1
  61. package/lib/components/Panel/ResponsePanel.js +12 -6
  62. package/lib/components/Panel/Trigger.js +4 -2
  63. package/lib/components/Panel/index.js +3 -1
  64. package/lib/components/PanelItem/PanelItem.js +6 -1
  65. package/lib/components/PanelItem/index.js +3 -1
  66. package/lib/components/PanelItem/styled.js +20 -10
  67. package/lib/components/PayloadSamples/Example.js +6 -1
  68. package/lib/components/PayloadSamples/ExampleValue.js +30 -1
  69. package/lib/components/PayloadSamples/MediaTypeSamples.js +36 -2
  70. package/lib/components/PayloadSamples/PayloadSamples.js +26 -1
  71. package/lib/components/PayloadSamples/index.js +7 -1
  72. package/lib/components/PayloadSamples/styled.js +9 -4
  73. package/lib/components/PayloadSamples/types.js +2 -0
  74. package/lib/components/PropertyDetails/DescriptionEnums.js +19 -3
  75. package/lib/components/PropertyDetails/EnumValues.js +37 -1
  76. package/lib/components/PropertyDetails/Examples.js +26 -1
  77. package/lib/components/PropertyDetails/Extensions.js +17 -2
  78. package/lib/components/PropertyDetails/FieldDetail.js +15 -2
  79. package/lib/components/PropertyDetails/FieldDetails.js +51 -6
  80. package/lib/components/PropertyDetails/Pattern.js +21 -1
  81. package/lib/components/PropertyDetails/PlusCircleIcon.js +10 -4
  82. package/lib/components/PropertyDetails/PropertyDetails.js +22 -5
  83. package/lib/components/PropertyDetails/SchemaTypeInfo.js +10 -2
  84. package/lib/components/PropertyDetails/SimpleEnums.js +13 -2
  85. package/lib/components/PropertyDetails/cycleColorsByLevel.js +18 -1
  86. package/lib/components/PropertyDetails/index.js +4 -1
  87. package/lib/components/PropertyDetails/styled.js +15 -7
  88. package/lib/components/PropertyDetails/types.js +2 -0
  89. package/lib/components/RedoclyOpenAPIDocs/Providers.js +114 -1
  90. package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocs.js +57 -1
  91. package/lib/components/RedoclyOpenAPIDocs/RedoclyOpenAPIDocsStandalone.js +86 -1
  92. package/lib/components/RedoclyOpenAPIDocs/index.js +5 -1
  93. package/lib/components/RedoclyOpenAPIDocs/styled.js +4 -2
  94. package/lib/components/RedoclyOpenAPIDocs/types.js +2 -0
  95. package/lib/components/RedoclyOpenAPIDocs/utils.js +33 -1
  96. package/lib/components/RenderHook/RenderHook.js +17 -1
  97. package/lib/components/RenderHook/index.js +2 -1
  98. package/lib/components/Replay/EmbeddedReplay.js +41 -3
  99. package/lib/components/Replay/Replay.js +99 -1
  100. package/lib/components/Replay/index.js +3 -1
  101. package/lib/components/Replay/utils.js +208 -1
  102. package/lib/components/Request/RequestDetails.js +33 -2
  103. package/lib/components/Request/types.js +2 -0
  104. package/lib/components/RequestParameters/Body.js +8 -1
  105. package/lib/components/RequestParameters/ParametersGroup.js +19 -4
  106. package/lib/components/RequestParameters/RequestParameters.js +40 -1
  107. package/lib/components/RequestParameters/index.js +4 -1
  108. package/lib/components/RequestSamples/CodeSample.js +55 -2
  109. package/lib/components/RequestSamples/Example.js +37 -1
  110. package/lib/components/RequestSamples/RequestSamples.js +89 -5
  111. package/lib/components/RequestSamples/index.js +3 -1
  112. package/lib/components/RequestSamples/useCodeSamples.js +92 -1
  113. package/lib/components/ResponseSamples/ResponseSamples.js +47 -1
  114. package/lib/components/ResponseSamples/Summary.js +9 -1
  115. package/lib/components/ResponseSamples/index.js +2 -1
  116. package/lib/components/Responses/OperationResponseList.js +42 -2
  117. package/lib/components/Responses/ResponseDetails.js +18 -1
  118. package/lib/components/Responses/ResponseHeaders.js +15 -1
  119. package/lib/components/Responses/index.js +6 -1
  120. package/lib/components/Responses/styled.js +14 -6
  121. package/lib/components/Responses/types.js +2 -0
  122. package/lib/components/RightPanel/RightPanel.js +21 -1
  123. package/lib/components/RightPanel/index.js +2 -1
  124. package/lib/components/Samples/ExampleSwitch.js +33 -1
  125. package/lib/components/Samples/index.js +3 -1
  126. package/lib/components/Samples/use-example-key.js +12 -1
  127. package/lib/components/Schema/ArraySchema.js +45 -1
  128. package/lib/components/Schema/ObjectSchema.js +29 -1
  129. package/lib/components/Schema/OneOfSchema.js +47 -3
  130. package/lib/components/Schema/RecursiveSchema.js +10 -1
  131. package/lib/components/Schema/Schema.js +63 -2
  132. package/lib/components/Schema/SubSchema.js +20 -1
  133. package/lib/components/Schema/helpers.js +16 -1
  134. package/lib/components/Schema/index.js +5 -1
  135. package/lib/components/Schema/types.js +2 -0
  136. package/lib/components/Schema/useOneOfLocationIdx.js +11 -1
  137. package/lib/components/SchemaDefinition/SchemaDefinition.js +65 -2
  138. package/lib/components/SchemaDefinition/index.js +2 -1
  139. package/lib/components/SectionContent/SectionContent.js +49 -6
  140. package/lib/components/SectionContent/index.js +2 -1
  141. package/lib/components/SectionItem/SectionItem.js +14 -1
  142. package/lib/components/SectionItem/index.js +2 -1
  143. package/lib/components/Security/Divider.js +9 -2
  144. package/lib/components/Security/OAuthFlow.js +11 -1
  145. package/lib/components/Security/OAuthScopes.js +59 -9
  146. package/lib/components/Security/Security.js +15 -1
  147. package/lib/components/Security/SecurityButton.js +31 -7
  148. package/lib/components/Security/SecurityFlow.js +28 -4
  149. package/lib/components/Security/SecurityModal.js +34 -5
  150. package/lib/components/Security/SecuritySchemeItem.js +15 -4
  151. package/lib/components/Security/helper.js +16 -1
  152. package/lib/components/Security/index.js +11 -1
  153. package/lib/components/Security/styled.js +6 -3
  154. package/lib/components/SelectOrLabel/SelectOrLabel.js +12 -2
  155. package/lib/components/SelectOrLabel/index.js +2 -1
  156. package/lib/components/ServerList/ServerList.js +36 -10
  157. package/lib/components/ServerList/index.js +2 -1
  158. package/lib/components/ServerList/types.js +2 -0
  159. package/lib/components/ServerListDropdown/ServerListDropdown.js +54 -1
  160. package/lib/components/ServerListDropdown/index.js +2 -1
  161. package/lib/components/ServerListDropdown/styled.js +15 -6
  162. package/lib/components/SideMenu/SideMenu.js +13 -2
  163. package/lib/components/SideMenu/hooks/useMenuItems.js +110 -1
  164. package/lib/components/SideMenu/index.js +2 -1
  165. package/lib/components/SideMenu/types.js +2 -0
  166. package/lib/components/StickySidebar/SidebarActions.js +14 -2
  167. package/lib/components/StickySidebar/StickyResponsiveSidebar.js +37 -7
  168. package/lib/components/StickySidebar/index.js +2 -1
  169. package/lib/components/Tabs/Tabs.js +16 -5
  170. package/lib/components/Tabs/index.js +3 -1
  171. package/lib/components/Tabs/useTabsState.js +22 -1
  172. package/lib/components/TagItem/OperationNavigationItems.js +18 -4
  173. package/lib/components/TagItem/OperationsNavigation.js +46 -2
  174. package/lib/components/TagItem/TagItem.js +40 -7
  175. package/lib/components/TagItem/index.js +2 -1
  176. package/lib/components/TagItem/styled.js +5 -2
  177. package/lib/components/TagItem/types.js +2 -0
  178. package/lib/components/ViewNested/ViewNested.js +42 -9
  179. package/lib/components/ViewNested/index.js +2 -1
  180. package/lib/components/common/Badges.js +21 -5
  181. package/lib/components/common/BodyContent/BodyContent.js +31 -4
  182. package/lib/components/common/BodyContent/index.js +2 -1
  183. package/lib/components/common/ClearButton/ClearButton.js +5 -1
  184. package/lib/components/common/ClearButton/index.js +3 -1
  185. package/lib/components/common/ClearButton/styled.js +5 -2
  186. package/lib/components/common/ClearButton/types.js +2 -0
  187. package/lib/components/common/CodeBlockPanel.js +7 -3
  188. package/lib/components/common/ConstraintsView.js +14 -2
  189. package/lib/components/common/Dropdown/Dropdown.js +22 -4
  190. package/lib/components/common/Dropdown/index.js +2 -1
  191. package/lib/components/common/ExpandableExample/ExpandableExample.js +24 -3
  192. package/lib/components/common/ExpandableExample/index.js +2 -1
  193. package/lib/components/common/Extensions.js +17 -2
  194. package/lib/components/common/Fields/fields-layout.js +76 -51
  195. package/lib/components/common/Fields/fields.js +39 -17
  196. package/lib/components/common/Fields/index.js +3 -1
  197. package/lib/components/common/LinkToField.js +33 -6
  198. package/lib/components/common/OperationItemTitle.js +12 -6
  199. package/lib/components/common/SchemaSelection/SchemaSelection.js +51 -1
  200. package/lib/components/common/SchemaSelection/index.js +2 -1
  201. package/lib/components/common/Select/Select.js +21 -1
  202. package/lib/components/common/Select/index.js +3 -1
  203. package/lib/components/common/Select/styled.js +17 -9
  204. package/lib/components/common/Select/types.js +2 -0
  205. package/lib/components/common/Skeleton/LanguageListSkeleton.js +16 -6
  206. package/lib/components/common/Skeleton/Skeleton.js +15 -5
  207. package/lib/components/common/Skeleton/index.js +3 -1
  208. package/lib/components/common/headers.js +4 -2
  209. package/lib/components/common/index.js +14 -1
  210. package/lib/components/common/linkify.js +28 -4
  211. package/lib/components/common/mixins.js +4 -2
  212. package/lib/components/common/panels.js +52 -29
  213. package/lib/components/common/schema.js +16 -8
  214. package/lib/components/common/styled.js +15 -7
  215. package/lib/components/index.js +25 -1
  216. package/lib/components/pluggable/RedocExample.js +20 -1
  217. package/lib/components/pluggable/RedocSchema.js +22 -1
  218. package/lib/components/pluggable/index.js +3 -1
  219. package/lib/components/pluggable/styled.components.js +9 -4
  220. package/lib/constants.js +30 -1
  221. package/lib/empty.js +7 -1
  222. package/lib/events/codeSampleCopy.js +19 -1
  223. package/lib/events/creator.js +5 -1
  224. package/lib/events/index.js +8 -1
  225. package/lib/events/languageSwitch.js +18 -1
  226. package/lib/events/panelToggle.js +16 -1
  227. package/lib/events/serverSwitch.js +13 -1
  228. package/lib/events/tryItOpen.js +12 -1
  229. package/lib/events/tryItSent.js +12 -1
  230. package/lib/events/types.js +11 -1
  231. package/lib/hoc/types.js +2 -0
  232. package/lib/hoc/utils.js +4 -1
  233. package/lib/hoc/withRouter.js +17 -1
  234. package/lib/hoc/withStore.js +28 -1
  235. package/lib/hooks/index.js +9 -1
  236. package/lib/hooks/useActivateExample.js +35 -1
  237. package/lib/hooks/useActiveWithFallback.js +12 -1
  238. package/lib/hooks/useContentItems.js +10 -1
  239. package/lib/hooks/useLicense.js +17 -1
  240. package/lib/hooks/usePerformanceMetrics.js +26 -1
  241. package/lib/hooks/useRouter.js +17 -1
  242. package/lib/hooks/useTelemetry.js +5 -1
  243. package/lib/hooks/useTranslate.js +6 -1
  244. package/lib/hooks/useUppercase2LowercaseRedirect.js +12 -1
  245. package/lib/icons/CSharpIcon/CSharpIcon.js +7 -1
  246. package/lib/icons/CSharpIcon/index.js +2 -1
  247. package/lib/icons/CurlIcon/CurlIcon.js +8 -2
  248. package/lib/icons/CurlIcon/index.js +2 -1
  249. package/lib/icons/GOIcon/GOIcon.js +7 -1
  250. package/lib/icons/GOIcon/index.js +2 -1
  251. package/lib/icons/JavaIcon/JavaIcon.js +7 -1
  252. package/lib/icons/JavaIcon/index.js +2 -1
  253. package/lib/icons/JavaScriptIcon/JavaScriptIcon.js +7 -1
  254. package/lib/icons/JavaScriptIcon/index.js +2 -1
  255. package/lib/icons/NodeJSIcon/NodeJSIcon.js +7 -1
  256. package/lib/icons/NodeJSIcon/index.js +2 -1
  257. package/lib/icons/PHPIcon/PHPIcon.js +7 -1
  258. package/lib/icons/PHPIcon/index.js +2 -1
  259. package/lib/icons/PayloadIcon/PayloadIcon.js +7 -1
  260. package/lib/icons/PayloadIcon/index.js +2 -1
  261. package/lib/icons/PythonIcon/PythonIcon.js +7 -1
  262. package/lib/icons/PythonIcon/index.js +2 -1
  263. package/lib/icons/RIcon/RIcon.js +7 -1
  264. package/lib/icons/RIcon/index.js +2 -1
  265. package/lib/icons/RubyIcon/RubyIcon.js +7 -1
  266. package/lib/icons/RubyIcon/index.js +2 -1
  267. package/lib/index.js +49 -1
  268. package/lib/jotai/app.js +113 -1
  269. package/lib/jotai/operation.js +28 -1
  270. package/lib/jotai/replay.js +5 -1
  271. package/lib/jotai/store.js +8 -1
  272. package/lib/jotai/use-write-atom.js +9 -1
  273. package/lib/models/callback.js +28 -1
  274. package/lib/models/code-sample-options.js +2 -0
  275. package/lib/models/example.js +17 -1
  276. package/lib/models/field.js +109 -1
  277. package/lib/models/group.js +38 -1
  278. package/lib/models/index.js +14 -1
  279. package/lib/models/mediaContent.js +26 -1
  280. package/lib/models/mediaType.js +153 -1
  281. package/lib/models/operation.js +166 -1
  282. package/lib/models/request.js +25 -1
  283. package/lib/models/response.js +46 -1
  284. package/lib/models/schema.js +474 -2
  285. package/lib/models/security.js +84 -1
  286. package/lib/models/tab.js +2 -0
  287. package/lib/models/types.js +2 -0
  288. package/lib/services/OpenAPIParser.js +321 -1
  289. package/lib/services/check.js +104 -1
  290. package/lib/services/code-samples/constants.js +16 -1
  291. package/lib/services/code-samples/generator.js +540 -1
  292. package/lib/services/code-samples/httpsnippet/helpers/code-builder.js +252 -3
  293. package/lib/services/code-samples/httpsnippet/helpers/code-helpers.js +90 -2
  294. package/lib/services/code-samples/httpsnippet/helpers/constants.js +28 -1
  295. package/lib/services/code-samples/httpsnippet/helpers/lodash-int.js +173 -1
  296. package/lib/services/code-samples/httpsnippet/helpers/mocks/code-helpers-mock.js +76 -37
  297. package/lib/services/code-samples/httpsnippet/helpers/reducer.js +16 -1
  298. package/lib/services/code-samples/httpsnippet/helpers/shell.js +20 -1
  299. package/lib/services/code-samples/httpsnippet/helpers/string-utility.js +19 -1
  300. package/lib/services/code-samples/httpsnippet/index.js +166 -1
  301. package/lib/services/code-samples/httpsnippet/targets/__mocks__/mock.js +2340 -146
  302. package/lib/services/code-samples/httpsnippet/targets/csharp/httpclient.js +227 -2
  303. package/lib/services/code-samples/httpsnippet/targets/csharp/index.js +11 -1
  304. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/httpclient.js +185 -2
  305. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/index.js +11 -1
  306. package/lib/services/code-samples/httpsnippet/targets/go/index.js +11 -1
  307. package/lib/services/code-samples/httpsnippet/targets/go/native.js +222 -3
  308. package/lib/services/code-samples/httpsnippet/targets/index.js +28 -1
  309. package/lib/services/code-samples/httpsnippet/targets/java/httpclient.js +184 -3
  310. package/lib/services/code-samples/httpsnippet/targets/java/index.js +11 -1
  311. package/lib/services/code-samples/httpsnippet/targets/java8/apachehttp.js +223 -2
  312. package/lib/services/code-samples/httpsnippet/targets/java8/index.js +11 -1
  313. package/lib/services/code-samples/httpsnippet/targets/javascript/fetch.js +147 -1
  314. package/lib/services/code-samples/httpsnippet/targets/javascript/index.js +11 -1
  315. package/lib/services/code-samples/httpsnippet/targets/node/fetch.js +199 -1
  316. package/lib/services/code-samples/httpsnippet/targets/node/index.js +11 -1
  317. package/lib/services/code-samples/httpsnippet/targets/php/curl.js +203 -5
  318. package/lib/services/code-samples/httpsnippet/targets/php/index.js +11 -1
  319. package/lib/services/code-samples/httpsnippet/targets/php/types.js +2 -0
  320. package/lib/services/code-samples/httpsnippet/targets/php/utils.js +106 -5
  321. package/lib/services/code-samples/httpsnippet/targets/python/index.js +11 -1
  322. package/lib/services/code-samples/httpsnippet/targets/python/requests.js +185 -6
  323. package/lib/services/code-samples/httpsnippet/targets/r/httr.js +111 -1
  324. package/lib/services/code-samples/httpsnippet/targets/r/index.js +11 -1
  325. package/lib/services/code-samples/httpsnippet/targets/r/utils.js +18 -6
  326. package/lib/services/code-samples/httpsnippet/targets/ruby/index.js +11 -1
  327. package/lib/services/code-samples/httpsnippet/targets/ruby/native.js +169 -1
  328. package/lib/services/code-samples/httpsnippet/targets/shell/curl.js +94 -6
  329. package/lib/services/code-samples/httpsnippet/targets/shell/index.js +11 -1
  330. package/lib/services/code-samples/index.js +3 -1
  331. package/lib/services/code-samples/types.js +2 -0
  332. package/lib/services/config-options/helpers.js +49 -1
  333. package/lib/services/config-options/index.js +3 -1
  334. package/lib/services/config-options/normalizeOptions.js +83 -1
  335. package/lib/services/config-options/types.js +2 -0
  336. package/lib/services/history/helpers.js +63 -1
  337. package/lib/services/history/index.js +2 -1
  338. package/lib/services/index.js +9 -1
  339. package/lib/services/menu/builder.js +47 -1
  340. package/lib/services/menu/index.js +2 -1
  341. package/lib/services/menu/markdown.js +93 -1
  342. package/lib/services/menu/operation.js +50 -1
  343. package/lib/services/menu/tags.js +166 -1
  344. package/lib/services/types.js +2 -0
  345. package/lib/services/utils.js +83 -1
  346. package/lib/standalone.js +68 -1
  347. package/lib/styled-components.js +6 -1
  348. package/lib/types/app.js +2 -0
  349. package/lib/types/index.js +4 -1
  350. package/lib/types/open-api.js +2 -0
  351. package/lib/types/security.js +2 -0
  352. package/lib/utils/JsonPointer.js +84 -1
  353. package/lib/utils/areArraysEqual.js +4 -1
  354. package/lib/utils/argValuesHelpers.js +35 -1
  355. package/lib/utils/compose.js +2 -1
  356. package/lib/utils/configure-helpers.js +223 -1
  357. package/lib/utils/convertSwagger2OpenAPI.js +14 -1
  358. package/lib/utils/cookies.js +73 -1
  359. package/lib/utils/debounce.js +22 -1
  360. package/lib/utils/debug.js +11 -1
  361. package/lib/utils/dom.js +65 -1
  362. package/lib/utils/environments.js +13 -1
  363. package/lib/utils/helpers.js +222 -12
  364. package/lib/utils/index.js +25 -1
  365. package/lib/utils/isMobile.js +13 -1
  366. package/lib/utils/loadAndBundleSpec.js +32 -1
  367. package/lib/utils/local-storage.js +12 -1
  368. package/lib/utils/object.js +31 -1
  369. package/lib/utils/openapi.js +592 -1
  370. package/lib/utils/parameters.js +13 -1
  371. package/lib/utils/path.js +22 -1
  372. package/lib/utils/queryString.js +60 -1
  373. package/lib/utils/replaceVariables.js +14 -1
  374. package/lib/utils/saveTextBeforeHeading.js +35 -1
  375. package/lib/utils/security-details.js +49 -1
  376. package/lib/utils/session-storage.js +12 -1
  377. package/lib/utils/simplifyAstStructure.js +22 -1
  378. package/lib/utils/sort.js +21 -1
  379. package/lib/utils/string.js +65 -1
  380. package/lib/utils/telemetry.js +7 -1
  381. package/lib/utils/test-utils.js +26 -1
  382. package/lib/utils/theme-helpers.js +24 -3
  383. package/lib/utils/url.js +38 -1
  384. package/package.json +3 -3
@@ -1,2 +1,227 @@
1
- import{isObject as d}from"@redocly/theme/core/openapi";import{CodeBuilder as T}from"../../helpers/code-builder.js";import{HTTPSnippet as w}from"../../index.js";import{buildUrlExpression as S,printUrlVariablesDeclarations as E}from"../../helpers/code-helpers.js";import{isEmptyObject as A,normalizeMimeType as m}from"../../../../utils.js";import{capitalizeFirst as O}from"../../../generator.js";import{Lang as k}from"../../helpers/constants.js";import{MediaTypes as i}from"../../../../../constants.js";import{isLastInArray as H,isLastProperty as j}from"../../../../../utils/index.js";const x=function(s,c,{target:C,client:D}){const r=Object.assign({indent:" ",withWrapper:!0},c),t=new T({indentation:r.indent,variablesPrefix:r.variablesPrefix,capitalize:!0,lang:k.CSHARP}),b=L(s.method);if(r.withComments&&P(t),r.withWrapper&&(t.push("using System;"),t.push("using System.Net.Http;"),t.push("using System.Threading.Tasks;"),(h(i.JSON)||h(i.XML)||s.basicAuth)&&t.push("using System.Text;"),(h(i.URL_ENCODED)||s.securityOAuth2ExtraCalls?.length)&&t.push("using System.Collections.Generic;"),(h(i.JSON)||s.securityOAuth2ExtraCalls?.length)&&t.push("using System.Text.Json;"),l()&&t.push("using System.IO;"),(l()||s.basicAuth)&&t.push("using System.Net.Http.Headers;"),t.blank(),t.push("public class Program"),t.push("{"),t.push(1,"public static async Task Main()"),t.push(1,"{")),s.securityOAuth2ExtraCalls?.length){const e=new w(s.securityOAuth2ExtraCalls?.[0]).convert(C,D,{...r,withImports:!1,withWrapper:!1,withComments:!1,variablesPrefix:"oauth2"});t.push(e),t.push(2,"var oauth2Response = await oauth2Request.Content.ReadAsStringAsync();"),t.push(2,"JObject inputJObject = JObject.Parse(oauth2Response);"),t.push(2,'var accessToken = inputJObject["access_token"].ToString();'),t.blank()}const f=Object.keys(s.allHeaders).filter(e=>{switch(e.toLowerCase()){case"content-type":case"content-length":case"accept-encoding":return!1;default:return!0}});if(f.length?(t.push(2,"System.Net.Http.HttpClient client = new()"),t.push(2,"{"),t.push(3,"DefaultRequestHeaders ="),t.push(3,"{"),f.forEach(e=>{t.push(4,'{"%s", %s},',e,s.securityOAuth2ExtraCalls?.length?'"Bearer " + accessToken':`"${s.allHeaders[e]}"`)}),t.push(3,"}"),t.push(2,"};")):t.push(2,"System.Net.Http.HttpClient client = new();"),t.blank(),s.basicAuth){const{username:e,password:a}=s.basicAuth;t.push(2,`string base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes("${e}:${a}"));`),t.push(2,'client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(@"Basic", base64String);'),t.blank()}if(s.postData)switch(m(s.postData.mimeType)){case i.URL_ENCODED:s.postData.params&&(t.blank(),t.push(2,"List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();"),s.postData.params.forEach(e=>{t.push(2,'postData.Add(new KeyValuePair<string, string>("%s", "%s"));',e.name,e.value)}),t.blank());break;case i.MULTIPART:s.postData.params&&(t.blank(),t.push(2,"MultipartFormDataContent postData = new MultipartFormDataContent();"),s.postData.params.forEach(e=>{t.push(2,'postData.Add(new StringContent("%s"), "%s");',e.value,e.name)}));break;case i.JSON:s.postData.jsonObj&&(t.push(2,"string json = JsonSerializer.Serialize(new"),t.push(2,"{"),u(s.postData.jsonObj,3),t.push(2,"});"),t.blank(),t.push(2,'using StringContent postData = new(json, Encoding.UTF8, "%s");',s.postData.mimeType));break;case i.XML:s.postData.text&&(s.postData.text.trim().split(`
2
- `).forEach((e,a)=>{const n=(a===0?'string xml = @"':"")+e.replace(/"/g,'""');t.push(a===0?2:3,n)}),t.push(2,'";'),t.push(2,'using StringContent postData = new StringContent(xml, Encoding.UTF8, "%s");',s.postData.mimeType));break}else l()&&(t.push(2,"var ms = new MemoryStream();"),t.push(2,"var postData = new StreamContent(ms);"),t.push(2,'postData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");'));return E(s,t,3),t.push(2,"using HttpResponseMessage %s = await client.%sAsync(%s%s);",t.var("request"),b,S(s,t),r.withImports?M(s.method)?m(s.postData&&s.postData.mimeType)===i.URL_ENCODED?", new FormUrlEncodedContent(postData)":s.method==="delete"?"":s.postData&&s.postData.params||l()?", postData":", null":"":", new FormUrlEncodedContent(postData)"),r.withWrapper&&(t.push(2,"string response = await request.Content.ReadAsStringAsync();"),t.blank(),t.push(2,"Console.WriteLine(response);"),t.push(1,"}"),t.push("}")),t.join();function h(e){return s.postData&&m(s.postData.mimeType)===e}function l(){return s.headersObj&&s.headersObj["Content-Type"]===i.OCTET_STREAM}function g(e,a){e.forEach((n,p)=>{const o=!H(e,p);Array.isArray(n)?g(n,a+1):d(n)?(t.push(a+1,"new {"),u(n,a+2),t.push(a+1,"}%s",o?",":"")):t.push(a+1,'"%s"%s',n,o?",":"")}),t.push(a,"},")}function u(e,a){for(const[n,p]of Object.entries(e)){const o=!j(e,n);if(Array.isArray(p))t.push(a,"%s = new[] {",n),g(p,a);else if(d(p)){const y=A(p);t.push(a,"%s = new %s",n,y?"{},":"{"),y||(u(p,a+1),t.push(a,"}%s",o?",":""))}else t.push(a,'%s = "%s"%s',n,p,o?",":"")}}},V={key:"httpclient",title:"HttpClient",link:"https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient",description:".NET Standard HTTP Client"};var B=x;function P(s){s.push("// Requires >= .NET 5"),s.blank()}function L(s){return O(s.toLowerCase())}function M(s){return s&&["POST","PUT","DELETE","PATCH"].includes(s.toUpperCase())}export{B as default,V as info};
1
+ import { isObject } from '@redocly/theme/core/openapi';
2
+ import { CodeBuilder } from '../../helpers/code-builder.js';
3
+ import { HTTPSnippet } from '../../index.js';
4
+ import { buildUrlExpression, printUrlVariablesDeclarations } from '../../helpers/code-helpers.js';
5
+ import { isEmptyObject, normalizeMimeType } from '../../../../utils.js';
6
+ import { capitalizeFirst } from '../../../generator.js';
7
+ import { Lang } from '../../helpers/constants.js';
8
+ import { MediaTypes } from '../../../../../constants.js';
9
+ import { isLastInArray, isLastProperty } from '../../../../../utils/index.js';
10
+ const handler = function (source, originalOptions, { target, client }) {
11
+ const options = Object.assign({ indent: ' ', withWrapper: true }, originalOptions);
12
+ const code = new CodeBuilder({
13
+ indentation: options.indent,
14
+ variablesPrefix: options.variablesPrefix,
15
+ capitalize: true,
16
+ lang: Lang.CSHARP,
17
+ });
18
+ const methodFormatted = formatHttpMethod(source.method);
19
+ if (options.withComments) {
20
+ addComments(code);
21
+ }
22
+ if (options.withWrapper) {
23
+ code.push('using System;');
24
+ code.push('using System.Net.Http;');
25
+ code.push('using System.Threading.Tasks;');
26
+ if (isMimeType(MediaTypes.JSON) || isMimeType(MediaTypes.XML) || source.basicAuth) {
27
+ code.push('using System.Text;');
28
+ }
29
+ if (isMimeType(MediaTypes.URL_ENCODED) || source.securityOAuth2ExtraCalls?.length) {
30
+ code.push('using System.Collections.Generic;');
31
+ }
32
+ if (isMimeType(MediaTypes.JSON) || source.securityOAuth2ExtraCalls?.length) {
33
+ code.push('using System.Text.Json;');
34
+ }
35
+ if (isOctetStream()) {
36
+ code.push('using System.IO;');
37
+ }
38
+ if (isOctetStream() || source.basicAuth) {
39
+ code.push('using System.Net.Http.Headers;');
40
+ }
41
+ code.blank();
42
+ code.push('public class Program');
43
+ code.push('{');
44
+ code.push(1, 'public static async Task Main()');
45
+ code.push(1, '{');
46
+ }
47
+ if (source.securityOAuth2ExtraCalls?.length) {
48
+ const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, {
49
+ ...options,
50
+ withImports: false,
51
+ withWrapper: false,
52
+ withComments: false,
53
+ variablesPrefix: 'oauth2',
54
+ });
55
+ code.push(oAuth2PrefixCode);
56
+ code.push(2, 'var oauth2Response = await oauth2Request.Content.ReadAsStringAsync();');
57
+ code.push(2, 'JObject inputJObject = JObject.Parse(oauth2Response);');
58
+ code.push(2, 'var accessToken = inputJObject["access_token"].ToString();');
59
+ code.blank();
60
+ }
61
+ const headers = Object.keys(source.allHeaders).filter((header) => {
62
+ switch (header.toLowerCase()) {
63
+ case 'content-type':
64
+ case 'content-length':
65
+ case 'accept-encoding':
66
+ return false;
67
+ default:
68
+ return true;
69
+ }
70
+ });
71
+ if (headers.length) {
72
+ code.push(2, 'System.Net.Http.HttpClient client = new()');
73
+ code.push(2, '{');
74
+ code.push(3, 'DefaultRequestHeaders =');
75
+ code.push(3, '{');
76
+ headers.forEach((key) => {
77
+ code.push(4, '{"%s", %s},', key, source.securityOAuth2ExtraCalls?.length
78
+ ? '"Bearer " + accessToken'
79
+ : `"${source.allHeaders[key]}"`);
80
+ });
81
+ code.push(3, '}');
82
+ code.push(2, '};');
83
+ }
84
+ else {
85
+ code.push(2, 'System.Net.Http.HttpClient client = new();');
86
+ }
87
+ code.blank();
88
+ if (source.basicAuth) {
89
+ const { username, password } = source.basicAuth;
90
+ code.push(2, `string base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes("${username}:${password}"));`);
91
+ code.push(2, 'client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(@"Basic", base64String);');
92
+ code.blank();
93
+ }
94
+ if (source.postData) {
95
+ switch (normalizeMimeType(source.postData.mimeType)) {
96
+ case MediaTypes.URL_ENCODED:
97
+ if (source.postData.params) {
98
+ code.blank();
99
+ code.push(2, 'List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();');
100
+ source.postData.params.forEach((param) => {
101
+ code.push(2, 'postData.Add(new KeyValuePair<string, string>("%s", "%s"));', param.name, param.value);
102
+ });
103
+ code.blank();
104
+ }
105
+ break;
106
+ case MediaTypes.MULTIPART:
107
+ if (source.postData.params) {
108
+ code.blank();
109
+ code.push(2, 'MultipartFormDataContent postData = new MultipartFormDataContent();');
110
+ source.postData.params.forEach((param) => {
111
+ code.push(2, 'postData.Add(new StringContent("%s"), "%s");', param.value, param.name);
112
+ });
113
+ }
114
+ break;
115
+ case MediaTypes.JSON:
116
+ if (source.postData.jsonObj) {
117
+ code.push(2, 'string json = JsonSerializer.Serialize(new');
118
+ code.push(2, '{');
119
+ iterateObject(source.postData.jsonObj, 3);
120
+ code.push(2, '});');
121
+ code.blank();
122
+ code.push(2, 'using StringContent postData = new(json, Encoding.UTF8, "%s");', source.postData.mimeType);
123
+ }
124
+ break;
125
+ case MediaTypes.XML:
126
+ if (source.postData.text) {
127
+ source.postData.text
128
+ .trim()
129
+ .split('\n')
130
+ .forEach((item, index) => {
131
+ const line = (index === 0 ? 'string xml = @"' : '') + item.replace(/"/g, '""');
132
+ code.push(index === 0 ? 2 : 3, line);
133
+ });
134
+ code.push(2, '";');
135
+ code.push(2, 'using StringContent postData = new StringContent(xml, Encoding.UTF8, "%s");', source.postData.mimeType);
136
+ }
137
+ break;
138
+ }
139
+ }
140
+ else if (isOctetStream()) {
141
+ code.push(2, 'var ms = new MemoryStream();');
142
+ code.push(2, 'var postData = new StreamContent(ms);');
143
+ code.push(2, 'postData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");');
144
+ }
145
+ printUrlVariablesDeclarations(source, code, 3);
146
+ code.push(2, 'using HttpResponseMessage %s = await client.%sAsync(%s%s);', code.var('request'), methodFormatted, buildUrlExpression(source, code), options.withImports
147
+ ? isDataMethod(source.method)
148
+ ? normalizeMimeType(source.postData && source.postData.mimeType) === MediaTypes.URL_ENCODED
149
+ ? ', new FormUrlEncodedContent(postData)'
150
+ : source.method === 'delete'
151
+ ? ''
152
+ : (source.postData && source.postData.params) || isOctetStream()
153
+ ? ', postData'
154
+ : ', null'
155
+ : ''
156
+ : ', new FormUrlEncodedContent(postData)');
157
+ if (options.withWrapper) {
158
+ code.push(2, 'string response = await request.Content.ReadAsStringAsync();');
159
+ code.blank();
160
+ code.push(2, 'Console.WriteLine(response);');
161
+ code.push(1, '}');
162
+ code.push('}');
163
+ }
164
+ return code.join();
165
+ function isMimeType(mimeType) {
166
+ return source.postData && normalizeMimeType(source.postData.mimeType) === mimeType;
167
+ }
168
+ function isOctetStream() {
169
+ return source.headersObj && source.headersObj['Content-Type'] === MediaTypes.OCTET_STREAM;
170
+ }
171
+ function iterateArray(arr, indent) {
172
+ arr.forEach((item, index) => {
173
+ const hasTrailingComma = !isLastInArray(arr, index);
174
+ if (Array.isArray(item)) {
175
+ iterateArray(item, indent + 1);
176
+ }
177
+ else if (isObject(item)) {
178
+ code.push(indent + 1, 'new {');
179
+ iterateObject(item, indent + 2);
180
+ code.push(indent + 1, '}%s', hasTrailingComma ? ',' : '');
181
+ }
182
+ else {
183
+ code.push(indent + 1, '"%s"%s', item, hasTrailingComma ? ',' : '');
184
+ }
185
+ });
186
+ code.push(indent, '},');
187
+ }
188
+ function iterateObject(obj, indent) {
189
+ for (const [key, value] of Object.entries(obj)) {
190
+ const hasTrailingComma = !isLastProperty(obj, key);
191
+ if (Array.isArray(value)) {
192
+ code.push(indent, '%s = new[] {', key);
193
+ iterateArray(value, indent);
194
+ }
195
+ else if (isObject(value)) {
196
+ const isEmpty = isEmptyObject(value);
197
+ code.push(indent, '%s = new %s', key, isEmpty ? '{},' : '{');
198
+ if (!isEmpty) {
199
+ iterateObject(value, indent + 1);
200
+ code.push(indent, '}%s', hasTrailingComma ? ',' : '');
201
+ }
202
+ }
203
+ else {
204
+ code.push(indent, '%s = "%s"%s', key, value, hasTrailingComma ? ',' : '');
205
+ }
206
+ }
207
+ }
208
+ };
209
+ export const info = {
210
+ key: 'httpclient',
211
+ title: 'HttpClient',
212
+ link: 'https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient',
213
+ description: '.NET Standard HTTP Client',
214
+ };
215
+ export default handler;
216
+ function addComments(code) {
217
+ code.push('// Requires >= .NET 5');
218
+ code.blank();
219
+ }
220
+ function formatHttpMethod(method) {
221
+ return capitalizeFirst(method.toLowerCase());
222
+ }
223
+ function isDataMethod(method) {
224
+ const methods = ['POST', 'PUT', 'DELETE', 'PATCH'];
225
+ return method && methods.includes(method.toUpperCase());
226
+ }
227
+ //# sourceMappingURL=httpclient.js.map
@@ -1 +1,11 @@
1
- import t from"./httpclient.js";var p={info:{key:"csharp",title:"CSharp",extname:".cs",default:"httpclient"},httpclient:t};export{p as default};
1
+ import httpclient from './httpclient.js';
2
+ export default {
3
+ info: {
4
+ key: 'csharp',
5
+ title: 'CSharp',
6
+ extname: '.cs',
7
+ default: 'httpclient',
8
+ },
9
+ httpclient,
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -1,2 +1,185 @@
1
- import f from"stringify-object";import{CodeBuilder as g}from"../../helpers/code-builder.js";import{HTTPSnippet as C}from"../../index.js";import{addIndentation as D,buildUrlExpression as y,printUrlVariablesDeclarations as T}from"../../helpers/code-helpers.js";import{normalizeMimeType as o}from"../../../../utils.js";import{capitalizeFirst as b}from"../../../generator.js";import{Lang as w}from"../../helpers/constants.js";import{MediaTypes as s}from"../../../../../constants.js";const S=function(t,h,{target:u,client:m}){const n=Object.assign({indent:" ",withWrapper:!0},h),e=new g({indentation:n.indent,variablesPrefix:n.variablesPrefix,capitalize:!0,lang:w.CSHARPNEWTONSOFT}),c=E(t.method);if(n.withComments&&O(e),n.withWrapper&&(e.push("using System;"),e.push("using System.Net.Http;"),e.push("using System.Threading.Tasks;"),(i(s.JSON)||i(s.XML)||t.basicAuth)&&e.push("using System.Text;"),(i(s.URL_ENCODED)||t.securityOAuth2ExtraCalls?.length)&&e.push("using System.Collections.Generic;"),(i(s.JSON)||t.securityOAuth2ExtraCalls?.length)&&e.push("using Newtonsoft.Json.Linq;"),p()&&e.push("using System.IO;"),(p()||t.basicAuth)&&e.push("using System.Net.Http.Headers;"),e.blank(),e.push("public class Program"),e.push("{"),e.push(1,"private readonly IHttpClientFactory _httpClientFactory;"),e.push(1,"public static async Task Main(string[] args)"),e.push(1,"{"),e.push(2,"var client = _httpClientFactory.CreateClient();")),t.securityOAuth2ExtraCalls?.length){const a=new C(t.securityOAuth2ExtraCalls?.[0]).convert(u,m,{...n,withImports:!1,withWrapper:!1,withComments:!1,variablesPrefix:"oauth2"});e.push(a),e.push(2,"var oauth2Response = await oauth2Request.Content.ReadAsStringAsync();"),e.push(2,"JObject inputJObject = JObject.Parse(oauth2Response);"),e.push(2,'var accessToken = inputJObject["access_token"].ToString();'),e.blank()}const l=Object.keys(t.allHeaders).filter(a=>{switch(a.toLowerCase()){case"content-type":case"content-length":case"accept-encoding":return!1;default:return!0}});if(l.length&&l.forEach(a=>{e.push(2,'client.DefaultRequestHeaders.Add("%s", %s);',a,t.securityOAuth2ExtraCalls?.length?'"Bearer " + accessToken':`"${t.allHeaders[a]}"`)}),t.basicAuth){const{username:a,password:r}=t.basicAuth;e.push(2,`var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes("${a}:${r}"));`),e.push(2,'client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(@"Basic", base64String);')}if(t.postData)switch(o(t.postData.mimeType)){case s.URL_ENCODED:t.postData.params&&(e.blank(),e.push(2,"List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();"),t.postData.params.forEach(a=>{e.push(2,'postData.Add(new KeyValuePair<string, string>("%s", "%s"));',a.name,a.value)}),e.blank());break;case s.MULTIPART:t.postData.params&&(e.blank(),e.push(2,"MultipartFormDataContent postData = new MultipartFormDataContent();"),t.postData.params.forEach(a=>{e.push(2,'postData.Add(new StringContent("%s"), "%s");',a.value,a.name)}));break;case s.JSON:t.postData.jsonObj&&(e.push(2,`JObject json = JObject.Parse(@"${D(f(t.postData.jsonObj,{indent:n.indent,inlineCharacterLimit:25}).replace(/"/g,'""'),{level:3,firstLine:!1})}");`),e.push(2,'var postData = new StringContent(json.ToString(), Encoding.UTF8, "%s");',t.postData.mimeType));break;case s.XML:t.postData.text&&(t.postData.text.trim().split(`
2
- `).forEach((a,r)=>{const d=(r===0?'string xml = @"':"")+a.replace(/"/g,'""');e.push(r===0?3:4,d)}),e.push(2,'";'),e.push(2,'var postData = new StringContent(xml, Encoding.UTF8, "%s");',t.postData.mimeType));break}else p()&&(e.push(2,"var ms = new MemoryStream();"),e.push(2,"var postData = new StreamContent(ms);"),e.push(2,'postData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");'));return T(t,e,3),e.push(2,"var %s = await client.%sAsync(%s%s);",e.var("request"),c,y(t,e),n.withImports?A(t.method)?o(t.postData&&t.postData.mimeType)===s.URL_ENCODED?", new FormUrlEncodedContent(postData)":t.method==="delete"?"":t.postData&&t.postData.params||p()?", postData":", null":"":", new FormUrlEncodedContent(postData)"),n.withWrapper&&(e.push(2,"var response = await request.Content.ReadAsStringAsync();"),e.blank(),e.push(2,"Console.WriteLine(response);"),e.push(1,"}"),e.push("}")),e.join();function i(a){return t.postData&&o(t.postData.mimeType)===a}function p(){return t.headersObj&&t.headersObj["Content-Type"]===s.OCTET_STREAM}},M={key:"httpclient",title:"HttpClient",link:"https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient",description:".NET Standard HTTP Client"};var N=S;function O(t){t.push("/*"),t.push(" * Requires >= .NET 5"),t.push(" *"),t.push(' * Requires package "Newtonsoft.Json" >= 9.01'),t.push(" * See here for installation details:"),t.push(" * https://www.newtonsoft.com/json"),t.push(" */"),t.blank()}function E(t){return b(t.toLowerCase())}function A(t){return t&&["POST","PUT","DELETE","PATCH"].includes(t.toUpperCase())}export{N as default,M as info};
1
+ import stringifyObject from 'stringify-object';
2
+ import { CodeBuilder } from '../../helpers/code-builder.js';
3
+ import { HTTPSnippet } from '../../index.js';
4
+ import { addIndentation, buildUrlExpression, printUrlVariablesDeclarations, } from '../../helpers/code-helpers.js';
5
+ import { normalizeMimeType } from '../../../../utils.js';
6
+ import { capitalizeFirst } from '../../../generator.js';
7
+ import { Lang } from '../../helpers/constants.js';
8
+ import { MediaTypes } from '../../../../../constants.js';
9
+ const handler = function (source, originalOptions, { target, client }) {
10
+ const options = Object.assign({ indent: ' ', withWrapper: true }, originalOptions);
11
+ const code = new CodeBuilder({
12
+ indentation: options.indent,
13
+ variablesPrefix: options.variablesPrefix,
14
+ capitalize: true,
15
+ lang: Lang.CSHARPNEWTONSOFT,
16
+ });
17
+ const methodFormatted = formatHttpMethod(source.method);
18
+ if (options.withComments) {
19
+ addComments(code);
20
+ }
21
+ if (options.withWrapper) {
22
+ code.push('using System;');
23
+ code.push('using System.Net.Http;');
24
+ code.push('using System.Threading.Tasks;');
25
+ if (isMimeType(MediaTypes.JSON) || isMimeType(MediaTypes.XML) || source.basicAuth) {
26
+ code.push('using System.Text;');
27
+ }
28
+ if (isMimeType(MediaTypes.URL_ENCODED) || source.securityOAuth2ExtraCalls?.length) {
29
+ code.push('using System.Collections.Generic;');
30
+ }
31
+ if (isMimeType(MediaTypes.JSON) || source.securityOAuth2ExtraCalls?.length) {
32
+ code.push('using Newtonsoft.Json.Linq;');
33
+ }
34
+ if (isOctetStream()) {
35
+ code.push('using System.IO;');
36
+ }
37
+ if (isOctetStream() || source.basicAuth) {
38
+ code.push('using System.Net.Http.Headers;');
39
+ }
40
+ code.blank();
41
+ code.push('public class Program');
42
+ code.push('{');
43
+ code.push(1, 'private readonly IHttpClientFactory _httpClientFactory;');
44
+ code.push(1, 'public static async Task Main(string[] args)');
45
+ code.push(1, '{');
46
+ code.push(2, 'var client = _httpClientFactory.CreateClient();');
47
+ }
48
+ if (source.securityOAuth2ExtraCalls?.length) {
49
+ const oAuth2PrefixCode = new HTTPSnippet(source.securityOAuth2ExtraCalls?.[0]).convert(target, client, {
50
+ ...options,
51
+ withImports: false,
52
+ withWrapper: false,
53
+ withComments: false,
54
+ variablesPrefix: 'oauth2',
55
+ });
56
+ code.push(oAuth2PrefixCode);
57
+ code.push(2, 'var oauth2Response = await oauth2Request.Content.ReadAsStringAsync();');
58
+ code.push(2, 'JObject inputJObject = JObject.Parse(oauth2Response);');
59
+ code.push(2, 'var accessToken = inputJObject["access_token"].ToString();');
60
+ code.blank();
61
+ }
62
+ const headers = Object.keys(source.allHeaders).filter((header) => {
63
+ switch (header.toLowerCase()) {
64
+ case 'content-type':
65
+ case 'content-length':
66
+ case 'accept-encoding':
67
+ return false;
68
+ default:
69
+ return true;
70
+ }
71
+ });
72
+ if (headers.length) {
73
+ headers.forEach((key) => {
74
+ code.push(2, 'client.DefaultRequestHeaders.Add("%s", %s);', key, source.securityOAuth2ExtraCalls?.length
75
+ ? '"Bearer " + accessToken'
76
+ : `"${source.allHeaders[key]}"`);
77
+ });
78
+ }
79
+ if (source.basicAuth) {
80
+ const { username, password } = source.basicAuth;
81
+ code.push(2, `var base64String = Convert.ToBase64String(Encoding.ASCII.GetBytes("${username}:${password}"));`);
82
+ code.push(2, 'client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(@"Basic", base64String);');
83
+ }
84
+ if (source.postData) {
85
+ switch (normalizeMimeType(source.postData.mimeType)) {
86
+ case MediaTypes.URL_ENCODED:
87
+ if (source.postData.params) {
88
+ code.blank();
89
+ code.push(2, 'List<KeyValuePair<string, string>> postData = new List<KeyValuePair<string, string>>();');
90
+ source.postData.params.forEach((param) => {
91
+ code.push(2, 'postData.Add(new KeyValuePair<string, string>("%s", "%s"));', param.name, param.value);
92
+ });
93
+ code.blank();
94
+ }
95
+ break;
96
+ case MediaTypes.MULTIPART:
97
+ if (source.postData.params) {
98
+ code.blank();
99
+ code.push(2, 'MultipartFormDataContent postData = new MultipartFormDataContent();');
100
+ source.postData.params.forEach((param) => {
101
+ code.push(2, 'postData.Add(new StringContent("%s"), "%s");', param.value, param.name);
102
+ });
103
+ }
104
+ break;
105
+ case MediaTypes.JSON:
106
+ if (source.postData.jsonObj) {
107
+ code.push(2, `JObject json = JObject.Parse(@"${addIndentation(stringifyObject(source.postData.jsonObj, {
108
+ indent: options.indent,
109
+ inlineCharacterLimit: 25,
110
+ }).replace(/"/g, '""'), { level: 3, firstLine: false })}");`);
111
+ code.push(2, 'var postData = new StringContent(json.ToString(), Encoding.UTF8, "%s");', source.postData.mimeType);
112
+ }
113
+ break;
114
+ case MediaTypes.XML:
115
+ if (source.postData.text) {
116
+ source.postData.text
117
+ .trim()
118
+ .split('\n')
119
+ .forEach((item, index) => {
120
+ const line = (index === 0 ? 'string xml = @"' : '') + item.replace(/"/g, '""');
121
+ code.push(index === 0 ? 3 : 4, line);
122
+ });
123
+ code.push(2, '";');
124
+ code.push(2, 'var postData = new StringContent(xml, Encoding.UTF8, "%s");', source.postData.mimeType);
125
+ }
126
+ break;
127
+ }
128
+ }
129
+ else if (isOctetStream()) {
130
+ code.push(2, 'var ms = new MemoryStream();');
131
+ code.push(2, 'var postData = new StreamContent(ms);');
132
+ code.push(2, 'postData.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");');
133
+ }
134
+ printUrlVariablesDeclarations(source, code, 3);
135
+ code.push(2, 'var %s = await client.%sAsync(%s%s);', code.var('request'), methodFormatted, buildUrlExpression(source, code), options.withImports
136
+ ? isDataMethod(source.method)
137
+ ? normalizeMimeType(source.postData && source.postData.mimeType) === MediaTypes.URL_ENCODED
138
+ ? ', new FormUrlEncodedContent(postData)'
139
+ : source.method === 'delete'
140
+ ? ''
141
+ : (source.postData && source.postData.params) || isOctetStream()
142
+ ? ', postData'
143
+ : ', null'
144
+ : ''
145
+ : ', new FormUrlEncodedContent(postData)');
146
+ if (options.withWrapper) {
147
+ code.push(2, 'var response = await request.Content.ReadAsStringAsync();');
148
+ code.blank();
149
+ code.push(2, 'Console.WriteLine(response);');
150
+ code.push(1, '}');
151
+ code.push('}');
152
+ }
153
+ return code.join();
154
+ function isMimeType(mimeType) {
155
+ return source.postData && normalizeMimeType(source.postData.mimeType) === mimeType;
156
+ }
157
+ function isOctetStream() {
158
+ return source.headersObj && source.headersObj['Content-Type'] === MediaTypes.OCTET_STREAM;
159
+ }
160
+ };
161
+ export const info = {
162
+ key: 'httpclient',
163
+ title: 'HttpClient',
164
+ link: 'https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient',
165
+ description: '.NET Standard HTTP Client',
166
+ };
167
+ export default handler;
168
+ function addComments(code) {
169
+ code.push('/*');
170
+ code.push(' * Requires >= .NET 5');
171
+ code.push(' *');
172
+ code.push(' * Requires package "Newtonsoft.Json" >= 9.01');
173
+ code.push(' * See here for installation details:');
174
+ code.push(' * https://www.newtonsoft.com/json');
175
+ code.push(' */');
176
+ code.blank();
177
+ }
178
+ function formatHttpMethod(method) {
179
+ return capitalizeFirst(method.toLowerCase());
180
+ }
181
+ function isDataMethod(method) {
182
+ const methods = ['POST', 'PUT', 'DELETE', 'PATCH'];
183
+ return method && methods.includes(method.toUpperCase());
184
+ }
185
+ //# sourceMappingURL=httpclient.js.map
@@ -1 +1,11 @@
1
- import t from"./httpclient.js";var o={info:{key:"csharpNewtonsoft",title:"CSharpNewtonsoft",extname:".cs",default:"httpclient"},httpclient:t};export{o as default};
1
+ import httpclient from './httpclient.js';
2
+ export default {
3
+ info: {
4
+ key: 'csharpNewtonsoft',
5
+ title: 'CSharpNewtonsoft',
6
+ extname: '.cs',
7
+ default: 'httpclient',
8
+ },
9
+ httpclient,
10
+ };
11
+ //# sourceMappingURL=index.js.map
@@ -1 +1,11 @@
1
- import e from"./native.js";var o={info:{key:"go",title:"Go",extname:".go",default:"native"},native:e};export{o as default};
1
+ import native from './native.js';
2
+ export default {
3
+ info: {
4
+ key: 'go',
5
+ title: 'Go',
6
+ extname: '.go',
7
+ default: 'native',
8
+ },
9
+ native,
10
+ };
11
+ //# sourceMappingURL=index.js.map