@redocly/openapi-docs 3.24.1 → 3.25.0-next.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 (283) hide show
  1. package/dist/{redocly-openapi-docs.min.AiChatProvider-j-VDfFJ9.js → redocly-openapi-docs.min.AiChatProvider-CDMc3dS6.js} +1 -1
  2. package/dist/{redocly-openapi-docs.min.AiChatSqliteDBStorage-BBRBmffc.js → redocly-openapi-docs.min.AiChatSqliteDBStorage-BopXqcPv.js} +1 -1
  3. package/dist/{redocly-openapi-docs.min.AiPanel-DTzHqAiI.js → redocly-openapi-docs.min.AiPanel-DkXOeLs5.js} +1 -1
  4. package/dist/redocly-openapi-docs.min.FileWatcher-DMjNW66W.js +1 -0
  5. package/dist/{redocly-openapi-docs.min.SemanticSearchService-DNFOPBZK.js → redocly-openapi-docs.min.SemanticSearchService-DbpnWseN.js} +1 -1
  6. package/dist/{redocly-openapi-docs.min.SqliteDBStorage-Dy40Vq04.js → redocly-openapi-docs.min.SqliteDBStorage-ak3Zqgtw.js} +1 -1
  7. package/dist/{redocly-openapi-docs.min.TauriFileSystemAdapter-CpViFqJQ.js → redocly-openapi-docs.min.TauriFileSystemAdapter-Dl2fY3am.js} +1 -1
  8. package/dist/{redocly-openapi-docs.min.TauriRootStorage-TCUrp2uB.js → redocly-openapi-docs.min.TauriRootStorage-m4plsfqx.js} +1 -1
  9. package/dist/{redocly-openapi-docs.min.ai-chat-mappers-CmX-8902.js → redocly-openapi-docs.min.ai-chat-mappers-Dg8U8w8r.js} +1 -1
  10. package/dist/{redocly-openapi-docs.min.external-resolver-BkceRyB4.js → redocly-openapi-docs.min.external-resolver-Db7hewsm.js} +1 -1
  11. package/dist/{redocly-openapi-docs.min.index-BCcol5vU.js → redocly-openapi-docs.min.index-B5-R6EGY.js} +1 -1
  12. package/dist/{redocly-openapi-docs.min.index-CmXZfuiZ.js → redocly-openapi-docs.min.index-D9U4Tk7n.js} +1320 -1213
  13. package/dist/{redocly-openapi-docs.min.index-DVWw0ICA.js → redocly-openapi-docs.min.index-DeHk4n2z.js} +1 -1
  14. package/dist/{redocly-openapi-docs.min.index-C6uU_v-b.js → redocly-openapi-docs.min.index-EVRmC_IQ.js} +1 -1
  15. package/dist/redocly-openapi-docs.min.js +1 -1
  16. package/dist/{redocly-openapi-docs.min.lint-2YpbCz3r.js → redocly-openapi-docs.min.lint-PvmGrAK3.js} +2 -2
  17. package/dist/{redocly-openapi-docs.min.lint-graphql-Bgfcu2tP.js → redocly-openapi-docs.min.lint-graphql-CMMhYVr_.js} +1 -1
  18. package/dist/{redocly-openapi-docs.min.respect-run-Ct8taisL.js → redocly-openapi-docs.min.respect-run-DgsYdmxw.js} +1 -1
  19. package/dist/{redocly-openapi-docs.min.standalone-BPCdJgtH.js → redocly-openapi-docs.min.standalone-D9becCWS.js} +708 -673
  20. package/dist/redocly-openapi-docs.min.tauri-path-Bv9A5DVf.js +1 -0
  21. package/dist/{redocly-openapi-docs.min.useAiChatQueries-t8oy8jik.js → redocly-openapi-docs.min.useAiChatQueries-Cb-1pa0w.js} +2 -2
  22. package/lib/telemetry/RedocTelemetry.js +1 -31
  23. package/package.json +5 -5
  24. package/dist/redocly-openapi-docs.min.FileWatcher-DDoyaS7A.js +0 -1
  25. package/dist/redocly-openapi-docs.min.tauri-path-CmqBCxGb.js +0 -1
  26. package/lib/components/ApiInfo/__tests__/ApiInfo.test.d.ts +0 -1
  27. package/lib/components/ApiInfo/__tests__/ApiInfo.test.js +0 -46
  28. package/lib/components/Callbacks/__tests__/Callbacks.test.d.ts +0 -1
  29. package/lib/components/Callbacks/__tests__/Callbacks.test.js +0 -46
  30. package/lib/components/Content/__tests__/useAutoScroll.test.d.ts +0 -1
  31. package/lib/components/Content/__tests__/useAutoScroll.test.js +0 -88
  32. package/lib/components/ContentItem/__tests__/useIsExpanded.test.d.ts +0 -1
  33. package/lib/components/ContentItem/__tests__/useIsExpanded.test.js +0 -123
  34. package/lib/components/ContentItems/__tests__/Items.test.d.ts +0 -1
  35. package/lib/components/ContentItems/__tests__/Items.test.js +0 -66
  36. package/lib/components/ContentItems/__tests__/VirtualList.test.d.ts +0 -1
  37. package/lib/components/ContentItems/__tests__/VirtualList.test.js +0 -135
  38. package/lib/components/Discriminator/__tests__/DiscriminatorDropdown.test.d.ts +0 -1
  39. package/lib/components/Discriminator/__tests__/DiscriminatorDropdown.test.js +0 -63
  40. package/lib/components/Download/__tests__/DownloadSpecification.test.d.ts +0 -1
  41. package/lib/components/Download/__tests__/DownloadSpecification.test.js +0 -52
  42. package/lib/components/ExpandAllButton/__tests__/ExpandAllButton.test.d.ts +0 -1
  43. package/lib/components/ExpandAllButton/__tests__/ExpandAllButton.test.js +0 -60
  44. package/lib/components/ExpandAllButton/__tests__/helpers.test.d.ts +0 -1
  45. package/lib/components/ExpandAllButton/__tests__/helpers.test.js +0 -133
  46. package/lib/components/Language/__tests__/LanguageDropdown.test.d.ts +0 -1
  47. package/lib/components/Language/__tests__/LanguageDropdown.test.js +0 -23
  48. package/lib/components/Markdown/__tests__/Markdown.test.d.ts +0 -1
  49. package/lib/components/Markdown/__tests__/Markdown.test.js +0 -34
  50. package/lib/components/McpOverview/__tests__/McpOverview.test.d.ts +0 -1
  51. package/lib/components/McpOverview/__tests__/McpOverview.test.js +0 -66
  52. package/lib/components/McpTool/__tests__/McpPrompt.test.d.ts +0 -1
  53. package/lib/components/McpTool/__tests__/McpPrompt.test.js +0 -57
  54. package/lib/components/McpTool/__tests__/McpResource.test.d.ts +0 -1
  55. package/lib/components/McpTool/__tests__/McpResource.test.js +0 -81
  56. package/lib/components/McpTool/__tests__/McpTool.test.d.ts +0 -1
  57. package/lib/components/McpTool/__tests__/McpTool.test.js +0 -82
  58. package/lib/components/MediaTypeSwitch/__tests__/MediaTypesSwitch.test.d.ts +0 -1
  59. package/lib/components/MediaTypeSwitch/__tests__/MediaTypesSwitch.test.js +0 -79
  60. package/lib/components/OperationItem/__tests__/OperationItem.test.d.ts +0 -1
  61. package/lib/components/OperationItem/__tests__/OperationItem.test.js +0 -70
  62. package/lib/components/OperationItem/__tests__/__mocks__/mock-intersection-observer.d.ts +0 -16
  63. package/lib/components/OperationItem/__tests__/__mocks__/mock-intersection-observer.js +0 -42
  64. package/lib/components/Overview/__tests__/Overview.test.d.ts +0 -1
  65. package/lib/components/Overview/__tests__/Overview.test.js +0 -59
  66. package/lib/components/PayloadSamples/__tests__/Example.test.d.ts +0 -1
  67. package/lib/components/PayloadSamples/__tests__/Example.test.js +0 -36
  68. package/lib/components/PayloadSamples/__tests__/ExampleValue.test.d.ts +0 -1
  69. package/lib/components/PayloadSamples/__tests__/ExampleValue.test.js +0 -197
  70. package/lib/components/PayloadSamples/__tests__/PayloadSamples.test.d.ts +0 -1
  71. package/lib/components/PayloadSamples/__tests__/PayloadSamples.test.js +0 -38
  72. package/lib/components/PropertyDetails/__tests__/Extensions.test.d.ts +0 -1
  73. package/lib/components/PropertyDetails/__tests__/Extensions.test.js +0 -21
  74. package/lib/components/PropertyDetails/__tests__/FieldDetail.test.d.ts +0 -1
  75. package/lib/components/PropertyDetails/__tests__/FieldDetail.test.js +0 -52
  76. package/lib/components/PropertyDetails/__tests__/FieldDetails.test.d.ts +0 -1
  77. package/lib/components/PropertyDetails/__tests__/FieldDetails.test.js +0 -191
  78. package/lib/components/PropertyDetails/__tests__/PropertyDetails.test.d.ts +0 -1
  79. package/lib/components/PropertyDetails/__tests__/PropertyDetails.test.js +0 -365
  80. package/lib/components/PropertyDetails/__tests__/cycleColorsByLevel.test.d.ts +0 -1
  81. package/lib/components/PropertyDetails/__tests__/cycleColorsByLevel.test.js +0 -23
  82. package/lib/components/RedoclyOpenAPIDocs/__tests__/AppProvider.test.d.ts +0 -1
  83. package/lib/components/RedoclyOpenAPIDocs/__tests__/AppProvider.test.js +0 -16
  84. package/lib/components/RedoclyOpenAPIDocs/__tests__/RedoclyOpenAPIDocs.test.d.ts +0 -1
  85. package/lib/components/RedoclyOpenAPIDocs/__tests__/RedoclyOpenAPIDocs.test.js +0 -104
  86. package/lib/components/RenderHook/__tests__/RenderHook.test.d.ts +0 -1
  87. package/lib/components/RenderHook/__tests__/RenderHook.test.js +0 -15
  88. package/lib/components/Replay/__tests__/utils.test.d.ts +0 -1
  89. package/lib/components/Replay/__tests__/utils.test.js +0 -526
  90. package/lib/components/Request/__tests__/RequestDetails.test.d.ts +0 -1
  91. package/lib/components/Request/__tests__/RequestDetails.test.js +0 -98
  92. package/lib/components/RequestSamples/__tests__/Example.test.d.ts +0 -1
  93. package/lib/components/RequestSamples/__tests__/Example.test.js +0 -384
  94. package/lib/components/RequestSamples/__tests__/RequestSamples.test.d.ts +0 -1
  95. package/lib/components/RequestSamples/__tests__/RequestSamples.test.js +0 -226
  96. package/lib/components/RequestSamples/__tests__/useCodeSamples.test.d.ts +0 -1
  97. package/lib/components/RequestSamples/__tests__/useCodeSamples.test.js +0 -64
  98. package/lib/components/ResponseSamples/__tests__/ResponseSamples.test.d.ts +0 -1
  99. package/lib/components/ResponseSamples/__tests__/ResponseSamples.test.js +0 -29
  100. package/lib/components/Responses/__tests__/OperationResponseList.test.d.ts +0 -1
  101. package/lib/components/Responses/__tests__/OperationResponseList.test.js +0 -89
  102. package/lib/components/Responses/__tests__/ResponseDetails.test.d.ts +0 -1
  103. package/lib/components/Responses/__tests__/ResponseDetails.test.js +0 -111
  104. package/lib/components/Responses/__tests__/ResponsesHeaders.test.d.ts +0 -1
  105. package/lib/components/Responses/__tests__/ResponsesHeaders.test.js +0 -26
  106. package/lib/components/Schema/__tests__/ArraySchema.test.d.ts +0 -1
  107. package/lib/components/Schema/__tests__/ArraySchema.test.js +0 -93
  108. package/lib/components/Schema/__tests__/ObjectSchema.test.d.ts +0 -1
  109. package/lib/components/Schema/__tests__/ObjectSchema.test.js +0 -115
  110. package/lib/components/Schema/__tests__/OneOfSchema.test.d.ts +0 -1
  111. package/lib/components/Schema/__tests__/OneOfSchema.test.js +0 -33
  112. package/lib/components/Schema/__tests__/Schema.test.d.ts +0 -1
  113. package/lib/components/Schema/__tests__/Schema.test.js +0 -67
  114. package/lib/components/Schema/__tests__/useOneOfLocationIdx.test.d.ts +0 -1
  115. package/lib/components/Schema/__tests__/useOneOfLocationIdx.test.js +0 -22
  116. package/lib/components/SchemaCatalogLink/__tests__/SchemaCatalogLink.test.d.ts +0 -1
  117. package/lib/components/SchemaCatalogLink/__tests__/SchemaCatalogLink.test.js +0 -95
  118. package/lib/components/Security/__tests__/Security.test.d.ts +0 -1
  119. package/lib/components/Security/__tests__/Security.test.js +0 -38
  120. package/lib/components/Security/__tests__/SecurityButton.test.d.ts +0 -1
  121. package/lib/components/Security/__tests__/SecurityButton.test.js +0 -92
  122. package/lib/components/Security/__tests__/SecurityModal.test.d.ts +0 -1
  123. package/lib/components/Security/__tests__/SecurityModal.test.js +0 -172
  124. package/lib/components/ServerList/__tests__/ServerList.test.d.ts +0 -1
  125. package/lib/components/ServerList/__tests__/ServerList.test.js +0 -83
  126. package/lib/components/Tabs/__tests__/Tabs.test.d.ts +0 -1
  127. package/lib/components/Tabs/__tests__/Tabs.test.js +0 -27
  128. package/lib/components/ViewNested/__tests__/ViewNested.test.d.ts +0 -1
  129. package/lib/components/ViewNested/__tests__/ViewNested.test.js +0 -42
  130. package/lib/components/__tests__/Samples/ExampleSwitch.test.d.ts +0 -1
  131. package/lib/components/__tests__/Samples/ExampleSwitch.test.js +0 -45
  132. package/lib/components/__tests__/Samples/use-example-key.test.d.ts +0 -1
  133. package/lib/components/__tests__/Samples/use-example-key.test.js +0 -28
  134. package/lib/components/__tests__/common/ClearButton.test.d.ts +0 -1
  135. package/lib/components/__tests__/common/ClearButton.test.js +0 -18
  136. package/lib/components/__tests__/common/Dropdown.test.d.ts +0 -1
  137. package/lib/components/__tests__/common/Dropdown.test.js +0 -52
  138. package/lib/components/__tests__/mocks/examples.d.ts +0 -4
  139. package/lib/components/__tests__/mocks/examples.js +0 -115
  140. package/lib/components/common/__tests__/Dropdown.test.d.ts +0 -1
  141. package/lib/components/common/__tests__/Dropdown.test.js +0 -129
  142. package/lib/components/common/__tests__/LinkToField.test.d.ts +0 -1
  143. package/lib/components/common/__tests__/LinkToField.test.js +0 -39
  144. package/lib/jotai/__tests__/app.test.d.ts +0 -1
  145. package/lib/jotai/__tests__/app.test.js +0 -53
  146. package/lib/models/__tests__/Callback.test.d.ts +0 -1
  147. package/lib/models/__tests__/Callback.test.js +0 -15
  148. package/lib/models/__tests__/FieldModel.test.d.ts +0 -1
  149. package/lib/models/__tests__/FieldModel.test.js +0 -117
  150. package/lib/models/__tests__/MediaContent.test.d.ts +0 -1
  151. package/lib/models/__tests__/MediaContent.test.js +0 -105
  152. package/lib/models/__tests__/Operation.test.d.ts +0 -1
  153. package/lib/models/__tests__/Operation.test.js +0 -459
  154. package/lib/models/__tests__/Response.test.d.ts +0 -1
  155. package/lib/models/__tests__/Response.test.js +0 -221
  156. package/lib/models/__tests__/Schema.circular.test.d.ts +0 -1
  157. package/lib/models/__tests__/Schema.circular.test.js +0 -694
  158. package/lib/models/__tests__/Schema.test.d.ts +0 -1
  159. package/lib/models/__tests__/Schema.test.js +0 -1395
  160. package/lib/models/__tests__/example.test.d.ts +0 -1
  161. package/lib/models/__tests__/example.test.js +0 -90
  162. package/lib/models/__tests__/group.test.d.ts +0 -1
  163. package/lib/models/__tests__/group.test.js +0 -52
  164. package/lib/models/__tests__/helpers.d.ts +0 -5
  165. package/lib/models/__tests__/helpers.js +0 -62
  166. package/lib/models/__tests__/request.test.d.ts +0 -1
  167. package/lib/models/__tests__/request.test.js +0 -119
  168. package/lib/services/__tests__/OpenAPIParser.test.d.ts +0 -1
  169. package/lib/services/__tests__/OpenAPIParser.test.js +0 -80
  170. package/lib/services/__tests__/check.test.d.ts +0 -1
  171. package/lib/services/__tests__/check.test.js +0 -22
  172. package/lib/services/__tests__/utils.test.d.ts +0 -1
  173. package/lib/services/__tests__/utils.test.js +0 -42
  174. package/lib/services/code-samples/__tests__/apply-environments.test.d.ts +0 -1
  175. package/lib/services/code-samples/__tests__/apply-environments.test.js +0 -64
  176. package/lib/services/code-samples/__tests__/build-code-samples.test.d.ts +0 -1
  177. package/lib/services/code-samples/__tests__/build-code-samples.test.js +0 -70
  178. package/lib/services/code-samples/__tests__/convertSampleToString.test.d.ts +0 -1
  179. package/lib/services/code-samples/__tests__/convertSampleToString.test.js +0 -116
  180. package/lib/services/code-samples/__tests__/generator-data-value.test.d.ts +0 -1
  181. package/lib/services/code-samples/__tests__/generator-data-value.test.js +0 -277
  182. package/lib/services/code-samples/__tests__/generator-serialized-value.test.d.ts +0 -1
  183. package/lib/services/code-samples/__tests__/generator-serialized-value.test.js +0 -258
  184. package/lib/services/code-samples/__tests__/generator-value.test.d.ts +0 -1
  185. package/lib/services/code-samples/__tests__/generator-value.test.js +0 -273
  186. package/lib/services/code-samples/__tests__/generator.test.d.ts +0 -249
  187. package/lib/services/code-samples/__tests__/generator.test.js +0 -1201
  188. package/lib/services/code-samples/__tests__/get-example-value-by-mime-type.test.d.ts +0 -1
  189. package/lib/services/code-samples/__tests__/get-example-value-by-mime-type.test.js +0 -31
  190. package/lib/services/code-samples/httpsnippet/__tests__/device-authorization.test.d.ts +0 -1
  191. package/lib/services/code-samples/httpsnippet/__tests__/device-authorization.test.js +0 -222
  192. package/lib/services/code-samples/httpsnippet/helpers/__tests__/code-helpers.test.d.ts +0 -1
  193. package/lib/services/code-samples/httpsnippet/helpers/__tests__/code-helpers.test.js +0 -129
  194. package/lib/services/code-samples/httpsnippet/helpers/__tests__/string-utility.test.d.ts +0 -1
  195. package/lib/services/code-samples/httpsnippet/helpers/__tests__/string-utility.test.js +0 -49
  196. package/lib/services/code-samples/httpsnippet/targets/csharp/__tests__/httpclient.test.d.ts +0 -1
  197. package/lib/services/code-samples/httpsnippet/targets/csharp/__tests__/httpclient.test.js +0 -172
  198. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/__tests__/httpclient.test.d.ts +0 -1
  199. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/__tests__/httpclient.test.js +0 -172
  200. package/lib/services/code-samples/httpsnippet/targets/go/__tests__/native.test.d.ts +0 -1
  201. package/lib/services/code-samples/httpsnippet/targets/go/__tests__/native.test.js +0 -130
  202. package/lib/services/code-samples/httpsnippet/targets/java/__tests__/httpclient.test.d.ts +0 -1
  203. package/lib/services/code-samples/httpsnippet/targets/java/__tests__/httpclient.test.js +0 -191
  204. package/lib/services/code-samples/httpsnippet/targets/java8/__tests__/apachehttp.test.d.ts +0 -1
  205. package/lib/services/code-samples/httpsnippet/targets/java8/__tests__/apachehttp.test.js +0 -172
  206. package/lib/services/code-samples/httpsnippet/targets/javascript/__tests__/fetch.test.d.ts +0 -1
  207. package/lib/services/code-samples/httpsnippet/targets/javascript/__tests__/fetch.test.js +0 -85
  208. package/lib/services/code-samples/httpsnippet/targets/node/__tests__/fetch.test.d.ts +0 -1
  209. package/lib/services/code-samples/httpsnippet/targets/node/__tests__/fetch.test.js +0 -85
  210. package/lib/services/code-samples/httpsnippet/targets/php/__tests__/curl.test.d.ts +0 -1
  211. package/lib/services/code-samples/httpsnippet/targets/php/__tests__/curl.test.js +0 -126
  212. package/lib/services/code-samples/httpsnippet/targets/python/__tests__/requests.test.d.ts +0 -1
  213. package/lib/services/code-samples/httpsnippet/targets/python/__tests__/requests.test.js +0 -105
  214. package/lib/services/code-samples/httpsnippet/targets/r/__tests__/httr.test.d.ts +0 -1
  215. package/lib/services/code-samples/httpsnippet/targets/r/__tests__/httr.test.js +0 -126
  216. package/lib/services/code-samples/httpsnippet/targets/ruby/__tests__/native.test.d.ts +0 -1
  217. package/lib/services/code-samples/httpsnippet/targets/ruby/__tests__/native.test.js +0 -129
  218. package/lib/services/code-samples/httpsnippet/targets/shell/__tests__/curl.test.d.ts +0 -1
  219. package/lib/services/code-samples/httpsnippet/targets/shell/__tests__/curl.test.js +0 -129
  220. package/lib/services/config-options/__tests__/helpers.test.d.ts +0 -1
  221. package/lib/services/config-options/__tests__/helpers.test.js +0 -234
  222. package/lib/services/history/__tests__/helpers.test.d.ts +0 -1
  223. package/lib/services/history/__tests__/helpers.test.js +0 -19
  224. package/lib/services/menu/__tests__/buildNestedTagsItems.test.d.ts +0 -1
  225. package/lib/services/menu/__tests__/buildNestedTagsItems.test.js +0 -109
  226. package/lib/services/menu/__tests__/builder.test.d.ts +0 -1
  227. package/lib/services/menu/__tests__/builder.test.js +0 -307
  228. package/lib/services/menu/__tests__/operation.test.d.ts +0 -1
  229. package/lib/services/menu/__tests__/operation.test.js +0 -240
  230. package/lib/services/menu/__tests__/tags.test.d.ts +0 -1
  231. package/lib/services/menu/__tests__/tags.test.js +0 -71
  232. package/lib/telemetry/__tests__/RedocTelemetry.test.d.ts +0 -1
  233. package/lib/telemetry/__tests__/RedocTelemetry.test.js +0 -107
  234. package/lib/testProviders.d.ts +0 -6
  235. package/lib/testProviders.js +0 -14
  236. package/lib/utils/__tests__/areArraysEqual.test.d.ts +0 -1
  237. package/lib/utils/__tests__/areArraysEqual.test.js +0 -33
  238. package/lib/utils/__tests__/argValuesHelpers.d.ts +0 -1
  239. package/lib/utils/__tests__/argValuesHelpers.js +0 -56
  240. package/lib/utils/__tests__/calculateMaxLength.test.d.ts +0 -1
  241. package/lib/utils/__tests__/calculateMaxLength.test.js +0 -119
  242. package/lib/utils/__tests__/configure-helpers.test.d.ts +0 -1
  243. package/lib/utils/__tests__/configure-helpers.test.js +0 -356
  244. package/lib/utils/__tests__/convertSwagger2OpenAPI.test.d.ts +0 -1
  245. package/lib/utils/__tests__/convertSwagger2OpenAPI.test.js +0 -392
  246. package/lib/utils/__tests__/debounce.test.d.ts +0 -1
  247. package/lib/utils/__tests__/debounce.test.js +0 -54
  248. package/lib/utils/__tests__/debug.test.d.ts +0 -1
  249. package/lib/utils/__tests__/debug.test.js +0 -23
  250. package/lib/utils/__tests__/dom.test.d.ts +0 -1
  251. package/lib/utils/__tests__/dom.test.js +0 -108
  252. package/lib/utils/__tests__/getBreadcrumbs.test.d.ts +0 -1
  253. package/lib/utils/__tests__/getBreadcrumbs.test.js +0 -98
  254. package/lib/utils/__tests__/hasNestedFields.test.d.ts +0 -1
  255. package/lib/utils/__tests__/hasNestedFields.test.js +0 -147
  256. package/lib/utils/__tests__/helpers.test.d.ts +0 -1
  257. package/lib/utils/__tests__/helpers.test.js +0 -174
  258. package/lib/utils/__tests__/isMobile.test.d.ts +0 -1
  259. package/lib/utils/__tests__/isMobile.test.js +0 -28
  260. package/lib/utils/__tests__/loadAndBundleSpec.test.d.ts +0 -1
  261. package/lib/utils/__tests__/loadAndBundleSpec.test.js +0 -22
  262. package/lib/utils/__tests__/local-storage.test.d.ts +0 -1
  263. package/lib/utils/__tests__/local-storage.test.js +0 -48
  264. package/lib/utils/__tests__/object.test.d.ts +0 -1
  265. package/lib/utils/__tests__/object.test.js +0 -45
  266. package/lib/utils/__tests__/openapi.test.d.ts +0 -1
  267. package/lib/utils/__tests__/openapi.test.js +0 -1378
  268. package/lib/utils/__tests__/path.test.d.ts +0 -1
  269. package/lib/utils/__tests__/path.test.js +0 -16
  270. package/lib/utils/__tests__/queryString.test.d.ts +0 -1
  271. package/lib/utils/__tests__/queryString.test.js +0 -60
  272. package/lib/utils/__tests__/replaceVariables.test.d.ts +0 -1
  273. package/lib/utils/__tests__/replaceVariables.test.js +0 -46
  274. package/lib/utils/__tests__/simplifyAstStructure.test.d.ts +0 -1
  275. package/lib/utils/__tests__/simplifyAstStructure.test.js +0 -26
  276. package/lib/utils/__tests__/sort.test.d.ts +0 -1
  277. package/lib/utils/__tests__/sort.test.js +0 -16
  278. package/lib/utils/__tests__/string.test.d.ts +0 -1
  279. package/lib/utils/__tests__/string.test.js +0 -16
  280. package/lib/utils/__tests__/theme-helpers.test.d.ts +0 -1
  281. package/lib/utils/__tests__/theme-helpers.test.js +0 -24
  282. package/lib/utils/__tests__/url.test.d.ts +0 -1
  283. package/lib/utils/__tests__/url.test.js +0 -134
@@ -1,1201 +0,0 @@
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