@redocly/openapi-docs 3.24.0 → 3.24.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 (281) hide show
  1. package/dist/{redocly-openapi-docs.min.AiChatProvider-CIrPFbvX.js → redocly-openapi-docs.min.AiChatProvider-j-VDfFJ9.js} +1 -1
  2. package/dist/{redocly-openapi-docs.min.AiChatSqliteDBStorage-eAy3scC4.js → redocly-openapi-docs.min.AiChatSqliteDBStorage-BBRBmffc.js} +1 -1
  3. package/dist/{redocly-openapi-docs.min.AiPanel-C6CGDyzy.js → redocly-openapi-docs.min.AiPanel-DTzHqAiI.js} +1 -1
  4. package/dist/{redocly-openapi-docs.min.FileWatcher-dIKl80Ec.js → redocly-openapi-docs.min.FileWatcher-DDoyaS7A.js} +1 -1
  5. package/dist/{redocly-openapi-docs.min.SemanticSearchService-D4V6-td8.js → redocly-openapi-docs.min.SemanticSearchService-DNFOPBZK.js} +1 -1
  6. package/dist/{redocly-openapi-docs.min.SqliteDBStorage-D9-Rb-N7.js → redocly-openapi-docs.min.SqliteDBStorage-Dy40Vq04.js} +1 -1
  7. package/dist/{redocly-openapi-docs.min.TauriFileSystemAdapter-CHW6hO3z.js → redocly-openapi-docs.min.TauriFileSystemAdapter-CpViFqJQ.js} +1 -1
  8. package/dist/{redocly-openapi-docs.min.TauriRootStorage-CHiKNUn2.js → redocly-openapi-docs.min.TauriRootStorage-TCUrp2uB.js} +1 -1
  9. package/dist/{redocly-openapi-docs.min.ai-chat-mappers-C19k85fj.js → redocly-openapi-docs.min.ai-chat-mappers-CmX-8902.js} +1 -1
  10. package/dist/{redocly-openapi-docs.min.external-resolver-BH7DBWU-.js → redocly-openapi-docs.min.external-resolver-BkceRyB4.js} +1 -1
  11. package/dist/{redocly-openapi-docs.min.index-BQp5pipW.js → redocly-openapi-docs.min.index-BCcol5vU.js} +1 -1
  12. package/dist/{redocly-openapi-docs.min.index-dirYvuKs.js → redocly-openapi-docs.min.index-C6uU_v-b.js} +1 -1
  13. package/dist/{redocly-openapi-docs.min.index-BuFUmOUm.js → redocly-openapi-docs.min.index-CmXZfuiZ.js} +11 -11
  14. package/dist/{redocly-openapi-docs.min.index-DLlCa16R.js → redocly-openapi-docs.min.index-DVWw0ICA.js} +1 -1
  15. package/dist/redocly-openapi-docs.min.js +1 -1
  16. package/dist/{redocly-openapi-docs.min.lint-Xu623Q1T.js → redocly-openapi-docs.min.lint-2YpbCz3r.js} +2 -2
  17. package/dist/{redocly-openapi-docs.min.lint-graphql-D-Nm5P1M.js → redocly-openapi-docs.min.lint-graphql-Bgfcu2tP.js} +1 -1
  18. package/dist/{redocly-openapi-docs.min.respect-run-CWNqYysq.js → redocly-openapi-docs.min.respect-run-Ct8taisL.js} +1 -1
  19. package/dist/{redocly-openapi-docs.min.standalone-CRo0Sa5b.js → redocly-openapi-docs.min.standalone-BPCdJgtH.js} +3 -3
  20. package/dist/{redocly-openapi-docs.min.tauri-path-BUSVirPk.js → redocly-openapi-docs.min.tauri-path-CmqBCxGb.js} +1 -1
  21. package/dist/{redocly-openapi-docs.min.useAiChatQueries-CXyQzME7.js → redocly-openapi-docs.min.useAiChatQueries-t8oy8jik.js} +2 -2
  22. package/lib/components/ApiInfo/__tests__/ApiInfo.test.d.ts +1 -0
  23. package/lib/components/ApiInfo/__tests__/ApiInfo.test.js +46 -0
  24. package/lib/components/Callbacks/__tests__/Callbacks.test.d.ts +1 -0
  25. package/lib/components/Callbacks/__tests__/Callbacks.test.js +46 -0
  26. package/lib/components/Content/__tests__/useAutoScroll.test.d.ts +1 -0
  27. package/lib/components/Content/__tests__/useAutoScroll.test.js +88 -0
  28. package/lib/components/ContentItem/__tests__/useIsExpanded.test.d.ts +1 -0
  29. package/lib/components/ContentItem/__tests__/useIsExpanded.test.js +123 -0
  30. package/lib/components/ContentItems/__tests__/Items.test.d.ts +1 -0
  31. package/lib/components/ContentItems/__tests__/Items.test.js +66 -0
  32. package/lib/components/ContentItems/__tests__/VirtualList.test.d.ts +1 -0
  33. package/lib/components/ContentItems/__tests__/VirtualList.test.js +135 -0
  34. package/lib/components/Discriminator/__tests__/DiscriminatorDropdown.test.d.ts +1 -0
  35. package/lib/components/Discriminator/__tests__/DiscriminatorDropdown.test.js +63 -0
  36. package/lib/components/Download/__tests__/DownloadSpecification.test.d.ts +1 -0
  37. package/lib/components/Download/__tests__/DownloadSpecification.test.js +52 -0
  38. package/lib/components/ExpandAllButton/__tests__/ExpandAllButton.test.d.ts +1 -0
  39. package/lib/components/ExpandAllButton/__tests__/ExpandAllButton.test.js +60 -0
  40. package/lib/components/ExpandAllButton/__tests__/helpers.test.d.ts +1 -0
  41. package/lib/components/ExpandAllButton/__tests__/helpers.test.js +133 -0
  42. package/lib/components/Language/__tests__/LanguageDropdown.test.d.ts +1 -0
  43. package/lib/components/Language/__tests__/LanguageDropdown.test.js +23 -0
  44. package/lib/components/Markdown/__tests__/Markdown.test.d.ts +1 -0
  45. package/lib/components/Markdown/__tests__/Markdown.test.js +34 -0
  46. package/lib/components/McpOverview/__tests__/McpOverview.test.d.ts +1 -0
  47. package/lib/components/McpOverview/__tests__/McpOverview.test.js +66 -0
  48. package/lib/components/McpTool/__tests__/McpPrompt.test.d.ts +1 -0
  49. package/lib/components/McpTool/__tests__/McpPrompt.test.js +57 -0
  50. package/lib/components/McpTool/__tests__/McpResource.test.d.ts +1 -0
  51. package/lib/components/McpTool/__tests__/McpResource.test.js +81 -0
  52. package/lib/components/McpTool/__tests__/McpTool.test.d.ts +1 -0
  53. package/lib/components/McpTool/__tests__/McpTool.test.js +82 -0
  54. package/lib/components/MediaTypeSwitch/__tests__/MediaTypesSwitch.test.d.ts +1 -0
  55. package/lib/components/MediaTypeSwitch/__tests__/MediaTypesSwitch.test.js +79 -0
  56. package/lib/components/OperationItem/__tests__/OperationItem.test.d.ts +1 -0
  57. package/lib/components/OperationItem/__tests__/OperationItem.test.js +70 -0
  58. package/lib/components/OperationItem/__tests__/__mocks__/mock-intersection-observer.d.ts +16 -0
  59. package/lib/components/OperationItem/__tests__/__mocks__/mock-intersection-observer.js +42 -0
  60. package/lib/components/Overview/__tests__/Overview.test.d.ts +1 -0
  61. package/lib/components/Overview/__tests__/Overview.test.js +59 -0
  62. package/lib/components/PayloadSamples/__tests__/Example.test.d.ts +1 -0
  63. package/lib/components/PayloadSamples/__tests__/Example.test.js +36 -0
  64. package/lib/components/PayloadSamples/__tests__/ExampleValue.test.d.ts +1 -0
  65. package/lib/components/PayloadSamples/__tests__/ExampleValue.test.js +197 -0
  66. package/lib/components/PayloadSamples/__tests__/PayloadSamples.test.d.ts +1 -0
  67. package/lib/components/PayloadSamples/__tests__/PayloadSamples.test.js +38 -0
  68. package/lib/components/PropertyDetails/__tests__/Extensions.test.d.ts +1 -0
  69. package/lib/components/PropertyDetails/__tests__/Extensions.test.js +21 -0
  70. package/lib/components/PropertyDetails/__tests__/FieldDetail.test.d.ts +1 -0
  71. package/lib/components/PropertyDetails/__tests__/FieldDetail.test.js +52 -0
  72. package/lib/components/PropertyDetails/__tests__/FieldDetails.test.d.ts +1 -0
  73. package/lib/components/PropertyDetails/__tests__/FieldDetails.test.js +191 -0
  74. package/lib/components/PropertyDetails/__tests__/PropertyDetails.test.d.ts +1 -0
  75. package/lib/components/PropertyDetails/__tests__/PropertyDetails.test.js +365 -0
  76. package/lib/components/PropertyDetails/__tests__/cycleColorsByLevel.test.d.ts +1 -0
  77. package/lib/components/PropertyDetails/__tests__/cycleColorsByLevel.test.js +23 -0
  78. package/lib/components/RedoclyOpenAPIDocs/__tests__/AppProvider.test.d.ts +1 -0
  79. package/lib/components/RedoclyOpenAPIDocs/__tests__/AppProvider.test.js +16 -0
  80. package/lib/components/RedoclyOpenAPIDocs/__tests__/RedoclyOpenAPIDocs.test.d.ts +1 -0
  81. package/lib/components/RedoclyOpenAPIDocs/__tests__/RedoclyOpenAPIDocs.test.js +104 -0
  82. package/lib/components/RenderHook/__tests__/RenderHook.test.d.ts +1 -0
  83. package/lib/components/RenderHook/__tests__/RenderHook.test.js +15 -0
  84. package/lib/components/Replay/__tests__/utils.test.d.ts +1 -0
  85. package/lib/components/Replay/__tests__/utils.test.js +526 -0
  86. package/lib/components/Request/__tests__/RequestDetails.test.d.ts +1 -0
  87. package/lib/components/Request/__tests__/RequestDetails.test.js +98 -0
  88. package/lib/components/RequestSamples/__tests__/Example.test.d.ts +1 -0
  89. package/lib/components/RequestSamples/__tests__/Example.test.js +384 -0
  90. package/lib/components/RequestSamples/__tests__/RequestSamples.test.d.ts +1 -0
  91. package/lib/components/RequestSamples/__tests__/RequestSamples.test.js +226 -0
  92. package/lib/components/RequestSamples/__tests__/useCodeSamples.test.d.ts +1 -0
  93. package/lib/components/RequestSamples/__tests__/useCodeSamples.test.js +64 -0
  94. package/lib/components/ResponseSamples/__tests__/ResponseSamples.test.d.ts +1 -0
  95. package/lib/components/ResponseSamples/__tests__/ResponseSamples.test.js +29 -0
  96. package/lib/components/Responses/__tests__/OperationResponseList.test.d.ts +1 -0
  97. package/lib/components/Responses/__tests__/OperationResponseList.test.js +89 -0
  98. package/lib/components/Responses/__tests__/ResponseDetails.test.d.ts +1 -0
  99. package/lib/components/Responses/__tests__/ResponseDetails.test.js +111 -0
  100. package/lib/components/Responses/__tests__/ResponsesHeaders.test.d.ts +1 -0
  101. package/lib/components/Responses/__tests__/ResponsesHeaders.test.js +26 -0
  102. package/lib/components/Schema/__tests__/ArraySchema.test.d.ts +1 -0
  103. package/lib/components/Schema/__tests__/ArraySchema.test.js +93 -0
  104. package/lib/components/Schema/__tests__/ObjectSchema.test.d.ts +1 -0
  105. package/lib/components/Schema/__tests__/ObjectSchema.test.js +115 -0
  106. package/lib/components/Schema/__tests__/OneOfSchema.test.d.ts +1 -0
  107. package/lib/components/Schema/__tests__/OneOfSchema.test.js +33 -0
  108. package/lib/components/Schema/__tests__/Schema.test.d.ts +1 -0
  109. package/lib/components/Schema/__tests__/Schema.test.js +67 -0
  110. package/lib/components/Schema/__tests__/useOneOfLocationIdx.test.d.ts +1 -0
  111. package/lib/components/Schema/__tests__/useOneOfLocationIdx.test.js +22 -0
  112. package/lib/components/SchemaCatalogLink/__tests__/SchemaCatalogLink.test.d.ts +1 -0
  113. package/lib/components/SchemaCatalogLink/__tests__/SchemaCatalogLink.test.js +95 -0
  114. package/lib/components/Security/__tests__/Security.test.d.ts +1 -0
  115. package/lib/components/Security/__tests__/Security.test.js +38 -0
  116. package/lib/components/Security/__tests__/SecurityButton.test.d.ts +1 -0
  117. package/lib/components/Security/__tests__/SecurityButton.test.js +92 -0
  118. package/lib/components/Security/__tests__/SecurityModal.test.d.ts +1 -0
  119. package/lib/components/Security/__tests__/SecurityModal.test.js +172 -0
  120. package/lib/components/ServerList/__tests__/ServerList.test.d.ts +1 -0
  121. package/lib/components/ServerList/__tests__/ServerList.test.js +83 -0
  122. package/lib/components/Tabs/__tests__/Tabs.test.d.ts +1 -0
  123. package/lib/components/Tabs/__tests__/Tabs.test.js +27 -0
  124. package/lib/components/ViewNested/__tests__/ViewNested.test.d.ts +1 -0
  125. package/lib/components/ViewNested/__tests__/ViewNested.test.js +42 -0
  126. package/lib/components/__tests__/Samples/ExampleSwitch.test.d.ts +1 -0
  127. package/lib/components/__tests__/Samples/ExampleSwitch.test.js +45 -0
  128. package/lib/components/__tests__/Samples/use-example-key.test.d.ts +1 -0
  129. package/lib/components/__tests__/Samples/use-example-key.test.js +28 -0
  130. package/lib/components/__tests__/common/ClearButton.test.d.ts +1 -0
  131. package/lib/components/__tests__/common/ClearButton.test.js +18 -0
  132. package/lib/components/__tests__/common/Dropdown.test.d.ts +1 -0
  133. package/lib/components/__tests__/common/Dropdown.test.js +52 -0
  134. package/lib/components/__tests__/mocks/examples.d.ts +4 -0
  135. package/lib/components/__tests__/mocks/examples.js +115 -0
  136. package/lib/components/common/__tests__/Dropdown.test.d.ts +1 -0
  137. package/lib/components/common/__tests__/Dropdown.test.js +129 -0
  138. package/lib/components/common/__tests__/LinkToField.test.d.ts +1 -0
  139. package/lib/components/common/__tests__/LinkToField.test.js +39 -0
  140. package/lib/jotai/__tests__/app.test.d.ts +1 -0
  141. package/lib/jotai/__tests__/app.test.js +53 -0
  142. package/lib/models/__tests__/Callback.test.d.ts +1 -0
  143. package/lib/models/__tests__/Callback.test.js +15 -0
  144. package/lib/models/__tests__/FieldModel.test.d.ts +1 -0
  145. package/lib/models/__tests__/FieldModel.test.js +117 -0
  146. package/lib/models/__tests__/MediaContent.test.d.ts +1 -0
  147. package/lib/models/__tests__/MediaContent.test.js +105 -0
  148. package/lib/models/__tests__/Operation.test.d.ts +1 -0
  149. package/lib/models/__tests__/Operation.test.js +459 -0
  150. package/lib/models/__tests__/Response.test.d.ts +1 -0
  151. package/lib/models/__tests__/Response.test.js +221 -0
  152. package/lib/models/__tests__/Schema.circular.test.d.ts +1 -0
  153. package/lib/models/__tests__/Schema.circular.test.js +694 -0
  154. package/lib/models/__tests__/Schema.test.d.ts +1 -0
  155. package/lib/models/__tests__/Schema.test.js +1395 -0
  156. package/lib/models/__tests__/example.test.d.ts +1 -0
  157. package/lib/models/__tests__/example.test.js +90 -0
  158. package/lib/models/__tests__/group.test.d.ts +1 -0
  159. package/lib/models/__tests__/group.test.js +52 -0
  160. package/lib/models/__tests__/helpers.d.ts +5 -0
  161. package/lib/models/__tests__/helpers.js +62 -0
  162. package/lib/models/__tests__/request.test.d.ts +1 -0
  163. package/lib/models/__tests__/request.test.js +119 -0
  164. package/lib/services/__tests__/OpenAPIParser.test.d.ts +1 -0
  165. package/lib/services/__tests__/OpenAPIParser.test.js +80 -0
  166. package/lib/services/__tests__/check.test.d.ts +1 -0
  167. package/lib/services/__tests__/check.test.js +22 -0
  168. package/lib/services/__tests__/utils.test.d.ts +1 -0
  169. package/lib/services/__tests__/utils.test.js +42 -0
  170. package/lib/services/code-samples/__tests__/apply-environments.test.d.ts +1 -0
  171. package/lib/services/code-samples/__tests__/apply-environments.test.js +64 -0
  172. package/lib/services/code-samples/__tests__/build-code-samples.test.d.ts +1 -0
  173. package/lib/services/code-samples/__tests__/build-code-samples.test.js +70 -0
  174. package/lib/services/code-samples/__tests__/convertSampleToString.test.d.ts +1 -0
  175. package/lib/services/code-samples/__tests__/convertSampleToString.test.js +116 -0
  176. package/lib/services/code-samples/__tests__/generator-data-value.test.d.ts +1 -0
  177. package/lib/services/code-samples/__tests__/generator-data-value.test.js +277 -0
  178. package/lib/services/code-samples/__tests__/generator-serialized-value.test.d.ts +1 -0
  179. package/lib/services/code-samples/__tests__/generator-serialized-value.test.js +258 -0
  180. package/lib/services/code-samples/__tests__/generator-value.test.d.ts +1 -0
  181. package/lib/services/code-samples/__tests__/generator-value.test.js +273 -0
  182. package/lib/services/code-samples/__tests__/generator.test.d.ts +249 -0
  183. package/lib/services/code-samples/__tests__/generator.test.js +1201 -0
  184. package/lib/services/code-samples/__tests__/get-example-value-by-mime-type.test.d.ts +1 -0
  185. package/lib/services/code-samples/__tests__/get-example-value-by-mime-type.test.js +31 -0
  186. package/lib/services/code-samples/httpsnippet/__tests__/device-authorization.test.d.ts +1 -0
  187. package/lib/services/code-samples/httpsnippet/__tests__/device-authorization.test.js +222 -0
  188. package/lib/services/code-samples/httpsnippet/helpers/__tests__/code-helpers.test.d.ts +1 -0
  189. package/lib/services/code-samples/httpsnippet/helpers/__tests__/code-helpers.test.js +129 -0
  190. package/lib/services/code-samples/httpsnippet/helpers/__tests__/string-utility.test.d.ts +1 -0
  191. package/lib/services/code-samples/httpsnippet/helpers/__tests__/string-utility.test.js +49 -0
  192. package/lib/services/code-samples/httpsnippet/targets/csharp/__tests__/httpclient.test.d.ts +1 -0
  193. package/lib/services/code-samples/httpsnippet/targets/csharp/__tests__/httpclient.test.js +172 -0
  194. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/__tests__/httpclient.test.d.ts +1 -0
  195. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/__tests__/httpclient.test.js +172 -0
  196. package/lib/services/code-samples/httpsnippet/targets/go/__tests__/native.test.d.ts +1 -0
  197. package/lib/services/code-samples/httpsnippet/targets/go/__tests__/native.test.js +130 -0
  198. package/lib/services/code-samples/httpsnippet/targets/java/__tests__/httpclient.test.d.ts +1 -0
  199. package/lib/services/code-samples/httpsnippet/targets/java/__tests__/httpclient.test.js +191 -0
  200. package/lib/services/code-samples/httpsnippet/targets/java8/__tests__/apachehttp.test.d.ts +1 -0
  201. package/lib/services/code-samples/httpsnippet/targets/java8/__tests__/apachehttp.test.js +172 -0
  202. package/lib/services/code-samples/httpsnippet/targets/javascript/__tests__/fetch.test.d.ts +1 -0
  203. package/lib/services/code-samples/httpsnippet/targets/javascript/__tests__/fetch.test.js +85 -0
  204. package/lib/services/code-samples/httpsnippet/targets/node/__tests__/fetch.test.d.ts +1 -0
  205. package/lib/services/code-samples/httpsnippet/targets/node/__tests__/fetch.test.js +85 -0
  206. package/lib/services/code-samples/httpsnippet/targets/php/__tests__/curl.test.d.ts +1 -0
  207. package/lib/services/code-samples/httpsnippet/targets/php/__tests__/curl.test.js +126 -0
  208. package/lib/services/code-samples/httpsnippet/targets/python/__tests__/requests.test.d.ts +1 -0
  209. package/lib/services/code-samples/httpsnippet/targets/python/__tests__/requests.test.js +105 -0
  210. package/lib/services/code-samples/httpsnippet/targets/r/__tests__/httr.test.d.ts +1 -0
  211. package/lib/services/code-samples/httpsnippet/targets/r/__tests__/httr.test.js +126 -0
  212. package/lib/services/code-samples/httpsnippet/targets/ruby/__tests__/native.test.d.ts +1 -0
  213. package/lib/services/code-samples/httpsnippet/targets/ruby/__tests__/native.test.js +129 -0
  214. package/lib/services/code-samples/httpsnippet/targets/shell/__tests__/curl.test.d.ts +1 -0
  215. package/lib/services/code-samples/httpsnippet/targets/shell/__tests__/curl.test.js +129 -0
  216. package/lib/services/config-options/__tests__/helpers.test.d.ts +1 -0
  217. package/lib/services/config-options/__tests__/helpers.test.js +234 -0
  218. package/lib/services/history/__tests__/helpers.test.d.ts +1 -0
  219. package/lib/services/history/__tests__/helpers.test.js +19 -0
  220. package/lib/services/menu/__tests__/buildNestedTagsItems.test.d.ts +1 -0
  221. package/lib/services/menu/__tests__/buildNestedTagsItems.test.js +109 -0
  222. package/lib/services/menu/__tests__/builder.test.d.ts +1 -0
  223. package/lib/services/menu/__tests__/builder.test.js +307 -0
  224. package/lib/services/menu/__tests__/operation.test.d.ts +1 -0
  225. package/lib/services/menu/__tests__/operation.test.js +240 -0
  226. package/lib/services/menu/__tests__/tags.test.d.ts +1 -0
  227. package/lib/services/menu/__tests__/tags.test.js +71 -0
  228. package/lib/telemetry/RedocTelemetry.js +31 -1
  229. package/lib/telemetry/__tests__/RedocTelemetry.test.d.ts +1 -0
  230. package/lib/telemetry/__tests__/RedocTelemetry.test.js +107 -0
  231. package/lib/testProviders.d.ts +6 -0
  232. package/lib/testProviders.js +14 -0
  233. package/lib/utils/__tests__/areArraysEqual.test.d.ts +1 -0
  234. package/lib/utils/__tests__/areArraysEqual.test.js +33 -0
  235. package/lib/utils/__tests__/argValuesHelpers.d.ts +1 -0
  236. package/lib/utils/__tests__/argValuesHelpers.js +56 -0
  237. package/lib/utils/__tests__/calculateMaxLength.test.d.ts +1 -0
  238. package/lib/utils/__tests__/calculateMaxLength.test.js +119 -0
  239. package/lib/utils/__tests__/configure-helpers.test.d.ts +1 -0
  240. package/lib/utils/__tests__/configure-helpers.test.js +356 -0
  241. package/lib/utils/__tests__/convertSwagger2OpenAPI.test.d.ts +1 -0
  242. package/lib/utils/__tests__/convertSwagger2OpenAPI.test.js +392 -0
  243. package/lib/utils/__tests__/debounce.test.d.ts +1 -0
  244. package/lib/utils/__tests__/debounce.test.js +54 -0
  245. package/lib/utils/__tests__/debug.test.d.ts +1 -0
  246. package/lib/utils/__tests__/debug.test.js +23 -0
  247. package/lib/utils/__tests__/dom.test.d.ts +1 -0
  248. package/lib/utils/__tests__/dom.test.js +108 -0
  249. package/lib/utils/__tests__/getBreadcrumbs.test.d.ts +1 -0
  250. package/lib/utils/__tests__/getBreadcrumbs.test.js +98 -0
  251. package/lib/utils/__tests__/hasNestedFields.test.d.ts +1 -0
  252. package/lib/utils/__tests__/hasNestedFields.test.js +147 -0
  253. package/lib/utils/__tests__/helpers.test.d.ts +1 -0
  254. package/lib/utils/__tests__/helpers.test.js +174 -0
  255. package/lib/utils/__tests__/isMobile.test.d.ts +1 -0
  256. package/lib/utils/__tests__/isMobile.test.js +28 -0
  257. package/lib/utils/__tests__/loadAndBundleSpec.test.d.ts +1 -0
  258. package/lib/utils/__tests__/loadAndBundleSpec.test.js +22 -0
  259. package/lib/utils/__tests__/local-storage.test.d.ts +1 -0
  260. package/lib/utils/__tests__/local-storage.test.js +48 -0
  261. package/lib/utils/__tests__/object.test.d.ts +1 -0
  262. package/lib/utils/__tests__/object.test.js +45 -0
  263. package/lib/utils/__tests__/openapi.test.d.ts +1 -0
  264. package/lib/utils/__tests__/openapi.test.js +1378 -0
  265. package/lib/utils/__tests__/path.test.d.ts +1 -0
  266. package/lib/utils/__tests__/path.test.js +16 -0
  267. package/lib/utils/__tests__/queryString.test.d.ts +1 -0
  268. package/lib/utils/__tests__/queryString.test.js +60 -0
  269. package/lib/utils/__tests__/replaceVariables.test.d.ts +1 -0
  270. package/lib/utils/__tests__/replaceVariables.test.js +46 -0
  271. package/lib/utils/__tests__/simplifyAstStructure.test.d.ts +1 -0
  272. package/lib/utils/__tests__/simplifyAstStructure.test.js +26 -0
  273. package/lib/utils/__tests__/sort.test.d.ts +1 -0
  274. package/lib/utils/__tests__/sort.test.js +16 -0
  275. package/lib/utils/__tests__/string.test.d.ts +1 -0
  276. package/lib/utils/__tests__/string.test.js +16 -0
  277. package/lib/utils/__tests__/theme-helpers.test.d.ts +1 -0
  278. package/lib/utils/__tests__/theme-helpers.test.js +24 -0
  279. package/lib/utils/__tests__/url.test.d.ts +1 -0
  280. package/lib/utils/__tests__/url.test.js +134 -0
  281. package/package.json +4 -4
@@ -0,0 +1,1201 @@
1
+ import { SecurityVariablesEnvSuffix } from '@redocly/theme/core/openapi';
2
+ import { getOperation } from '../../../models/index.js';
3
+ import { getCodeSample, getDataRequest } from '../generator.js';
4
+ import { normalizeOptions } from '../../config-options/normalizeOptions.js';
5
+ import { OpenAPIParser } from '../../OpenAPIParser.js';
6
+ // Mock translate function for tests
7
+ const mockTranslate = ((key) => key);
8
+ export const testGetOperation = {
9
+ summary: 'test',
10
+ responses: { '200': {} },
11
+ parameters: [
12
+ {
13
+ name: 'id',
14
+ in: 'path',
15
+ schema: { type: 'string' },
16
+ },
17
+ ],
18
+ requestBody: {
19
+ content: {
20
+ 'application/json': {
21
+ schema: {
22
+ type: 'object',
23
+ properties: {
24
+ a: {
25
+ type: 'string',
26
+ },
27
+ b: {
28
+ type: 'string',
29
+ },
30
+ },
31
+ },
32
+ },
33
+ 'application/x-www-form-urlencoded': {
34
+ schema: {
35
+ type: 'object',
36
+ properties: {
37
+ a: {
38
+ type: 'string',
39
+ },
40
+ b: {
41
+ type: 'string',
42
+ },
43
+ },
44
+ },
45
+ },
46
+ 'application/xml': {
47
+ schema: {
48
+ type: 'object',
49
+ properties: {
50
+ a: {
51
+ type: 'string',
52
+ example: 'test-value-a',
53
+ },
54
+ b: {
55
+ type: 'object',
56
+ },
57
+ d: {
58
+ type: 'object',
59
+ },
60
+ },
61
+ },
62
+ },
63
+ 'multipart/form-data': {
64
+ schema: {
65
+ type: 'object',
66
+ properties: {
67
+ a: {
68
+ type: 'string',
69
+ },
70
+ b: {
71
+ type: 'object',
72
+ },
73
+ d: {
74
+ type: 'object',
75
+ },
76
+ g: {
77
+ type: 'object',
78
+ },
79
+ },
80
+ },
81
+ },
82
+ },
83
+ },
84
+ };
85
+ export const testPostOperation = {
86
+ summary: 'test',
87
+ responses: { '200': {} },
88
+ parameters: [
89
+ {
90
+ name: 'session_token',
91
+ in: 'cookie',
92
+ schema: { type: 'string' },
93
+ },
94
+ ],
95
+ requestBody: {
96
+ content: {
97
+ 'application/json': {
98
+ schema: {
99
+ type: 'object',
100
+ properties: {
101
+ a: {
102
+ type: 'string',
103
+ },
104
+ b: {
105
+ type: 'string',
106
+ },
107
+ },
108
+ },
109
+ },
110
+ },
111
+ },
112
+ };
113
+ export const testDefinition = {
114
+ openapi: '3.0.0',
115
+ info: { version: '1.0', title: 'Foo' },
116
+ security: [{ testApiKey: [] }, { testBasicAuth: [], testApiKey: [] }],
117
+ paths: {
118
+ '/test/{id}': {
119
+ get: testGetOperation,
120
+ post: testPostOperation,
121
+ },
122
+ },
123
+ components: {
124
+ securitySchemes: {
125
+ testApiKey: { type: 'apiKey', in: 'header', name: 'X-API-Key' },
126
+ testBasicAuth: { type: 'http', scheme: 'basic' },
127
+ },
128
+ },
129
+ };
130
+ describe('getCodeSample', () => {
131
+ const options = normalizeOptions({});
132
+ const parser = new OpenAPIParser(testDefinition, undefined, options);
133
+ const operationStore = {
134
+ activeServer: {
135
+ url: 'http://petstore.swagger.io/v2',
136
+ },
137
+ requestValues: {},
138
+ };
139
+ let operation;
140
+ beforeEach(() => {
141
+ operation = getOperation(parser, {
142
+ pointer: '#/paths/~1test~1{id}/get',
143
+ pathName: '/test/{id}',
144
+ httpVerb: 'GET',
145
+ pathParameters: [],
146
+ pathServers: [],
147
+ isWebhook: false,
148
+ isAdditionalOperation: false,
149
+ operationId: 'getPet',
150
+ defaultSampleName: 'defaultSampleName',
151
+ ...testGetOperation,
152
+ }, undefined, options, '');
153
+ vi.resetAllMocks();
154
+ });
155
+ it('should show correct code sample if operation is not visible', () => {
156
+ const operationNotVisible = getOperation(parser, {
157
+ pointer: '#/paths/~1test~1{id}/get',
158
+ pathName: '/test/{id}',
159
+ httpVerb: 'GET',
160
+ pathParameters: [],
161
+ pathServers: [],
162
+ isWebhook: false,
163
+ isAdditionalOperation: false,
164
+ operationId: 'getPet',
165
+ defaultSampleName: 'defaultSampleName',
166
+ ...testGetOperation,
167
+ }, undefined, options, '', { isCallback: false }, undefined);
168
+ const sample = getCodeSample({
169
+ lang: 'Node.js',
170
+ operation: operationNotVisible,
171
+ options: { store: operationStore },
172
+ environment: {
173
+ server: 'http://petstore.swagger.io/v2',
174
+ },
175
+ translate: mockTranslate,
176
+ });
177
+ expect(sample).toMatchInlineSnapshot(`
178
+ "import fetch from 'node-fetch';
179
+
180
+ async function run() {
181
+ const id = 'YOUR_id_PARAMETER';
182
+ const resp = await fetch(
183
+ \`http://localhost:3000/test/\${id}\`,
184
+ {
185
+ method: 'GET',
186
+ headers: {
187
+ 'Content-Type': 'application/json',
188
+ 'X-API-Key': 'YOUR_API_KEY_HERE'
189
+ },
190
+ body: JSON.stringify({
191
+ a: 'string',
192
+ b: 'string'
193
+ })
194
+ }
195
+ );
196
+
197
+ const data = await resp.json();
198
+ console.log(data);
199
+ }
200
+
201
+ run();"
202
+ `);
203
+ });
204
+ it('should properly handler query parameters', () => {
205
+ const queryParameters = [
206
+ {
207
+ name: 'q1',
208
+ in: 'query',
209
+ schema: {
210
+ type: 'string',
211
+ rawSchema: { type: 'string' },
212
+ },
213
+ style: 'form',
214
+ required: false,
215
+ example: '1',
216
+ },
217
+ {
218
+ name: 'q2',
219
+ in: 'query',
220
+ schema: {
221
+ type: 'string',
222
+ rawSchema: { type: 'string' },
223
+ },
224
+ style: 'form',
225
+ required: false,
226
+ example: '2',
227
+ },
228
+ ];
229
+ const params = {
230
+ operation: {
231
+ ...operation,
232
+ parameters: [...operation.parameters, ...queryParameters],
233
+ },
234
+ options: { store: operationStore },
235
+ environment: {
236
+ server: 'http://petstore.swagger.io/v2',
237
+ },
238
+ translate: mockTranslate,
239
+ };
240
+ const nodeSample = getCodeSample({
241
+ lang: 'Node.js',
242
+ ...params,
243
+ });
244
+ const curlSample = getCodeSample({
245
+ lang: 'curl',
246
+ ...params,
247
+ });
248
+ // no query parameters in the URL because we have a query object
249
+ expect(nodeSample).toMatchInlineSnapshot(`
250
+ "import fetch from 'node-fetch';
251
+
252
+ async function run() {
253
+ const query = new URLSearchParams({q1: '1', q2: '2'}).toString();
254
+
255
+ const id = 'YOUR_id_PARAMETER';
256
+ const resp = await fetch(
257
+ \`http://localhost:3000/test/\${id}?\${query}\`,
258
+ {
259
+ method: 'GET',
260
+ headers: {
261
+ 'Content-Type': 'application/json',
262
+ 'X-API-Key': 'YOUR_API_KEY_HERE'
263
+ },
264
+ body: JSON.stringify({
265
+ a: 'string',
266
+ b: 'string'
267
+ })
268
+ }
269
+ );
270
+
271
+ const data = await resp.json();
272
+ console.log(data);
273
+ }
274
+
275
+ run();"
276
+ `);
277
+ // query parameters in the URL because we don't have a query object
278
+ expect(curlSample).toMatchInlineSnapshot(`
279
+ "curl -i -X GET \\
280
+ 'http://localhost:3000/test/{id}?q1=1&q2=2' \\
281
+ -H 'Content-Type: application/json' \\
282
+ -H 'X-API-Key: YOUR_API_KEY_HERE' \\
283
+ -d '{
284
+ "a": "string",
285
+ "b": "string"
286
+ }'"
287
+ `);
288
+ });
289
+ it('should convert operation to proper code sample', () => {
290
+ const sample = getCodeSample({
291
+ lang: 'Node.js',
292
+ operation,
293
+ options: { store: operationStore },
294
+ environment: {
295
+ server: 'http://petstore.swagger.io/v2',
296
+ },
297
+ translate: mockTranslate,
298
+ });
299
+ expect(sample).toMatchInlineSnapshot(`
300
+ "import fetch from 'node-fetch';
301
+
302
+ async function run() {
303
+ const id = 'YOUR_id_PARAMETER';
304
+ const resp = await fetch(
305
+ \`http://localhost:3000/test/\${id}\`,
306
+ {
307
+ method: 'GET',
308
+ headers: {
309
+ 'Content-Type': 'application/json',
310
+ 'X-API-Key': 'YOUR_API_KEY_HERE'
311
+ },
312
+ body: JSON.stringify({
313
+ a: 'string',
314
+ b: 'string'
315
+ })
316
+ }
317
+ );
318
+
319
+ const data = await resp.json();
320
+ console.log(data);
321
+ }
322
+
323
+ run();"
324
+ `);
325
+ });
326
+ it('should show correct security type when multiple activeSecuritySchemeIds passed', () => {
327
+ const operationStoreWithActiveSecurityScheme = {
328
+ ...operationStore,
329
+ activeSecuritySchemeIds: ['testBasicAuth', 'testApiKey'],
330
+ };
331
+ const sample = getCodeSample({
332
+ lang: 'Node.js',
333
+ operation,
334
+ options: { store: operationStoreWithActiveSecurityScheme },
335
+ environment: {
336
+ server: 'http://petstore.swagger.io/v2',
337
+ },
338
+ translate: mockTranslate,
339
+ });
340
+ expect(sample).toMatchInlineSnapshot(`
341
+ "import fetch from 'node-fetch';
342
+
343
+ async function run() {
344
+ const id = 'YOUR_id_PARAMETER';
345
+ const resp = await fetch(
346
+ \`http://localhost:3000/test/\${id}\`,
347
+ {
348
+ method: 'GET',
349
+ headers: {
350
+ 'Content-Type': 'application/json',
351
+ 'X-API-Key': 'YOUR_API_KEY_HERE',
352
+ Authorization: 'Basic ' + Buffer.from('<username>:<password>').toString('base64')
353
+ },
354
+ body: JSON.stringify({
355
+ a: 'string',
356
+ b: 'string'
357
+ })
358
+ }
359
+ );
360
+
361
+ const data = await resp.json();
362
+ console.log(data);
363
+ }
364
+
365
+ run();"
366
+ `);
367
+ });
368
+ it('should show correct security type when single value passed in activeSecuritySchemeIds', () => {
369
+ const operationStoreWithActiveSecurityScheme = {
370
+ ...operationStore,
371
+ activeSecuritySchemeIds: ['testApiKey'],
372
+ };
373
+ const sample = getCodeSample({
374
+ lang: 'Node.js',
375
+ operation,
376
+ options: { store: operationStoreWithActiveSecurityScheme },
377
+ environment: {
378
+ server: 'http://petstore.swagger.io/v2',
379
+ },
380
+ translate: mockTranslate,
381
+ });
382
+ expect(sample).toMatchInlineSnapshot(`
383
+ "import fetch from 'node-fetch';
384
+
385
+ async function run() {
386
+ const id = 'YOUR_id_PARAMETER';
387
+ const resp = await fetch(
388
+ \`http://localhost:3000/test/\${id}\`,
389
+ {
390
+ method: 'GET',
391
+ headers: {
392
+ 'Content-Type': 'application/json',
393
+ 'X-API-Key': 'YOUR_API_KEY_HERE'
394
+ },
395
+ body: JSON.stringify({
396
+ a: 'string',
397
+ b: 'string'
398
+ })
399
+ }
400
+ );
401
+
402
+ const data = await resp.json();
403
+ console.log(data);
404
+ }
405
+
406
+ run();"
407
+ `);
408
+ });
409
+ it('should support custom path parameters values', () => {
410
+ const sample = getCodeSample({
411
+ lang: 'Node.js',
412
+ operation,
413
+ pathParams: { id: 'test-value' },
414
+ options: { store: operationStore },
415
+ environment: {
416
+ server: 'http://petstore.swagger.io/v2',
417
+ },
418
+ translate: mockTranslate,
419
+ });
420
+ expect(sample).toMatchInlineSnapshot(`
421
+ "import fetch from 'node-fetch';
422
+
423
+ async function run() {
424
+ const id = 'test-value';
425
+ const resp = await fetch(
426
+ \`http://localhost:3000/test/\${id}\`,
427
+ {
428
+ method: 'GET',
429
+ headers: {
430
+ 'Content-Type': 'application/json',
431
+ 'X-API-Key': 'YOUR_API_KEY_HERE'
432
+ },
433
+ body: JSON.stringify({
434
+ a: 'string',
435
+ b: 'string'
436
+ })
437
+ }
438
+ );
439
+
440
+ const data = await resp.json();
441
+ console.log(data);
442
+ }
443
+
444
+ run();"
445
+ `);
446
+ });
447
+ it('should support custom body properties values', () => {
448
+ const sample = getCodeSample({
449
+ lang: 'Node.js',
450
+ operation,
451
+ properties: { a: 'test-value' },
452
+ options: { store: operationStore },
453
+ environment: {
454
+ server: 'http://petstore.swagger.io/v2',
455
+ },
456
+ translate: mockTranslate,
457
+ });
458
+ expect(sample).toMatchInlineSnapshot(`
459
+ "import fetch from 'node-fetch';
460
+
461
+ async function run() {
462
+ const id = 'YOUR_id_PARAMETER';
463
+ const resp = await fetch(
464
+ \`http://localhost:3000/test/\${id}\`,
465
+ {
466
+ method: 'GET',
467
+ headers: {
468
+ 'Content-Type': 'application/json',
469
+ 'X-API-Key': 'YOUR_API_KEY_HERE'
470
+ },
471
+ body: JSON.stringify({
472
+ a: 'test-value',
473
+ b: 'string'
474
+ })
475
+ }
476
+ );
477
+
478
+ const data = await resp.json();
479
+ console.log(data);
480
+ }
481
+
482
+ run();"
483
+ `);
484
+ });
485
+ it('should work properly with form-data and url-encoded', () => {
486
+ const sample = getCodeSample({
487
+ lang: 'Node.js',
488
+ operation,
489
+ properties: { a: 'test-value' },
490
+ options: { store: operationStore, activeMimeName: 'application/x-www-form-urlencoded' },
491
+ environment: {
492
+ server: 'http://petstore.swagger.io/v2',
493
+ },
494
+ translate: mockTranslate,
495
+ });
496
+ expect(sample).toMatchInlineSnapshot(`
497
+ "import fetch from 'node-fetch';
498
+
499
+ async function run() {
500
+ const formData = {
501
+ a: 'test-value',
502
+ b: 'string'
503
+ };
504
+
505
+ const id = 'YOUR_id_PARAMETER';
506
+ const resp = await fetch(
507
+ \`http://localhost:3000/test/\${id}\`,
508
+ {
509
+ method: 'GET',
510
+ headers: {
511
+ 'Content-Type': 'application/x-www-form-urlencoded',
512
+ 'X-API-Key': 'YOUR_API_KEY_HERE'
513
+ },
514
+ body: new URLSearchParams(formData).toString()
515
+ }
516
+ );
517
+
518
+ const data = await resp.text();
519
+ console.log(data);
520
+ }
521
+
522
+ run();"
523
+ `);
524
+ });
525
+ it('should work properly with server variables', () => {
526
+ const operationStore = {
527
+ activeServer: {
528
+ url: 'https://api.{environment}',
529
+ },
530
+ requestValues: {},
531
+ };
532
+ const sample = getCodeSample({
533
+ lang: 'curl',
534
+ operation: { ...operation, servers: [{ url: 'https://api.{environment}' }] },
535
+ options: { store: operationStore, activeMimeName: 'multipart/form-data' },
536
+ environment: {
537
+ server: 'https://api.{environment}',
538
+ environment: 'production',
539
+ },
540
+ translate: mockTranslate,
541
+ });
542
+ expect(sample).toMatchInlineSnapshot(`
543
+ "curl -i -X GET \\
544
+ 'https://api.production/test/{id}' \\
545
+ -H 'Content-Type: multipart/form-data' \\
546
+ -H 'X-API-Key: YOUR_API_KEY_HERE' \\
547
+ -F a=string"
548
+ `);
549
+ });
550
+ it('should work properly with multipart/form-data', () => {
551
+ const sample = getCodeSample({
552
+ lang: 'curl',
553
+ operation,
554
+ properties: {
555
+ a: 'test-value-a',
556
+ b: { c: 'test-value-b-c' },
557
+ d: { e: { f: 'test-value-d-e-f' } },
558
+ g: { h: ['value 1', 'value 2', 'value 3'] },
559
+ f: { items: [{ name: 'John Doe', age: 100 }] },
560
+ },
561
+ options: { store: operationStore, activeMimeName: 'multipart/form-data' },
562
+ environment: {
563
+ server: 'http://petstore.swagger.io/v2',
564
+ },
565
+ translate: mockTranslate,
566
+ });
567
+ expect(sample).toMatchInlineSnapshot(`
568
+ "curl -i -X GET \\
569
+ 'http://localhost:3000/test/{id}' \\
570
+ -H 'Content-Type: multipart/form-data' \\
571
+ -H 'X-API-Key: YOUR_API_KEY_HERE' \\
572
+ -F a=test-value-a \\
573
+ -F 'b[c]=test-value-b-c' \\
574
+ -F 'd[e][f]=test-value-d-e-f' \\
575
+ -F 'g[h]=value 1' \\
576
+ -F 'g[h]=value 2' \\
577
+ -F 'g[h]=value 3' \\
578
+ -F 'f[items][0][name]=John Doe' \\
579
+ -F 'f[items][0][age]=100'"
580
+ `);
581
+ });
582
+ it('should work properly with application/xml', () => {
583
+ const sample = getCodeSample({
584
+ lang: 'curl',
585
+ operation,
586
+ properties: {
587
+ a: 'test-value-a',
588
+ b: { c: 'test-value-b-c' },
589
+ d: { e: ['value 1', 'value 2', 'value 3'] },
590
+ },
591
+ options: { store: operationStore, activeMimeName: 'application/xml' },
592
+ environment: {
593
+ server: 'http://petstore.swagger.io/v2',
594
+ },
595
+ translate: mockTranslate,
596
+ });
597
+ expect(sample).toMatchInlineSnapshot(`
598
+ "curl -i -X GET \\
599
+ 'http://localhost:3000/test/{id}' \\
600
+ -H 'Content-Type: application/xml' \\
601
+ -H 'X-API-Key: YOUR_API_KEY_HERE' \\
602
+ -d '<root>
603
+ <a>test-value-a</a>
604
+ <b></b>
605
+ <d></d>
606
+ </root>
607
+ '"
608
+ `);
609
+ });
610
+ it('should handle http security type with basic auth', () => {
611
+ const basicAuth = {
612
+ type: 'http',
613
+ scheme: 'basic',
614
+ id: 'testSchemeId',
615
+ scopes: [],
616
+ sectionId: 'sectionId',
617
+ bearerFormat: '',
618
+ flows: {},
619
+ };
620
+ const sample = getCodeSample({
621
+ lang: 'curl',
622
+ operation: {
623
+ ...operation,
624
+ security: [
625
+ {
626
+ schemes: [basicAuth],
627
+ },
628
+ ],
629
+ },
630
+ options: { store: operationStore },
631
+ environment: {
632
+ server: 'http://petstore.swagger.io/v2',
633
+ [basicAuth.id + SecurityVariablesEnvSuffix.Username]: 'test-user',
634
+ [basicAuth.id + SecurityVariablesEnvSuffix.Password]: '12345',
635
+ },
636
+ translate: mockTranslate,
637
+ });
638
+ expect(sample).toMatchInlineSnapshot(`
639
+ "curl -i -X GET \\
640
+ -u test-user:12345 \\
641
+ 'http://localhost:3000/test/{id}' \\
642
+ -H 'Content-Type: application/json' \\
643
+ -d '{
644
+ "a": "string",
645
+ "b": "string"
646
+ }'"
647
+ `);
648
+ });
649
+ it('should handle http security type with basic auth and no credentials', () => {
650
+ const sample = getCodeSample({
651
+ lang: 'curl',
652
+ operation: {
653
+ ...operation,
654
+ security: [
655
+ {
656
+ schemes: [
657
+ {
658
+ type: 'http',
659
+ scheme: 'basic',
660
+ id: 'testSchemeId',
661
+ sectionId: 'sectionId',
662
+ scopes: [],
663
+ bearerFormat: '',
664
+ flows: {},
665
+ },
666
+ ],
667
+ },
668
+ ],
669
+ },
670
+ options: { store: operationStore },
671
+ environment: {
672
+ server: 'http://petstore.swagger.io/v2',
673
+ },
674
+ translate: mockTranslate,
675
+ });
676
+ expect(sample).toMatchInlineSnapshot(`
677
+ "curl -i -X GET \\
678
+ -u <username>:<password> \\
679
+ 'http://localhost:3000/test/{id}' \\
680
+ -H 'Content-Type: application/json' \\
681
+ -d '{
682
+ "a": "string",
683
+ "b": "string"
684
+ }'"
685
+ `);
686
+ });
687
+ it('should handle http security type with bearer auth', () => {
688
+ const bearerAuth = {
689
+ type: 'http',
690
+ scheme: 'bearer',
691
+ id: 'testSchemeId',
692
+ scopes: [],
693
+ sectionId: 'sectionId',
694
+ bearerFormat: '',
695
+ flows: {},
696
+ };
697
+ const sample = getCodeSample({
698
+ lang: 'curl',
699
+ operation: {
700
+ ...operation,
701
+ security: [
702
+ {
703
+ schemes: [bearerAuth],
704
+ },
705
+ ],
706
+ },
707
+ options: { store: operationStore },
708
+ environment: {
709
+ server: 'http://petstore.swagger.io/v2',
710
+ [bearerAuth.id + SecurityVariablesEnvSuffix.Token]: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva',
711
+ },
712
+ translate: mockTranslate,
713
+ });
714
+ expect(sample).toMatchInlineSnapshot(`
715
+ "curl -i -X GET \\
716
+ 'http://localhost:3000/test/{id}' \\
717
+ -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6Ikpva' \\
718
+ -H 'Content-Type: application/json' \\
719
+ -d '{
720
+ "a": "string",
721
+ "b": "string"
722
+ }'"
723
+ `);
724
+ });
725
+ it('should handle http security type with bearer auth and no token provided', () => {
726
+ const sample = getCodeSample({
727
+ lang: 'curl',
728
+ operation: {
729
+ ...operation,
730
+ security: [
731
+ {
732
+ schemes: [
733
+ {
734
+ type: 'http',
735
+ scheme: 'bearer',
736
+ id: 'testSchemeId',
737
+ sectionId: 'sectionId',
738
+ scopes: [],
739
+ bearerFormat: '',
740
+ flows: {},
741
+ },
742
+ ],
743
+ },
744
+ ],
745
+ },
746
+ options: { store: operationStore },
747
+ environment: {
748
+ server: 'http://petstore.swagger.io/v2',
749
+ },
750
+ translate: mockTranslate,
751
+ });
752
+ expect(sample).toMatchInlineSnapshot(`
753
+ "curl -i -X GET \\
754
+ 'http://localhost:3000/test/{id}' \\
755
+ -H 'Authorization: Bearer <YOUR_TOKEN_HERE>' \\
756
+ -H 'Content-Type: application/json' \\
757
+ -d '{
758
+ "a": "string",
759
+ "b": "string"
760
+ }'"
761
+ `);
762
+ });
763
+ it('should handle basic auth with server specific credentials', () => {
764
+ const sample = getCodeSample({
765
+ lang: 'curl',
766
+ operation: {
767
+ ...operation,
768
+ security: [
769
+ {
770
+ schemes: [
771
+ {
772
+ type: 'http',
773
+ scheme: 'basic',
774
+ id: 'testSchemeId',
775
+ sectionId: 'sectionId',
776
+ scopes: [],
777
+ bearerFormat: '',
778
+ flows: {},
779
+ serverValues: {
780
+ 'http://petstore.swagger.io/v2': {
781
+ 'x-defaultUsername': 'test-user',
782
+ 'x-defaultPassword': '12345',
783
+ },
784
+ 'http://dev-petstore.swagger.io/v2': {
785
+ 'x-defaultUsername': 'test-user-dev',
786
+ 'x-defaultPassword': '12345-dev',
787
+ },
788
+ },
789
+ },
790
+ ],
791
+ },
792
+ ],
793
+ },
794
+ options: { store: operationStore },
795
+ environment: {
796
+ server: 'http://petstore.swagger.io/v2',
797
+ },
798
+ translate: mockTranslate,
799
+ });
800
+ expect(sample).toMatchInlineSnapshot(`
801
+ "curl -i -X GET \\
802
+ -u test-user:12345 \\
803
+ 'http://localhost:3000/test/{id}' \\
804
+ -H 'Content-Type: application/json' \\
805
+ -d '{
806
+ "a": "string",
807
+ "b": "string"
808
+ }'"
809
+ `);
810
+ });
811
+ it('should handle server specific path parameter', () => {
812
+ const sample = getCodeSample({
813
+ lang: 'curl',
814
+ operation: {
815
+ ...operation,
816
+ parameters: [
817
+ {
818
+ name: 'id',
819
+ in: 'path',
820
+ example: 'test-value',
821
+ serverValues: {
822
+ 'http://petstore.swagger.io/v2': {
823
+ example: 'test-value-env',
824
+ },
825
+ },
826
+ },
827
+ ],
828
+ },
829
+ options: { store: operationStore },
830
+ environment: {
831
+ server: 'http://petstore.swagger.io/v2',
832
+ },
833
+ translate: mockTranslate,
834
+ });
835
+ expect(sample).toMatchInlineSnapshot(`
836
+ "curl -i -X GET \\
837
+ http://localhost:3000/test/test-value-env \\
838
+ -H 'Content-Type: application/json' \\
839
+ -H 'X-API-Key: YOUR_API_KEY_HERE' \\
840
+ -d '{
841
+ "a": "string",
842
+ "b": "string"
843
+ }'"
844
+ `);
845
+ });
846
+ it('should handle server specific query parameter', () => {
847
+ const queryParameter = {
848
+ name: 'page',
849
+ in: 'query',
850
+ schema: {
851
+ type: 'string',
852
+ rawSchema: { type: 'string' },
853
+ },
854
+ style: 'form',
855
+ required: false,
856
+ example: '2',
857
+ serverValues: {
858
+ 'http://petstore.swagger.io/v2': {
859
+ example: '10',
860
+ },
861
+ },
862
+ };
863
+ const sample = getCodeSample({
864
+ lang: 'curl',
865
+ operation: {
866
+ ...operation,
867
+ parameters: [...operation.parameters, queryParameter],
868
+ },
869
+ options: { store: operationStore },
870
+ environment: {
871
+ server: 'http://petstore.swagger.io/v2',
872
+ },
873
+ translate: mockTranslate,
874
+ });
875
+ expect(sample).toMatchInlineSnapshot(`
876
+ "curl -i -X GET \\
877
+ 'http://localhost:3000/test/{id}?page=10' \\
878
+ -H 'Content-Type: application/json' \\
879
+ -H 'X-API-Key: YOUR_API_KEY_HERE' \\
880
+ -d '{
881
+ "a": "string",
882
+ "b": "string"
883
+ }'"
884
+ `);
885
+ });
886
+ it('should handle server specific cookie parameters', () => {
887
+ const postOperation = getOperation(parser, {
888
+ pointer: '#/paths/~1test~1{id}/post',
889
+ pathName: '/test/{id}',
890
+ httpVerb: 'POST',
891
+ pathParameters: [],
892
+ pathServers: [],
893
+ isWebhook: false,
894
+ isAdditionalOperation: false,
895
+ operationId: 'addPet',
896
+ defaultSampleName: 'defaultSampleName',
897
+ ...testPostOperation,
898
+ }, undefined, options, '', { isCallback: false }, undefined);
899
+ const sample = getCodeSample({
900
+ lang: 'curl',
901
+ operation: {
902
+ ...postOperation,
903
+ parameters: [
904
+ {
905
+ name: 'session_token',
906
+ in: 'cookie',
907
+ example: 'test-value',
908
+ style: 'form',
909
+ serverValues: {
910
+ 'http://petstore.swagger.io/v2': {
911
+ example: 'test-value-env',
912
+ },
913
+ },
914
+ },
915
+ ],
916
+ },
917
+ options: { store: operationStore },
918
+ environment: {
919
+ server: 'http://petstore.swagger.io/v2',
920
+ },
921
+ translate: mockTranslate,
922
+ });
923
+ expect(sample).toMatchInlineSnapshot(`
924
+ "curl -i -X POST \\
925
+ 'http://localhost:3000/test/{id}' \\
926
+ -H 'Content-Type: application/json' \\
927
+ -H 'X-API-Key: YOUR_API_KEY_HERE' \\
928
+ -b session_token=test-value-env \\
929
+ -d '{
930
+ "a": "string",
931
+ "b": "string"
932
+ }'"
933
+ `);
934
+ });
935
+ it('should handle server specific header parameters', () => {
936
+ const postOperation = getOperation(parser, {
937
+ pointer: '#/paths/~1test~1{id}/post',
938
+ pathName: '/test/{id}',
939
+ httpVerb: 'POST',
940
+ pathParameters: [],
941
+ pathServers: [],
942
+ isWebhook: false,
943
+ isAdditionalOperation: false,
944
+ operationId: 'addPet',
945
+ defaultSampleName: 'defaultSampleName',
946
+ ...testPostOperation,
947
+ }, undefined, options, '', { isCallback: false }, undefined);
948
+ const sample = getCodeSample({
949
+ lang: 'curl',
950
+ operation: {
951
+ ...postOperation,
952
+ parameters: [
953
+ {
954
+ name: 'User-Agent',
955
+ in: 'header',
956
+ example: 'test-value',
957
+ style: 'form',
958
+ serverValues: {
959
+ 'http://petstore.swagger.io/v2': {
960
+ example: 'test-value-env',
961
+ },
962
+ },
963
+ },
964
+ ],
965
+ },
966
+ options: { store: operationStore },
967
+ environment: {
968
+ server: 'http://petstore.swagger.io/v2',
969
+ },
970
+ translate: mockTranslate,
971
+ });
972
+ expect(sample).toMatchInlineSnapshot(`
973
+ "curl -i -X POST \\
974
+ 'http://localhost:3000/test/{id}' \\
975
+ -H 'Content-Type: application/json' \\
976
+ -H 'User-Agent: test-value-env' \\
977
+ -H 'X-API-Key: YOUR_API_KEY_HERE' \\
978
+ -d '{
979
+ "a": "string",
980
+ "b": "string"
981
+ }'"
982
+ `);
983
+ });
984
+ it('should handle variable interpolation', () => {
985
+ const operationStoreWithNestedVars = {
986
+ activeServer: {
987
+ url: 'https://api.{domain}',
988
+ },
989
+ requestValues: {},
990
+ };
991
+ const testParams = {
992
+ operation,
993
+ pathParams: { id: 'test-value' },
994
+ options: { store: operationStoreWithNestedVars },
995
+ environment: {
996
+ server: 'https://api.{domain}',
997
+ domain: 'example.hxrenew.com',
998
+ oauth2_base: 'https://accounts.{domain}/oauth2',
999
+ },
1000
+ translate: mockTranslate,
1001
+ };
1002
+ const jsSample = getCodeSample({
1003
+ lang: 'JavaScript',
1004
+ ...testParams,
1005
+ });
1006
+ expect(jsSample).toMatchInlineSnapshot(`
1007
+ "const id = 'test-value';
1008
+ const domain = 'example.hxrenew.com';
1009
+ const oauth2Base = \`https://accounts.\${domain}/oauth2\`;
1010
+ const resp = await fetch(
1011
+ \`http://localhost:3000/test/\${id}\`,
1012
+ {
1013
+ method: 'GET',
1014
+ headers: {
1015
+ 'Content-Type': 'application/json',
1016
+ 'X-API-Key': 'YOUR_API_KEY_HERE'
1017
+ },
1018
+ body: JSON.stringify({
1019
+ a: 'string',
1020
+ b: 'string'
1021
+ })
1022
+ }
1023
+ );
1024
+
1025
+ const data = await resp.json();
1026
+ console.log(data);"
1027
+ `);
1028
+ const pythonSample = getCodeSample({
1029
+ lang: 'Python',
1030
+ ...testParams,
1031
+ });
1032
+ expect(pythonSample).toMatchInlineSnapshot(`
1033
+ "import requests
1034
+
1035
+ id = "test-value"
1036
+ domain = "example.hxrenew.com"
1037
+ oauth_2_base = "https://accounts." + domain + "/oauth2"
1038
+ url = "http://localhost:3000/test/" + id
1039
+
1040
+ payload = {
1041
+ "a": "string",
1042
+ "b": "string"
1043
+ }
1044
+
1045
+ headers = {
1046
+ "Content-Type": "application/json",
1047
+ "X-API-Key": "YOUR_API_KEY_HERE"
1048
+ }
1049
+
1050
+ response = requests.get(url, json=payload, headers=headers)
1051
+
1052
+ data = response.json()
1053
+ print(data)"
1054
+ `);
1055
+ const phpSample = getCodeSample({
1056
+ lang: 'PHP',
1057
+ ...testParams,
1058
+ });
1059
+ expect(phpSample).toMatchInlineSnapshot(`
1060
+ "/**
1061
+ * Requires libcurl
1062
+ */
1063
+
1064
+ const id = "test-value";
1065
+ const domain = "example.hxrenew.com";
1066
+ const oauth2Base = "https://accounts." . domain . "/oauth2";
1067
+ $curl = curl_init();
1068
+
1069
+ $payload = array(
1070
+ "a" => "string",
1071
+ "b" => "string"
1072
+ );
1073
+
1074
+ curl_setopt_array($curl, [
1075
+ CURLOPT_HTTPHEADER => [
1076
+ "Content-Type: application/json",
1077
+ "X-API-Key: YOUR_API_KEY_HERE"
1078
+ ],
1079
+ CURLOPT_POSTFIELDS => json_encode($payload),
1080
+ CURLOPT_PORT => "3000",
1081
+ CURLOPT_URL => "http://localhost:3000/test/" . id,
1082
+ CURLOPT_RETURNTRANSFER => true,
1083
+ CURLOPT_CUSTOMREQUEST => "GET",
1084
+ ]);
1085
+
1086
+ $response = curl_exec($curl);
1087
+ $error = curl_error($curl);
1088
+
1089
+ curl_close($curl);
1090
+
1091
+ if ($error) {
1092
+ echo "cURL Error #:" . $error;
1093
+ } else {
1094
+ echo $response;
1095
+ }"
1096
+ `);
1097
+ });
1098
+ it('should handle querystring parameter with form-urlencoded content and object value', () => {
1099
+ const querystringParameter = {
1100
+ name: 'filter',
1101
+ in: 'querystring',
1102
+ content: {
1103
+ 'application/x-www-form-urlencoded': {
1104
+ schema: {
1105
+ type: 'object',
1106
+ properties: {
1107
+ name: { type: 'string' },
1108
+ age: { type: 'number' },
1109
+ },
1110
+ rawSchema: {
1111
+ type: 'object',
1112
+ properties: {
1113
+ name: { type: 'string' },
1114
+ age: { type: 'number' },
1115
+ },
1116
+ },
1117
+ },
1118
+ },
1119
+ },
1120
+ required: false,
1121
+ };
1122
+ const parser = new OpenAPIParser({
1123
+ openapi: '3.2.0',
1124
+ info: { title: 'Test', version: '1.0' },
1125
+ paths: {
1126
+ '/test': {
1127
+ get: {
1128
+ summary: 'test',
1129
+ responses: { '200': {} },
1130
+ parameters: [querystringParameter],
1131
+ },
1132
+ },
1133
+ },
1134
+ }, undefined, options);
1135
+ const testOperation = getOperation(parser, {
1136
+ pointer: '#/paths/~1test/get',
1137
+ pathName: '/test',
1138
+ httpVerb: 'GET',
1139
+ pathParameters: [],
1140
+ pathServers: [],
1141
+ isWebhook: false,
1142
+ isAdditionalOperation: false,
1143
+ operationId: 'testQuerystring',
1144
+ defaultSampleName: 'defaultSampleName',
1145
+ summary: 'test',
1146
+ responses: { '200': {} },
1147
+ parameters: [querystringParameter],
1148
+ }, undefined, options, '');
1149
+ const sample = getCodeSample({
1150
+ lang: 'curl',
1151
+ operation: testOperation,
1152
+ options: { store: operationStore },
1153
+ environment: {
1154
+ server: 'http://petstore.swagger.io/v2',
1155
+ },
1156
+ translate: mockTranslate,
1157
+ });
1158
+ expect(sample).toContain('name=');
1159
+ expect(sample).toContain('age=');
1160
+ });
1161
+ });
1162
+ describe('getDataRequest', () => {
1163
+ it('should return false when exampleValue is falsy', () => {
1164
+ expect(getDataRequest(null, {})).toBe(false);
1165
+ expect(getDataRequest(undefined, {})).toBe(false);
1166
+ expect(getDataRequest('', {})).toBe(false);
1167
+ });
1168
+ it('should return exampleValue when it is an object with properties and empty properties param', () => {
1169
+ const example = { foo: 'bar' };
1170
+ expect(getDataRequest(example, {})).toEqual(example);
1171
+ });
1172
+ it('should merge exampleValue object with properties', () => {
1173
+ const example = { foo: 'bar' };
1174
+ const props = { baz: 'qux' };
1175
+ expect(getDataRequest(example, props)).toEqual({
1176
+ foo: 'bar',
1177
+ baz: 'qux',
1178
+ });
1179
+ });
1180
+ it('should parse JSON string and merge with properties', () => {
1181
+ const example = '{"foo":"bar"}';
1182
+ const props = { baz: 'qux' };
1183
+ expect(getDataRequest(example, props)).toEqual({
1184
+ foo: 'bar',
1185
+ baz: 'qux',
1186
+ });
1187
+ });
1188
+ it('should return false when JSON parsing fails', () => {
1189
+ const example = 'invalid json';
1190
+ const props = { baz: 'qux' };
1191
+ expect(getDataRequest(example, props)).toBe(false);
1192
+ });
1193
+ it('should merge arrays using arrayMergeStrategy', () => {
1194
+ const example = { arr: [1, 2] };
1195
+ const props = { arr: [3, 4] };
1196
+ expect(getDataRequest(example, props)).toEqual({
1197
+ arr: [3, 4], //it is correct, because arrayMergeStrategy returns second array
1198
+ });
1199
+ });
1200
+ });
1201
+ //# sourceMappingURL=generator.test.js.map