@redocly/openapi-docs 3.24.0-next.9 → 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 (314) hide show
  1. package/dist/{redocly-openapi-docs.min.AiChatProvider-DcsGB2gP.js → redocly-openapi-docs.min.AiChatProvider-j-VDfFJ9.js} +3 -3
  2. package/dist/{redocly-openapi-docs.min.AiChatSqliteDBStorage-wCZA4usG.js → redocly-openapi-docs.min.AiChatSqliteDBStorage-BBRBmffc.js} +1 -1
  3. package/dist/{redocly-openapi-docs.min.AiPanel-jo7fqtSt.js → redocly-openapi-docs.min.AiPanel-DTzHqAiI.js} +116 -116
  4. package/dist/redocly-openapi-docs.min.FileWatcher-DDoyaS7A.js +1 -0
  5. package/dist/redocly-openapi-docs.min.Observable-D6wKbFwB.js +1 -0
  6. package/dist/redocly-openapi-docs.min.SemanticSearchService-DNFOPBZK.js +1 -0
  7. package/dist/{redocly-openapi-docs.min.SqliteDBStorage-B_f6WR8o.js → redocly-openapi-docs.min.SqliteDBStorage-Dy40Vq04.js} +1 -1
  8. package/dist/redocly-openapi-docs.min.TauriFileSystemAdapter-CpViFqJQ.js +1 -0
  9. package/dist/redocly-openapi-docs.min.TauriRootStorage-TCUrp2uB.js +1 -0
  10. package/dist/redocly-openapi-docs.min.ai-chat-mappers-CmX-8902.js +1 -0
  11. package/dist/redocly-openapi-docs.min.core-BYyFOtMX.js +1 -0
  12. package/dist/redocly-openapi-docs.min.external-resolver-BkceRyB4.js +2 -0
  13. package/dist/redocly-openapi-docs.min.index-BCcol5vU.js +1 -0
  14. package/dist/redocly-openapi-docs.min.index-C6uU_v-b.js +1 -0
  15. package/dist/redocly-openapi-docs.min.index-CmXZfuiZ.js +7730 -0
  16. package/dist/redocly-openapi-docs.min.index-DVWw0ICA.js +1 -0
  17. package/dist/redocly-openapi-docs.min.index-YnvLQkG_.js +1 -0
  18. package/dist/redocly-openapi-docs.min.index-xl_tBaHD.js +1 -0
  19. package/dist/redocly-openapi-docs.min.js +1 -1
  20. package/dist/{redocly-openapi-docs.min.lint-C-zlwxhp.js → redocly-openapi-docs.min.lint-2YpbCz3r.js} +69 -69
  21. package/dist/{redocly-openapi-docs.min.lint-graphql-qEh9cZHx.js → redocly-openapi-docs.min.lint-graphql-Bgfcu2tP.js} +1 -1
  22. package/dist/redocly-openapi-docs.min.periodic-revalidation-Dsp-n7ui.js +1 -0
  23. package/dist/redocly-openapi-docs.min.promise-map-limit-Db_42GvV.js +1 -0
  24. package/dist/{redocly-openapi-docs.min.respect-run-hfNPYQ9x.js → redocly-openapi-docs.min.respect-run-Ct8taisL.js} +1 -1
  25. package/dist/redocly-openapi-docs.min.standalone-BPCdJgtH.js +11995 -0
  26. package/dist/redocly-openapi-docs.min.tauri-path-CmqBCxGb.js +1 -0
  27. package/dist/{redocly-openapi-docs.min.useAiChatQueries-DgSsCKMW.js → redocly-openapi-docs.min.useAiChatQueries-t8oy8jik.js} +80 -80
  28. package/lib/components/ApiInfo/__tests__/ApiInfo.test.d.ts +1 -0
  29. package/lib/components/ApiInfo/__tests__/ApiInfo.test.js +46 -0
  30. package/lib/components/Callbacks/CallbackOperation.js +1 -1
  31. package/lib/components/Callbacks/__tests__/Callbacks.test.d.ts +1 -0
  32. package/lib/components/Callbacks/__tests__/Callbacks.test.js +46 -0
  33. package/lib/components/Content/__tests__/useAutoScroll.test.d.ts +1 -0
  34. package/lib/components/Content/__tests__/useAutoScroll.test.js +88 -0
  35. package/lib/components/Content/useAutoScroll.js +1 -1
  36. package/lib/components/ContentItem/__tests__/useIsExpanded.test.d.ts +1 -0
  37. package/lib/components/ContentItem/__tests__/useIsExpanded.test.js +123 -0
  38. package/lib/components/ContentItem/useIsExpanded.js +1 -1
  39. package/lib/components/ContentItems/ContentItems.js +1 -1
  40. package/lib/components/ContentItems/VirtualList.js +1 -1
  41. package/lib/components/ContentItems/__tests__/Items.test.d.ts +1 -0
  42. package/lib/components/ContentItems/__tests__/Items.test.js +66 -0
  43. package/lib/components/ContentItems/__tests__/VirtualList.test.d.ts +1 -0
  44. package/lib/components/ContentItems/__tests__/VirtualList.test.js +135 -0
  45. package/lib/components/ContentItems/useScrollOnRender.js +1 -1
  46. package/lib/components/Discriminator/__tests__/DiscriminatorDropdown.test.d.ts +1 -0
  47. package/lib/components/Discriminator/__tests__/DiscriminatorDropdown.test.js +63 -0
  48. package/lib/components/Download/__tests__/DownloadSpecification.test.d.ts +1 -0
  49. package/lib/components/Download/__tests__/DownloadSpecification.test.js +52 -0
  50. package/lib/components/ExpandAllButton/__tests__/ExpandAllButton.test.d.ts +1 -0
  51. package/lib/components/ExpandAllButton/__tests__/ExpandAllButton.test.js +60 -0
  52. package/lib/components/ExpandAllButton/__tests__/helpers.test.d.ts +1 -0
  53. package/lib/components/ExpandAllButton/__tests__/helpers.test.js +133 -0
  54. package/lib/components/Language/__tests__/LanguageDropdown.test.d.ts +1 -0
  55. package/lib/components/Language/__tests__/LanguageDropdown.test.js +23 -0
  56. package/lib/components/Markdown/__tests__/Markdown.test.d.ts +1 -0
  57. package/lib/components/Markdown/__tests__/Markdown.test.js +34 -0
  58. package/lib/components/McpOverview/__tests__/McpOverview.test.d.ts +1 -0
  59. package/lib/components/McpOverview/__tests__/McpOverview.test.js +66 -0
  60. package/lib/components/McpTool/__tests__/McpPrompt.test.d.ts +1 -0
  61. package/lib/components/McpTool/__tests__/McpPrompt.test.js +57 -0
  62. package/lib/components/McpTool/__tests__/McpResource.test.d.ts +1 -0
  63. package/lib/components/McpTool/__tests__/McpResource.test.js +81 -0
  64. package/lib/components/McpTool/__tests__/McpTool.test.d.ts +1 -0
  65. package/lib/components/McpTool/__tests__/McpTool.test.js +82 -0
  66. package/lib/components/MediaTypeSwitch/__tests__/MediaTypesSwitch.test.d.ts +1 -0
  67. package/lib/components/MediaTypeSwitch/__tests__/MediaTypesSwitch.test.js +79 -0
  68. package/lib/components/OperationItem/__tests__/OperationItem.test.d.ts +1 -0
  69. package/lib/components/OperationItem/__tests__/OperationItem.test.js +70 -0
  70. package/lib/components/OperationItem/__tests__/__mocks__/mock-intersection-observer.d.ts +16 -0
  71. package/lib/components/OperationItem/__tests__/__mocks__/mock-intersection-observer.js +42 -0
  72. package/lib/components/Overview/__tests__/Overview.test.d.ts +1 -0
  73. package/lib/components/Overview/__tests__/Overview.test.js +59 -0
  74. package/lib/components/PayloadSamples/__tests__/Example.test.d.ts +1 -0
  75. package/lib/components/PayloadSamples/__tests__/Example.test.js +36 -0
  76. package/lib/components/PayloadSamples/__tests__/ExampleValue.test.d.ts +1 -0
  77. package/lib/components/PayloadSamples/__tests__/ExampleValue.test.js +197 -0
  78. package/lib/components/PayloadSamples/__tests__/PayloadSamples.test.d.ts +1 -0
  79. package/lib/components/PayloadSamples/__tests__/PayloadSamples.test.js +38 -0
  80. package/lib/components/PropertyDetails/__tests__/Extensions.test.d.ts +1 -0
  81. package/lib/components/PropertyDetails/__tests__/Extensions.test.js +21 -0
  82. package/lib/components/PropertyDetails/__tests__/FieldDetail.test.d.ts +1 -0
  83. package/lib/components/PropertyDetails/__tests__/FieldDetail.test.js +52 -0
  84. package/lib/components/PropertyDetails/__tests__/FieldDetails.test.d.ts +1 -0
  85. package/lib/components/PropertyDetails/__tests__/FieldDetails.test.js +191 -0
  86. package/lib/components/PropertyDetails/__tests__/PropertyDetails.test.d.ts +1 -0
  87. package/lib/components/PropertyDetails/__tests__/PropertyDetails.test.js +365 -0
  88. package/lib/components/PropertyDetails/__tests__/cycleColorsByLevel.test.d.ts +1 -0
  89. package/lib/components/PropertyDetails/__tests__/cycleColorsByLevel.test.js +23 -0
  90. package/lib/components/RedoclyOpenAPIDocs/__tests__/AppProvider.test.d.ts +1 -0
  91. package/lib/components/RedoclyOpenAPIDocs/__tests__/AppProvider.test.js +16 -0
  92. package/lib/components/RedoclyOpenAPIDocs/__tests__/RedoclyOpenAPIDocs.test.d.ts +1 -0
  93. package/lib/components/RedoclyOpenAPIDocs/__tests__/RedoclyOpenAPIDocs.test.js +104 -0
  94. package/lib/components/RenderHook/__tests__/RenderHook.test.d.ts +1 -0
  95. package/lib/components/RenderHook/__tests__/RenderHook.test.js +15 -0
  96. package/lib/components/Replay/__tests__/utils.test.d.ts +1 -0
  97. package/lib/components/Replay/__tests__/utils.test.js +526 -0
  98. package/lib/components/Request/__tests__/RequestDetails.test.d.ts +1 -0
  99. package/lib/components/Request/__tests__/RequestDetails.test.js +98 -0
  100. package/lib/components/RequestSamples/__tests__/Example.test.d.ts +1 -0
  101. package/lib/components/RequestSamples/__tests__/Example.test.js +384 -0
  102. package/lib/components/RequestSamples/__tests__/RequestSamples.test.d.ts +1 -0
  103. package/lib/components/RequestSamples/__tests__/RequestSamples.test.js +226 -0
  104. package/lib/components/RequestSamples/__tests__/useCodeSamples.test.d.ts +1 -0
  105. package/lib/components/RequestSamples/__tests__/useCodeSamples.test.js +64 -0
  106. package/lib/components/ResponseSamples/__tests__/ResponseSamples.test.d.ts +1 -0
  107. package/lib/components/ResponseSamples/__tests__/ResponseSamples.test.js +29 -0
  108. package/lib/components/Responses/OperationResponseList.js +1 -1
  109. package/lib/components/Responses/__tests__/OperationResponseList.test.d.ts +1 -0
  110. package/lib/components/Responses/__tests__/OperationResponseList.test.js +89 -0
  111. package/lib/components/Responses/__tests__/ResponseDetails.test.d.ts +1 -0
  112. package/lib/components/Responses/__tests__/ResponseDetails.test.js +111 -0
  113. package/lib/components/Responses/__tests__/ResponsesHeaders.test.d.ts +1 -0
  114. package/lib/components/Responses/__tests__/ResponsesHeaders.test.js +26 -0
  115. package/lib/components/Schema/Schema.js +1 -1
  116. package/lib/components/Schema/SubSchema.js +1 -1
  117. package/lib/components/Schema/__tests__/ArraySchema.test.d.ts +1 -0
  118. package/lib/components/Schema/__tests__/ArraySchema.test.js +93 -0
  119. package/lib/components/Schema/__tests__/ObjectSchema.test.d.ts +1 -0
  120. package/lib/components/Schema/__tests__/ObjectSchema.test.js +115 -0
  121. package/lib/components/Schema/__tests__/OneOfSchema.test.d.ts +1 -0
  122. package/lib/components/Schema/__tests__/OneOfSchema.test.js +33 -0
  123. package/lib/components/Schema/__tests__/Schema.test.d.ts +1 -0
  124. package/lib/components/Schema/__tests__/Schema.test.js +67 -0
  125. package/lib/components/Schema/__tests__/useOneOfLocationIdx.test.d.ts +1 -0
  126. package/lib/components/Schema/__tests__/useOneOfLocationIdx.test.js +22 -0
  127. package/lib/components/Schema/useOneOfLocationIdx.js +1 -1
  128. package/lib/components/SchemaCatalogLink/__tests__/SchemaCatalogLink.test.d.ts +1 -0
  129. package/lib/components/SchemaCatalogLink/__tests__/SchemaCatalogLink.test.js +95 -0
  130. package/lib/components/Security/__tests__/Security.test.d.ts +1 -0
  131. package/lib/components/Security/__tests__/Security.test.js +38 -0
  132. package/lib/components/Security/__tests__/SecurityButton.test.d.ts +1 -0
  133. package/lib/components/Security/__tests__/SecurityButton.test.js +92 -0
  134. package/lib/components/Security/__tests__/SecurityModal.test.d.ts +1 -0
  135. package/lib/components/Security/__tests__/SecurityModal.test.js +172 -0
  136. package/lib/components/ServerList/__tests__/ServerList.test.d.ts +1 -0
  137. package/lib/components/ServerList/__tests__/ServerList.test.js +83 -0
  138. package/lib/components/SideMenu/hooks/useMenuItems.js +1 -1
  139. package/lib/components/StickySidebar/StickyResponsiveSidebar.js +1 -1
  140. package/lib/components/Tabs/__tests__/Tabs.test.d.ts +1 -0
  141. package/lib/components/Tabs/__tests__/Tabs.test.js +27 -0
  142. package/lib/components/TagItem/OperationsNavigation.js +1 -1
  143. package/lib/components/TagItem/TagItem.js +1 -1
  144. package/lib/components/ViewNested/__tests__/ViewNested.test.d.ts +1 -0
  145. package/lib/components/ViewNested/__tests__/ViewNested.test.js +42 -0
  146. package/lib/components/__tests__/Samples/ExampleSwitch.test.d.ts +1 -0
  147. package/lib/components/__tests__/Samples/ExampleSwitch.test.js +45 -0
  148. package/lib/components/__tests__/Samples/use-example-key.test.d.ts +1 -0
  149. package/lib/components/__tests__/Samples/use-example-key.test.js +28 -0
  150. package/lib/components/__tests__/common/ClearButton.test.d.ts +1 -0
  151. package/lib/components/__tests__/common/ClearButton.test.js +18 -0
  152. package/lib/components/__tests__/common/Dropdown.test.d.ts +1 -0
  153. package/lib/components/__tests__/common/Dropdown.test.js +52 -0
  154. package/lib/components/__tests__/mocks/examples.d.ts +4 -0
  155. package/lib/components/__tests__/mocks/examples.js +115 -0
  156. package/lib/components/common/LinkToField.js +1 -1
  157. package/lib/components/common/__tests__/Dropdown.test.d.ts +1 -0
  158. package/lib/components/common/__tests__/Dropdown.test.js +129 -0
  159. package/lib/components/common/__tests__/LinkToField.test.d.ts +1 -0
  160. package/lib/components/common/__tests__/LinkToField.test.js +39 -0
  161. package/lib/components/common/linkify.js +1 -1
  162. package/lib/hooks/useRouter.js +1 -1
  163. package/lib/hooks/useUppercase2LowercaseRedirect.js +1 -1
  164. package/lib/jotai/__tests__/app.test.d.ts +1 -0
  165. package/lib/jotai/__tests__/app.test.js +53 -0
  166. package/lib/models/__tests__/Callback.test.d.ts +1 -0
  167. package/lib/models/__tests__/Callback.test.js +15 -0
  168. package/lib/models/__tests__/FieldModel.test.d.ts +1 -0
  169. package/lib/models/__tests__/FieldModel.test.js +117 -0
  170. package/lib/models/__tests__/MediaContent.test.d.ts +1 -0
  171. package/lib/models/__tests__/MediaContent.test.js +105 -0
  172. package/lib/models/__tests__/Operation.test.d.ts +1 -0
  173. package/lib/models/__tests__/Operation.test.js +459 -0
  174. package/lib/models/__tests__/Response.test.d.ts +1 -0
  175. package/lib/models/__tests__/Response.test.js +221 -0
  176. package/lib/models/__tests__/Schema.circular.test.d.ts +1 -0
  177. package/lib/models/__tests__/Schema.circular.test.js +694 -0
  178. package/lib/models/__tests__/Schema.test.d.ts +1 -0
  179. package/lib/models/__tests__/Schema.test.js +1395 -0
  180. package/lib/models/__tests__/example.test.d.ts +1 -0
  181. package/lib/models/__tests__/example.test.js +90 -0
  182. package/lib/models/__tests__/group.test.d.ts +1 -0
  183. package/lib/models/__tests__/group.test.js +52 -0
  184. package/lib/models/__tests__/helpers.d.ts +5 -0
  185. package/lib/models/__tests__/helpers.js +62 -0
  186. package/lib/models/__tests__/request.test.d.ts +1 -0
  187. package/lib/models/__tests__/request.test.js +119 -0
  188. package/lib/services/__tests__/OpenAPIParser.test.d.ts +1 -0
  189. package/lib/services/__tests__/OpenAPIParser.test.js +80 -0
  190. package/lib/services/__tests__/check.test.d.ts +1 -0
  191. package/lib/services/__tests__/check.test.js +22 -0
  192. package/lib/services/__tests__/utils.test.d.ts +1 -0
  193. package/lib/services/__tests__/utils.test.js +42 -0
  194. package/lib/services/code-samples/__tests__/apply-environments.test.d.ts +1 -0
  195. package/lib/services/code-samples/__tests__/apply-environments.test.js +64 -0
  196. package/lib/services/code-samples/__tests__/build-code-samples.test.d.ts +1 -0
  197. package/lib/services/code-samples/__tests__/build-code-samples.test.js +70 -0
  198. package/lib/services/code-samples/__tests__/convertSampleToString.test.d.ts +1 -0
  199. package/lib/services/code-samples/__tests__/convertSampleToString.test.js +116 -0
  200. package/lib/services/code-samples/__tests__/generator-data-value.test.d.ts +1 -0
  201. package/lib/services/code-samples/__tests__/generator-data-value.test.js +277 -0
  202. package/lib/services/code-samples/__tests__/generator-serialized-value.test.d.ts +1 -0
  203. package/lib/services/code-samples/__tests__/generator-serialized-value.test.js +258 -0
  204. package/lib/services/code-samples/__tests__/generator-value.test.d.ts +1 -0
  205. package/lib/services/code-samples/__tests__/generator-value.test.js +273 -0
  206. package/lib/services/code-samples/__tests__/generator.test.d.ts +249 -0
  207. package/lib/services/code-samples/__tests__/generator.test.js +1201 -0
  208. package/lib/services/code-samples/__tests__/get-example-value-by-mime-type.test.d.ts +1 -0
  209. package/lib/services/code-samples/__tests__/get-example-value-by-mime-type.test.js +31 -0
  210. package/lib/services/code-samples/httpsnippet/__tests__/device-authorization.test.d.ts +1 -0
  211. package/lib/services/code-samples/httpsnippet/__tests__/device-authorization.test.js +222 -0
  212. package/lib/services/code-samples/httpsnippet/helpers/__tests__/code-helpers.test.d.ts +1 -0
  213. package/lib/services/code-samples/httpsnippet/helpers/__tests__/code-helpers.test.js +129 -0
  214. package/lib/services/code-samples/httpsnippet/helpers/__tests__/string-utility.test.d.ts +1 -0
  215. package/lib/services/code-samples/httpsnippet/helpers/__tests__/string-utility.test.js +49 -0
  216. package/lib/services/code-samples/httpsnippet/targets/csharp/__tests__/httpclient.test.d.ts +1 -0
  217. package/lib/services/code-samples/httpsnippet/targets/csharp/__tests__/httpclient.test.js +172 -0
  218. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/__tests__/httpclient.test.d.ts +1 -0
  219. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/__tests__/httpclient.test.js +172 -0
  220. package/lib/services/code-samples/httpsnippet/targets/go/__tests__/native.test.d.ts +1 -0
  221. package/lib/services/code-samples/httpsnippet/targets/go/__tests__/native.test.js +130 -0
  222. package/lib/services/code-samples/httpsnippet/targets/java/__tests__/httpclient.test.d.ts +1 -0
  223. package/lib/services/code-samples/httpsnippet/targets/java/__tests__/httpclient.test.js +191 -0
  224. package/lib/services/code-samples/httpsnippet/targets/java8/__tests__/apachehttp.test.d.ts +1 -0
  225. package/lib/services/code-samples/httpsnippet/targets/java8/__tests__/apachehttp.test.js +172 -0
  226. package/lib/services/code-samples/httpsnippet/targets/javascript/__tests__/fetch.test.d.ts +1 -0
  227. package/lib/services/code-samples/httpsnippet/targets/javascript/__tests__/fetch.test.js +85 -0
  228. package/lib/services/code-samples/httpsnippet/targets/node/__tests__/fetch.test.d.ts +1 -0
  229. package/lib/services/code-samples/httpsnippet/targets/node/__tests__/fetch.test.js +85 -0
  230. package/lib/services/code-samples/httpsnippet/targets/php/__tests__/curl.test.d.ts +1 -0
  231. package/lib/services/code-samples/httpsnippet/targets/php/__tests__/curl.test.js +126 -0
  232. package/lib/services/code-samples/httpsnippet/targets/python/__tests__/requests.test.d.ts +1 -0
  233. package/lib/services/code-samples/httpsnippet/targets/python/__tests__/requests.test.js +105 -0
  234. package/lib/services/code-samples/httpsnippet/targets/r/__tests__/httr.test.d.ts +1 -0
  235. package/lib/services/code-samples/httpsnippet/targets/r/__tests__/httr.test.js +126 -0
  236. package/lib/services/code-samples/httpsnippet/targets/ruby/__tests__/native.test.d.ts +1 -0
  237. package/lib/services/code-samples/httpsnippet/targets/ruby/__tests__/native.test.js +129 -0
  238. package/lib/services/code-samples/httpsnippet/targets/shell/__tests__/curl.test.d.ts +1 -0
  239. package/lib/services/code-samples/httpsnippet/targets/shell/__tests__/curl.test.js +129 -0
  240. package/lib/services/config-options/__tests__/helpers.test.d.ts +1 -0
  241. package/lib/services/config-options/__tests__/helpers.test.js +234 -0
  242. package/lib/services/history/__tests__/helpers.test.d.ts +1 -0
  243. package/lib/services/history/__tests__/helpers.test.js +19 -0
  244. package/lib/services/menu/__tests__/buildNestedTagsItems.test.d.ts +1 -0
  245. package/lib/services/menu/__tests__/buildNestedTagsItems.test.js +109 -0
  246. package/lib/services/menu/__tests__/builder.test.d.ts +1 -0
  247. package/lib/services/menu/__tests__/builder.test.js +307 -0
  248. package/lib/services/menu/__tests__/operation.test.d.ts +1 -0
  249. package/lib/services/menu/__tests__/operation.test.js +240 -0
  250. package/lib/services/menu/__tests__/tags.test.d.ts +1 -0
  251. package/lib/services/menu/__tests__/tags.test.js +71 -0
  252. package/lib/telemetry/RedocTelemetry.js +31 -1
  253. package/lib/telemetry/__tests__/RedocTelemetry.test.d.ts +1 -0
  254. package/lib/telemetry/__tests__/RedocTelemetry.test.js +107 -0
  255. package/lib/testProviders.d.ts +6 -0
  256. package/lib/testProviders.js +14 -0
  257. package/lib/utils/__tests__/areArraysEqual.test.d.ts +1 -0
  258. package/lib/utils/__tests__/areArraysEqual.test.js +33 -0
  259. package/lib/utils/__tests__/argValuesHelpers.d.ts +1 -0
  260. package/lib/utils/__tests__/argValuesHelpers.js +56 -0
  261. package/lib/utils/__tests__/calculateMaxLength.test.d.ts +1 -0
  262. package/lib/utils/__tests__/calculateMaxLength.test.js +119 -0
  263. package/lib/utils/__tests__/configure-helpers.test.d.ts +1 -0
  264. package/lib/utils/__tests__/configure-helpers.test.js +356 -0
  265. package/lib/utils/__tests__/convertSwagger2OpenAPI.test.d.ts +1 -0
  266. package/lib/utils/__tests__/convertSwagger2OpenAPI.test.js +392 -0
  267. package/lib/utils/__tests__/debounce.test.d.ts +1 -0
  268. package/lib/utils/__tests__/debounce.test.js +54 -0
  269. package/lib/utils/__tests__/debug.test.d.ts +1 -0
  270. package/lib/utils/__tests__/debug.test.js +23 -0
  271. package/lib/utils/__tests__/dom.test.d.ts +1 -0
  272. package/lib/utils/__tests__/dom.test.js +108 -0
  273. package/lib/utils/__tests__/getBreadcrumbs.test.d.ts +1 -0
  274. package/lib/utils/__tests__/getBreadcrumbs.test.js +98 -0
  275. package/lib/utils/__tests__/hasNestedFields.test.d.ts +1 -0
  276. package/lib/utils/__tests__/hasNestedFields.test.js +147 -0
  277. package/lib/utils/__tests__/helpers.test.d.ts +1 -0
  278. package/lib/utils/__tests__/helpers.test.js +174 -0
  279. package/lib/utils/__tests__/isMobile.test.d.ts +1 -0
  280. package/lib/utils/__tests__/isMobile.test.js +28 -0
  281. package/lib/utils/__tests__/loadAndBundleSpec.test.d.ts +1 -0
  282. package/lib/utils/__tests__/loadAndBundleSpec.test.js +22 -0
  283. package/lib/utils/__tests__/local-storage.test.d.ts +1 -0
  284. package/lib/utils/__tests__/local-storage.test.js +48 -0
  285. package/lib/utils/__tests__/object.test.d.ts +1 -0
  286. package/lib/utils/__tests__/object.test.js +45 -0
  287. package/lib/utils/__tests__/openapi.test.d.ts +1 -0
  288. package/lib/utils/__tests__/openapi.test.js +1378 -0
  289. package/lib/utils/__tests__/path.test.d.ts +1 -0
  290. package/lib/utils/__tests__/path.test.js +16 -0
  291. package/lib/utils/__tests__/queryString.test.d.ts +1 -0
  292. package/lib/utils/__tests__/queryString.test.js +60 -0
  293. package/lib/utils/__tests__/replaceVariables.test.d.ts +1 -0
  294. package/lib/utils/__tests__/replaceVariables.test.js +46 -0
  295. package/lib/utils/__tests__/simplifyAstStructure.test.d.ts +1 -0
  296. package/lib/utils/__tests__/simplifyAstStructure.test.js +26 -0
  297. package/lib/utils/__tests__/sort.test.d.ts +1 -0
  298. package/lib/utils/__tests__/sort.test.js +16 -0
  299. package/lib/utils/__tests__/string.test.d.ts +1 -0
  300. package/lib/utils/__tests__/string.test.js +16 -0
  301. package/lib/utils/__tests__/theme-helpers.test.d.ts +1 -0
  302. package/lib/utils/__tests__/theme-helpers.test.js +24 -0
  303. package/lib/utils/__tests__/url.test.d.ts +1 -0
  304. package/lib/utils/__tests__/url.test.js +134 -0
  305. package/lib/utils/path.d.ts +1 -1
  306. package/package.json +12 -12
  307. package/dist/redocly-openapi-docs.min.ai-chat-mappers-MY79QAeW.js +0 -1
  308. package/dist/redocly-openapi-docs.min.external-resolver-3KMJv7SC.js +0 -2
  309. package/dist/redocly-openapi-docs.min.index-BYVMr_la.js +0 -1
  310. package/dist/redocly-openapi-docs.min.index-CsqzTi3Z.js +0 -7586
  311. package/dist/redocly-openapi-docs.min.index-D8F7x0S6.js +0 -1
  312. package/dist/redocly-openapi-docs.min.index-qqKTpI_q.js +0 -1
  313. package/dist/redocly-openapi-docs.min.standalone-Ci6886Cr.js +0 -12114
  314. package/dist/redocly-openapi-docs.min.tauri-path-Bs1-AQjc.js +0 -1
@@ -0,0 +1,1378 @@
1
+ import { detectType, getOperationName, getStatusCodeType, humanizeConstraints, isOperationName, isPrimitiveType, mergeParams, normalizeServers, pluralizeType, serializeParameterValue, sortByRequired, humanizeNumberRange, getDefinitionName, serializeQueryParameter, isSequentialMediaType, langFromMime, getContent, } from '../index.js';
2
+ import { getField } from '../../models/index.js';
3
+ import { OpenAPIParser } from '../../services/OpenAPIParser.js';
4
+ import { getContentWithLegacyExamples } from '../openapi.js';
5
+ import { normalizeOptions } from '../../services/index.js';
6
+ describe('Utils', () => {
7
+ describe('openapi getStatusCode', () => {
8
+ it('Should return info for status codes within 100 and 200', () => {
9
+ expect(getStatusCodeType(100)).toEqual('info');
10
+ expect(getStatusCodeType(150)).toEqual('info');
11
+ expect(getStatusCodeType(199)).toEqual('info');
12
+ });
13
+ it('Should return success for status codes within 200 and 300', () => {
14
+ expect(getStatusCodeType(200)).toEqual('success');
15
+ expect(getStatusCodeType(250)).toEqual('success');
16
+ expect(getStatusCodeType(299)).toEqual('success');
17
+ });
18
+ it('Should return redirect for status codes within 300 and 400', () => {
19
+ expect(getStatusCodeType(300)).toEqual('redirect');
20
+ expect(getStatusCodeType(399)).toEqual('redirect');
21
+ });
22
+ it('Should return error for status codes above 400', () => {
23
+ expect(getStatusCodeType(400)).toEqual('error');
24
+ expect(getStatusCodeType(500)).toEqual('error');
25
+ expect(getStatusCodeType(599)).toEqual('error');
26
+ });
27
+ it('Should throw for incorrect HTTP code', () => {
28
+ expect(() => getStatusCodeType(99)).toThrow('invalid HTTP code');
29
+ expect(() => getStatusCodeType(600)).toThrow('invalid HTTP code');
30
+ });
31
+ });
32
+ describe('openapi isOperationName', () => {
33
+ it('Should return `true` for correct HTTP verbs', () => {
34
+ expect(isOperationName('get')).toEqual(true);
35
+ expect(isOperationName('post')).toEqual(true);
36
+ expect(isOperationName('put')).toEqual(true);
37
+ expect(isOperationName('head')).toEqual(true);
38
+ expect(isOperationName('patch')).toEqual(true);
39
+ expect(isOperationName('delete')).toEqual(true);
40
+ expect(isOperationName('options')).toEqual(true);
41
+ expect(isOperationName('x-query')).toEqual(true);
42
+ expect(isOperationName('query')).toEqual(true);
43
+ });
44
+ it('Should return `false` for incorrect HTTP verbs', () => {
45
+ expect(isOperationName('properties')).toEqual(false);
46
+ expect(isOperationName('x-name')).toEqual(false);
47
+ expect(isOperationName('fix')).toEqual(false);
48
+ });
49
+ });
50
+ describe('openapi serializeQueryParameter', () => {
51
+ it('should join elements of the array with a "&"', () => {
52
+ expect(serializeQueryParameter('arrayOfObjects', 'form', true, [
53
+ { sub1: 'foo', enumTest: 'available' },
54
+ { sub1: 'test', enumTest: 'sold' },
55
+ ])).toEqual('arrayOfObjects=sub1%3Dfoo%26enumTest%3Davailable&arrayOfObjects=sub1%3Dtest%26enumTest%3Dsold');
56
+ });
57
+ });
58
+ let sixtyLetterStr = '';
59
+ for (let i = 0; i < 60; i++) {
60
+ sixtyLetterStr += 'a';
61
+ }
62
+ describe('openapi getOperationName', () => {
63
+ it('Should return operation self summary if exists', () => {
64
+ const operation = {
65
+ summary: 'test',
66
+ operationId: 'fail',
67
+ description: 'fail',
68
+ };
69
+ expect(getOperationName(operation)).toEqual('test');
70
+ });
71
+ it('Should return operationId if no summary', () => {
72
+ const operation = {
73
+ operationId: 'test',
74
+ description: 'fail',
75
+ };
76
+ expect(getOperationName(operation)).toEqual('test');
77
+ });
78
+ it('Should return description if no summary and operationId', () => {
79
+ const operation = {
80
+ description: 'test',
81
+ };
82
+ expect(getOperationName(operation)).toEqual('test');
83
+ });
84
+ it('Should return only first 50 description letter if no summary and operationId', () => {
85
+ const operation = {
86
+ description: sixtyLetterStr,
87
+ };
88
+ expect(sixtyLetterStr.length).toBeGreaterThan(50);
89
+ expect(getOperationName(operation).length).toBe(50);
90
+ });
91
+ it('Should return pathName if no summary, operationId, description', () => {
92
+ const operation = {
93
+ pathName: '/sandbox/test',
94
+ };
95
+ expect(getOperationName(operation)).toBe('/sandbox/test');
96
+ });
97
+ it('Should return <no summary> if no info', () => {
98
+ const operation = {
99
+ description: undefined,
100
+ };
101
+ expect(getOperationName(operation)).toBe('<no summary>');
102
+ });
103
+ });
104
+ describe('openapi detectType', () => {
105
+ it('Should detect object.type if it is specified', () => {
106
+ expect(detectType({
107
+ type: 'object',
108
+ })).toBe('object');
109
+ expect(detectType({
110
+ type: 'object',
111
+ minimum: 1,
112
+ })).toBe('object');
113
+ });
114
+ const tests = {
115
+ number: ['multipleOf', 'maximum', 'exclusiveMaximum', 'minimum', 'exclusiveMinimum'],
116
+ string: ['pattern', 'minLength', 'maxLength'],
117
+ array: ['items', 'maxItems', 'minItems', 'uniqueItems'],
118
+ object: [
119
+ 'maxProperties',
120
+ 'minProperties',
121
+ 'required',
122
+ 'additionalProperties',
123
+ 'unevaluatedProperties',
124
+ 'properties',
125
+ ],
126
+ };
127
+ Object.keys(tests).forEach((name) => {
128
+ it(`Should detect ${name} if ${name} properties are present`, () => {
129
+ tests[name].forEach((propName) => {
130
+ expect(detectType({
131
+ [propName]: 0,
132
+ })).toBe(name);
133
+ });
134
+ });
135
+ });
136
+ });
137
+ describe('openapi isPrimitiveType', () => {
138
+ it('Should return true for empty object', () => {
139
+ const schema = {
140
+ type: 'object',
141
+ };
142
+ expect(isPrimitiveType(schema)).toEqual(true);
143
+ });
144
+ it('Should return false for object with props', () => {
145
+ const schema = {
146
+ type: 'object',
147
+ properties: {
148
+ a: {
149
+ type: 'string',
150
+ },
151
+ },
152
+ };
153
+ expect(isPrimitiveType(schema)).toEqual(false);
154
+ });
155
+ it("should return true for array contains object and schema hasn't properties", () => {
156
+ const schema = {
157
+ type: ['object', 'string'],
158
+ };
159
+ expect(isPrimitiveType(schema)).toEqual(true);
160
+ });
161
+ it('should return false for array contains object and schema has properties', () => {
162
+ const schema = {
163
+ type: ['object', 'string'],
164
+ properties: {
165
+ a: {
166
+ type: 'string',
167
+ },
168
+ },
169
+ };
170
+ expect(isPrimitiveType(schema)).toEqual(false);
171
+ });
172
+ it('should return false for array contains array type and schema has items', () => {
173
+ const schema = {
174
+ type: ['array'],
175
+ items: {
176
+ type: 'object',
177
+ additionalProperties: true,
178
+ },
179
+ };
180
+ expect(isPrimitiveType(schema)).toEqual(false);
181
+ });
182
+ it('should return false for array contains array type and schema has items(unevaluatedProperties)', () => {
183
+ const schema = {
184
+ type: ['array'],
185
+ items: {
186
+ type: 'object',
187
+ unevaluatedProperties: true,
188
+ },
189
+ };
190
+ expect(isPrimitiveType(schema)).toEqual(false);
191
+ });
192
+ it('should return false for array contains object and array types and schema has items', () => {
193
+ const schema = {
194
+ type: ['array', 'object'],
195
+ items: {
196
+ type: 'object',
197
+ additionalProperties: true,
198
+ },
199
+ };
200
+ expect(isPrimitiveType(schema)).toEqual(false);
201
+ });
202
+ it('should return false for array contains object and array types and schema has properties', () => {
203
+ const schema = {
204
+ type: ['array', 'object'],
205
+ properties: {
206
+ a: {
207
+ type: 'string',
208
+ },
209
+ },
210
+ };
211
+ expect(isPrimitiveType(schema)).toEqual(false);
212
+ });
213
+ it('should return true for array contains array of strings', () => {
214
+ const schema = {
215
+ type: 'array',
216
+ items: {
217
+ type: 'array',
218
+ items: {
219
+ type: 'string',
220
+ },
221
+ },
222
+ };
223
+ expect(isPrimitiveType(schema)).toEqual(true);
224
+ });
225
+ it('Should return true for array of string which include the null value', () => {
226
+ const schema = {
227
+ type: ['object', 'string', 'null'],
228
+ };
229
+ expect(isPrimitiveType(schema)).toEqual(true);
230
+ });
231
+ it('Should return false for array with non-empty objects', () => {
232
+ const schema = {
233
+ type: 'array',
234
+ items: {
235
+ type: 'object',
236
+ properties: {
237
+ a: {
238
+ type: 'string',
239
+ },
240
+ },
241
+ },
242
+ };
243
+ expect(isPrimitiveType(schema)).toEqual(false);
244
+ });
245
+ it('should return false for object with additionalProperties', () => {
246
+ const schema = {
247
+ type: 'array',
248
+ items: {
249
+ type: 'object',
250
+ additionalProperties: true,
251
+ },
252
+ };
253
+ expect(isPrimitiveType(schema)).toEqual(false);
254
+ });
255
+ it('should return false for object with unevaluatedProperties', () => {
256
+ const schema = {
257
+ type: 'array',
258
+ items: {
259
+ type: 'object',
260
+ unevaluatedProperties: true,
261
+ },
262
+ };
263
+ expect(isPrimitiveType(schema)).toEqual(false);
264
+ });
265
+ it('should work with externally provided type', () => {
266
+ const schema = {
267
+ properties: {
268
+ a: {
269
+ type: 'string',
270
+ },
271
+ },
272
+ };
273
+ expect(isPrimitiveType(schema, 'object')).toEqual(false);
274
+ });
275
+ });
276
+ describe('openapi mergeParams', () => {
277
+ it('Should deduplicate params with same "name" and "in"', () => {
278
+ const pathParams = [
279
+ {
280
+ name: 'param1',
281
+ in: 'path',
282
+ description: 'path',
283
+ },
284
+ {
285
+ name: 'param2',
286
+ in: 'path',
287
+ },
288
+ ];
289
+ const operationParams = [
290
+ {
291
+ name: 'param1',
292
+ in: 'path',
293
+ description: 'oper',
294
+ },
295
+ {
296
+ name: 'param2',
297
+ in: 'query',
298
+ },
299
+ ];
300
+ const parser = new OpenAPIParser({ openapi: '3.0' });
301
+ const res = mergeParams(parser, pathParams, operationParams, {
302
+ pathPointer: '',
303
+ operationPointer: '/post',
304
+ });
305
+ expect(res).toHaveLength(3);
306
+ expect(res[0]).toEqual({
307
+ paramOrRef: pathParams[1],
308
+ pointer: '/parameters/1',
309
+ });
310
+ expect(res[1]).toEqual({
311
+ paramOrRef: operationParams[0],
312
+ pointer: '/post/parameters/0',
313
+ });
314
+ expect(res[2]).toEqual({
315
+ paramOrRef: operationParams[1],
316
+ pointer: '/post/parameters/1',
317
+ });
318
+ });
319
+ });
320
+ describe('normalize servers', () => {
321
+ it('should make url absolute and strip spec name', () => {
322
+ const res = normalizeServers('http://base.com/spec.yaml', [
323
+ {
324
+ url: '/sandbox/test',
325
+ },
326
+ ]);
327
+ expect(res).toEqual([{ url: 'http://base.com/sandbox/test', description: '' }]);
328
+ });
329
+ it('should correctly resolve url with server relative path', () => {
330
+ const res = normalizeServers('http://base.com/subpath/spec.yaml', [
331
+ {
332
+ url: '/sandbox/test',
333
+ },
334
+ ]);
335
+ expect(res).toEqual([{ url: 'http://base.com/sandbox/test', description: '' }]);
336
+ });
337
+ it('should correctly resolve url with relative path', () => {
338
+ const res = normalizeServers('http://base.com/subpath/spec.yaml', [
339
+ {
340
+ url: 'sandbox/test',
341
+ },
342
+ ]);
343
+ expect(res).toEqual([{ url: 'http://base.com/subpath/sandbox/test', description: '' }]);
344
+ });
345
+ it('should prefer server host over spec`s one', () => {
346
+ const res = normalizeServers('http://base.com/spec.yaml', [
347
+ {
348
+ url: 'https://otherbase.com/sandbox/test',
349
+ },
350
+ ]);
351
+ expect(res).toEqual([{ url: 'https://otherbase.com/sandbox/test', description: '' }]);
352
+ });
353
+ it('should strip trailing slash', () => {
354
+ const res = normalizeServers('', [
355
+ {
356
+ url: 'https://otherbase.com/sandbox/test/',
357
+ },
358
+ ]);
359
+ expect(res).toEqual([{ url: 'https://otherbase.com/sandbox/test', description: '' }]);
360
+ });
361
+ it('should remove query string and hash from url', () => {
362
+ const originalWindow = { ...window };
363
+ const windowSpy = vi.spyOn(global, 'window', 'get');
364
+ windowSpy.mockImplementation(() => ({
365
+ ...originalWindow,
366
+ location: {
367
+ ...originalWindow.location,
368
+ href: 'https://base.com/subpath/?param=value#tag',
369
+ },
370
+ }));
371
+ const res = normalizeServers(undefined, [
372
+ {
373
+ url: 'sandbox/test',
374
+ },
375
+ ]);
376
+ expect(res).toEqual([{ url: 'https://base.com/subpath/sandbox/test', description: '' }]);
377
+ windowSpy.mockRestore();
378
+ });
379
+ it('should set correct protocol', () => {
380
+ const res = normalizeServers('https://base.com', [
381
+ {
382
+ url: '//base.com/sandbox/test',
383
+ description: 'test',
384
+ },
385
+ ]);
386
+ expect(res).toEqual([{ url: 'https://base.com/sandbox/test', description: 'test' }]);
387
+ });
388
+ });
389
+ describe('openapi humanizeNumberRange', () => {
390
+ it('should return `>=` when only minimum value present or exclusiveMinimum = false', () => {
391
+ const expected = '>= 0';
392
+ expect(humanizeNumberRange({ minimum: 0 })).toEqual(expected);
393
+ expect(humanizeNumberRange({ minimum: 0, exclusiveMinimum: false })).toEqual(expected);
394
+ });
395
+ it('should return `>` when minimum value present and exclusiveMinimum set to true', () => {
396
+ expect(humanizeNumberRange({ minimum: 0, exclusiveMinimum: true })).toEqual('> 0');
397
+ });
398
+ it('should return `<=` when only maximum value present or exclusiveMinimum = false', () => {
399
+ const expected = '<= 10';
400
+ expect(humanizeNumberRange({ maximum: 10 })).toEqual(expected);
401
+ expect(humanizeNumberRange({ maximum: 10, exclusiveMaximum: false })).toEqual(expected);
402
+ });
403
+ it('should return `<` when maximum value present and exclusiveMaximum set to true', () => {
404
+ expect(humanizeNumberRange({ maximum: 10, exclusiveMaximum: true })).toEqual('< 10');
405
+ });
406
+ it('should return correct range for minimum and maximum values and with different exclusive set', () => {
407
+ expect(humanizeNumberRange({ minimum: 0, maximum: 10 })).toEqual('[ 0 .. 10 ]');
408
+ expect(humanizeNumberRange({
409
+ minimum: 0,
410
+ exclusiveMinimum: true,
411
+ maximum: 10,
412
+ exclusiveMaximum: true,
413
+ })).toEqual('( 0 .. 10 )');
414
+ expect(humanizeNumberRange({
415
+ minimum: 0,
416
+ maximum: 10,
417
+ exclusiveMaximum: true,
418
+ })).toEqual('[ 0 .. 10 )');
419
+ expect(humanizeNumberRange({
420
+ minimum: 0,
421
+ exclusiveMinimum: true,
422
+ maximum: 10,
423
+ })).toEqual('( 0 .. 10 ]');
424
+ });
425
+ it('should return correct range exclusive values only', () => {
426
+ expect(humanizeNumberRange({ exclusiveMinimum: 0 })).toEqual('> 0');
427
+ expect(humanizeNumberRange({ exclusiveMaximum: 10 })).toEqual('< 10');
428
+ expect(humanizeNumberRange({ exclusiveMinimum: 0, exclusiveMaximum: 10 })).toEqual('( 0 .. 10 )');
429
+ });
430
+ it('should return correct min value', () => {
431
+ expect(humanizeNumberRange({ minimum: 5, exclusiveMinimum: 10 })).toEqual('> 5');
432
+ expect(humanizeNumberRange({ minimum: -5, exclusiveMinimum: -10 })).toEqual('> -10');
433
+ });
434
+ it('should return correct max value', () => {
435
+ expect(humanizeNumberRange({ maximum: 10, exclusiveMaximum: 15 })).toEqual('< 15');
436
+ expect(humanizeNumberRange({ maximum: -10, exclusiveMaximum: -15 })).toEqual('< -10');
437
+ });
438
+ it('should return undefined', () => {
439
+ expect(humanizeNumberRange({})).toEqual(undefined);
440
+ });
441
+ });
442
+ describe('openapi humanizeConstraints', () => {
443
+ const itemConstraintSchema = (min, max, multipleOf, uniqueItems) => ({ type: 'array', minItems: min, maxItems: max, multipleOf, uniqueItems });
444
+ it('should not have a humanized constraint without schema constraints', () => {
445
+ expect(humanizeConstraints(itemConstraintSchema())).toHaveLength(0);
446
+ });
447
+ it('should have a humanized constraint when minItems is set', () => {
448
+ expect(humanizeConstraints(itemConstraintSchema(2))).toContain('>= 2 items');
449
+ });
450
+ it('should have a humanized constraint when maxItems is set', () => {
451
+ expect(humanizeConstraints(itemConstraintSchema(undefined, 8))).toContain('<= 8 items');
452
+ });
453
+ it('should have a humanized constraint when minItems and maxItems are both set', () => {
454
+ expect(humanizeConstraints(itemConstraintSchema(2, 8))).toContain('[ 2 .. 8 ] items');
455
+ });
456
+ it('should have a humanized constraint when minItems and maxItems are the same', () => {
457
+ expect(humanizeConstraints(itemConstraintSchema(7, 7))).toContain('= 7 items');
458
+ });
459
+ it('should have a humanized constraint when justMinItems is set, and it is equal to 1', () => {
460
+ expect(humanizeConstraints(itemConstraintSchema(1))).toContain('non-empty');
461
+ });
462
+ it('should have a humanized constraint when multipleOf is set, and it is in format of /^0\\.0*1$/', () => {
463
+ expect(humanizeConstraints(itemConstraintSchema(undefined, undefined, 0.01))).toContain('decimal places <= 2');
464
+ });
465
+ it('should have a humanized constraint when multipleOf is set, and it is in format other than /^0\\.0*1$/', () => {
466
+ expect(humanizeConstraints(itemConstraintSchema(undefined, undefined, 0.5))).toContain('multiple of 0.5');
467
+ });
468
+ it('should have a humanized constraint when uniqueItems is set', () => {
469
+ expect(humanizeConstraints(itemConstraintSchema(undefined, undefined, undefined, true))).toContain('unique');
470
+ });
471
+ });
472
+ describe('OpenAPI pluralizeType', () => {
473
+ it('should pluralize all simple types', () => {
474
+ expect(pluralizeType('string')).toEqual('strings');
475
+ expect(pluralizeType('number')).toEqual('numbers');
476
+ expect(pluralizeType('object')).toEqual('objects');
477
+ expect(pluralizeType('integer')).toEqual('integers');
478
+ expect(pluralizeType('boolean')).toEqual('booleans');
479
+ expect(pluralizeType('array')).toEqual('arrays');
480
+ });
481
+ it('should pluralize complex display types', () => {
482
+ expect(pluralizeType('object (Pet)')).toEqual('objects (Pet)');
483
+ expect(pluralizeType('string <email>')).toEqual('strings <email>');
484
+ });
485
+ it('should pluralize oneOf-ed display types', () => {
486
+ expect(pluralizeType('object or string')).toEqual('objects or strings');
487
+ expect(pluralizeType('object (Pet) or number <int64>')).toEqual('objects (Pet) or numbers <int64>');
488
+ });
489
+ it('should not pluralize display types that are already pluralized', () => {
490
+ expect(pluralizeType('strings')).toEqual('strings');
491
+ expect(pluralizeType('objects (Pet)')).toEqual('objects (Pet)');
492
+ expect(pluralizeType('strings <email>')).toEqual('strings <email>');
493
+ expect(pluralizeType('objects or strings')).toEqual('objects or strings');
494
+ expect(pluralizeType('objects (Pet) or numbers <int64>')).toEqual('objects (Pet) or numbers <int64>');
495
+ });
496
+ });
497
+ describe('openapi serializeParameter', () => {
498
+ const testCases = [
499
+ {
500
+ location: 'path',
501
+ name: 'id',
502
+ description: 'path parameters',
503
+ cases: [
504
+ {
505
+ value: 5,
506
+ description: 'primitive values',
507
+ cases: [
508
+ { style: 'simple', explode: false, expected: '5' },
509
+ { style: 'simple', explode: true, expected: '5' },
510
+ { style: 'label', explode: false, expected: '.5' },
511
+ { style: 'label', explode: true, expected: '.5' },
512
+ { style: 'matrix', explode: false, expected: ';id=5' },
513
+ { style: 'matrix', explode: true, expected: ';id=5' },
514
+ ],
515
+ },
516
+ {
517
+ value: [3, 4, 5],
518
+ description: 'array values',
519
+ cases: [
520
+ { style: 'simple', explode: false, expected: '3,4,5' },
521
+ { style: 'simple', explode: true, expected: '3,4,5' },
522
+ { style: 'label', explode: false, expected: '.3,4,5' },
523
+ { style: 'label', explode: true, expected: '.3.4.5' },
524
+ { style: 'matrix', explode: false, expected: ';id=3,4,5' },
525
+ { style: 'matrix', explode: true, expected: ';id=3;id=4;id=5' },
526
+ ],
527
+ },
528
+ {
529
+ value: { role: 'admin', firstName: 'Alex' },
530
+ description: 'object values',
531
+ cases: [
532
+ { style: 'simple', explode: false, expected: 'role,admin,firstName,Alex' },
533
+ { style: 'simple', explode: true, expected: 'role=admin,firstName=Alex' },
534
+ { style: 'label', explode: false, expected: '.role,admin,firstName,Alex' },
535
+ { style: 'label', explode: true, expected: '.role=admin.firstName=Alex' },
536
+ { style: 'matrix', explode: false, expected: ';id=role,admin,firstName,Alex' },
537
+ { style: 'matrix', explode: true, expected: ';role=admin;firstName=Alex' },
538
+ ],
539
+ },
540
+ ],
541
+ },
542
+ {
543
+ location: 'query',
544
+ name: 'id',
545
+ description: 'query parameters',
546
+ cases: [
547
+ {
548
+ value: 5,
549
+ description: 'primitive values',
550
+ cases: [
551
+ { style: 'form', explode: true, expected: 'id=5' },
552
+ { style: 'form', explode: false, expected: 'id=5' },
553
+ ],
554
+ },
555
+ {
556
+ value: [3, 4, 5],
557
+ description: 'array values',
558
+ cases: [
559
+ { style: 'form', explode: true, expected: 'id=3&id=4&id=5' },
560
+ { style: 'form', explode: false, expected: 'id=3,4,5' },
561
+ { style: 'spaceDelimited', explode: true, expected: 'id=3&id=4&id=5' },
562
+ { style: 'spaceDelimited', explode: false, expected: '3%204%205' },
563
+ { style: 'pipeDelimited', explode: true, expected: 'id=3&id=4&id=5' },
564
+ { style: 'pipeDelimited', explode: false, expected: '3|4|5' },
565
+ ],
566
+ },
567
+ {
568
+ value: { role: 'admin', firstName: 'Alex' },
569
+ description: 'object values',
570
+ cases: [
571
+ { style: 'form', explode: true, expected: 'role=admin&firstName=Alex' },
572
+ { style: 'form', explode: false, expected: 'id=role,admin,firstName,Alex' },
573
+ { style: 'deepObject', explode: true, expected: 'id[role]=admin&id[firstName]=Alex' },
574
+ {
575
+ style: 'spaceDelimited',
576
+ explode: false,
577
+ expected: 'role%20admin%20firstName%20Alex',
578
+ },
579
+ { style: 'pipeDelimited', explode: false, expected: 'role|admin|firstName|Alex' },
580
+ ],
581
+ },
582
+ ],
583
+ },
584
+ {
585
+ location: 'cookie',
586
+ name: 'id',
587
+ description: 'cookie parameters',
588
+ cases: [
589
+ {
590
+ value: 5,
591
+ description: 'primitive values',
592
+ cases: [
593
+ { style: 'form', explode: true, expected: 'id=5' },
594
+ { style: 'form', explode: false, expected: 'id=5' },
595
+ ],
596
+ },
597
+ {
598
+ value: [3, 4, 5],
599
+ description: 'array values',
600
+ cases: [
601
+ { style: 'form', explode: true, expected: 'id=3&id=4&id=5' },
602
+ { style: 'form', explode: false, expected: 'id=3,4,5' },
603
+ ],
604
+ },
605
+ {
606
+ value: { role: 'admin', firstName: 'Alex' },
607
+ description: 'object values',
608
+ cases: [
609
+ { style: 'form', explode: true, expected: 'role=admin&firstName=Alex' },
610
+ { style: 'form', explode: false, expected: 'id=role,admin,firstName,Alex' },
611
+ ],
612
+ },
613
+ ],
614
+ },
615
+ {
616
+ location: 'header',
617
+ name: 'x-id',
618
+ description: 'header parameters',
619
+ cases: [
620
+ {
621
+ value: 5,
622
+ description: 'primitive values',
623
+ cases: [
624
+ { style: 'simple', explode: false, expected: '5' },
625
+ { style: 'simple', explode: true, expected: '5' },
626
+ ],
627
+ },
628
+ {
629
+ value: [3, 4, 5],
630
+ description: 'array values',
631
+ cases: [
632
+ { style: 'simple', explode: false, expected: '3,4,5' },
633
+ { style: 'simple', explode: true, expected: '3,4,5' },
634
+ ],
635
+ },
636
+ {
637
+ value: { role: 'admin', firstName: 'Alex' },
638
+ description: 'object values',
639
+ cases: [
640
+ { style: 'simple', explode: false, expected: 'role,admin,firstName,Alex' },
641
+ { style: 'simple', explode: true, expected: 'role=admin,firstName=Alex' },
642
+ ],
643
+ },
644
+ ],
645
+ },
646
+ ];
647
+ testCases.forEach((locationTestGroup) => {
648
+ describe(`${locationTestGroup.description}`, () => {
649
+ locationTestGroup.cases.forEach((valueTypeTestGroup) => {
650
+ describe(`${valueTypeTestGroup.description}`, () => {
651
+ valueTypeTestGroup.cases.forEach((testCase) => {
652
+ it(`should serialize correctly when style is ${testCase.style} and explode is ${testCase.explode}`, () => {
653
+ const parameter = {
654
+ name: locationTestGroup.name,
655
+ in: locationTestGroup.location,
656
+ style: testCase.style,
657
+ explode: testCase.explode,
658
+ };
659
+ const serialized = serializeParameterValue(parameter, valueTypeTestGroup.value);
660
+ expect(serialized).toEqual(testCase.expected);
661
+ });
662
+ });
663
+ });
664
+ });
665
+ });
666
+ });
667
+ describe('advanced serialization', () => {
668
+ it('should serialize correctly query parameter with content with application/json', () => {
669
+ const parameter = {
670
+ name: 'id',
671
+ in: 'query',
672
+ content: {
673
+ 'application/json': {
674
+ schema: {
675
+ type: 'string',
676
+ },
677
+ },
678
+ },
679
+ };
680
+ const parser = new OpenAPIParser({ openapi: '3.0' });
681
+ const opts = normalizeOptions({});
682
+ const field = getField(parser, parameter, '', opts, { operation: {} });
683
+ expect(serializeParameterValue(field, { name: 'test', age: 23 })).toEqual('id={"name":"test","age":23}');
684
+ });
685
+ it('should serialize correctly header parameter with content with application/json', () => {
686
+ const parameter = {
687
+ name: 'x-header',
688
+ in: 'header',
689
+ content: {
690
+ 'application/json': {
691
+ schema: {
692
+ type: 'string',
693
+ },
694
+ },
695
+ },
696
+ };
697
+ const parser = new OpenAPIParser({ openapi: '3.0' });
698
+ const opts = normalizeOptions({});
699
+ const field = getField(parser, parameter, '', opts, { operation: {} });
700
+ expect(serializeParameterValue(field, { name: 'test', age: 23 })).toEqual('{"name":"test","age":23}');
701
+ });
702
+ });
703
+ describe('querystring parameters', () => {
704
+ it('should serialize complex nested object with arrays using form-urlencoded querystring', () => {
705
+ const parameter = {
706
+ name: 'filter',
707
+ in: 'querystring',
708
+ content: {
709
+ 'application/x-www-form-urlencoded': {
710
+ schema: {
711
+ type: 'object',
712
+ properties: {
713
+ name: { type: 'string' },
714
+ age: { type: 'number' },
715
+ tags: {
716
+ type: 'array',
717
+ items: { type: 'string' },
718
+ },
719
+ address: {
720
+ type: 'object',
721
+ properties: {
722
+ city: { type: 'string' },
723
+ zip: { type: 'string' },
724
+ },
725
+ },
726
+ preferences: {
727
+ type: 'object',
728
+ properties: {
729
+ notifications: { type: 'boolean' },
730
+ categories: {
731
+ type: 'array',
732
+ items: { type: 'string' },
733
+ },
734
+ },
735
+ },
736
+ },
737
+ },
738
+ },
739
+ },
740
+ };
741
+ const parser = new OpenAPIParser({ openapi: '3.2' });
742
+ const opts = normalizeOptions({});
743
+ const field = getField(parser, parameter, '', opts, { operation: {} });
744
+ const value = {
745
+ name: 'test',
746
+ age: 23,
747
+ tags: ['admin', 'editor'],
748
+ address: {
749
+ city: 'Test',
750
+ zip: '80-001',
751
+ },
752
+ preferences: {
753
+ notifications: true,
754
+ categories: ['tech', 'science'],
755
+ },
756
+ };
757
+ expect(serializeParameterValue(field, value)).toEqual('name=test&age=23&tags=admin&tags=editor&address%5Bcity%5D=Test&address%5Bzip%5D=80-001&preferences%5Bnotifications%5D=true&preferences%5Bcategories%5D=tech&preferences%5Bcategories%5D=science');
758
+ });
759
+ it('should serialize querystring parameter with json content and primitive value', () => {
760
+ const parameter = {
761
+ name: 'filter',
762
+ in: 'querystring',
763
+ content: {
764
+ 'application/json': {
765
+ schema: {
766
+ type: 'string',
767
+ },
768
+ },
769
+ },
770
+ };
771
+ const parser = new OpenAPIParser({ openapi: '3.2' });
772
+ const opts = normalizeOptions({});
773
+ const field = getField(parser, parameter, '', opts, { operation: {} });
774
+ expect(serializeParameterValue(field, 'test-value')).toEqual('filter="test-value"');
775
+ });
776
+ it('should serialize querystring parameter with schema and style (no content)', () => {
777
+ const parameter = {
778
+ name: 'filter',
779
+ in: 'querystring',
780
+ style: 'form',
781
+ explode: true,
782
+ schema: {
783
+ type: 'object',
784
+ properties: {
785
+ name: { type: 'string' },
786
+ age: { type: 'number' },
787
+ },
788
+ },
789
+ };
790
+ const parser = new OpenAPIParser({ openapi: '3.2' });
791
+ const opts = normalizeOptions({});
792
+ const field = getField(parser, parameter, '', opts, { operation: {} });
793
+ expect(serializeParameterValue(field, { name: 'test', age: 23 })).toEqual('name=test&age=23');
794
+ });
795
+ });
796
+ });
797
+ describe('OpenAPI sortByRequired', () => {
798
+ it('should equal to the old data when all items have no required props', () => {
799
+ const fields = [
800
+ {
801
+ name: 'loginName',
802
+ required: false,
803
+ },
804
+ {
805
+ name: 'displayName',
806
+ required: false,
807
+ },
808
+ {
809
+ name: 'email',
810
+ required: false,
811
+ },
812
+ {
813
+ name: 'space',
814
+ required: false,
815
+ },
816
+ {
817
+ name: 'type',
818
+ required: false,
819
+ },
820
+ {
821
+ name: 'depIds',
822
+ required: false,
823
+ },
824
+ {
825
+ name: 'depNames',
826
+ required: false,
827
+ },
828
+ {
829
+ name: 'password',
830
+ required: false,
831
+ },
832
+ {
833
+ name: 'pwdControl',
834
+ required: false,
835
+ },
836
+ {
837
+ name: 'csfLevel',
838
+ required: false,
839
+ },
840
+ {
841
+ name: 'priority',
842
+ required: false,
843
+ },
844
+ {
845
+ name: 'siteId',
846
+ required: false,
847
+ },
848
+ ];
849
+ expect(sortByRequired(fields)).toEqual(fields);
850
+ });
851
+ it('other item should be the same order when some of items are required', () => {
852
+ const fields = [
853
+ {
854
+ name: 'loginName',
855
+ required: true,
856
+ },
857
+ {
858
+ name: 'displayName',
859
+ required: false,
860
+ },
861
+ {
862
+ name: 'email',
863
+ required: true,
864
+ },
865
+ {
866
+ name: 'space',
867
+ required: false,
868
+ },
869
+ {
870
+ name: 'type',
871
+ required: false,
872
+ },
873
+ {
874
+ name: 'depIds',
875
+ required: false,
876
+ },
877
+ {
878
+ name: 'depNames',
879
+ required: false,
880
+ },
881
+ {
882
+ name: 'password',
883
+ required: false,
884
+ },
885
+ {
886
+ name: 'pwdControl',
887
+ required: false,
888
+ },
889
+ {
890
+ name: 'csfLevel',
891
+ required: false,
892
+ },
893
+ {
894
+ name: 'priority',
895
+ required: false,
896
+ },
897
+ {
898
+ name: 'siteId',
899
+ required: false,
900
+ },
901
+ ];
902
+ const sortedFields = [
903
+ {
904
+ name: 'loginName',
905
+ required: true,
906
+ },
907
+ {
908
+ name: 'email',
909
+ required: true,
910
+ },
911
+ {
912
+ name: 'displayName',
913
+ required: false,
914
+ },
915
+ {
916
+ name: 'space',
917
+ required: false,
918
+ },
919
+ {
920
+ name: 'type',
921
+ required: false,
922
+ },
923
+ {
924
+ name: 'depIds',
925
+ required: false,
926
+ },
927
+ {
928
+ name: 'depNames',
929
+ required: false,
930
+ },
931
+ {
932
+ name: 'password',
933
+ required: false,
934
+ },
935
+ {
936
+ name: 'pwdControl',
937
+ required: false,
938
+ },
939
+ {
940
+ name: 'csfLevel',
941
+ required: false,
942
+ },
943
+ {
944
+ name: 'priority',
945
+ required: false,
946
+ },
947
+ {
948
+ name: 'siteId',
949
+ required: false,
950
+ },
951
+ ];
952
+ expect(sortByRequired(fields)).toEqual(sortedFields);
953
+ });
954
+ it('should the order of required items is as same as the order parameter', () => {
955
+ const fields = [
956
+ {
957
+ name: 'loginName',
958
+ required: true,
959
+ },
960
+ {
961
+ name: 'displayName',
962
+ required: true,
963
+ },
964
+ {
965
+ name: 'email',
966
+ required: true,
967
+ },
968
+ {
969
+ name: 'space',
970
+ required: false,
971
+ },
972
+ {
973
+ name: 'type',
974
+ required: false,
975
+ },
976
+ {
977
+ name: 'depIds',
978
+ required: false,
979
+ },
980
+ {
981
+ name: 'depNames',
982
+ required: false,
983
+ },
984
+ {
985
+ name: 'password',
986
+ required: false,
987
+ },
988
+ {
989
+ name: 'pwdControl',
990
+ required: false,
991
+ },
992
+ {
993
+ name: 'csfLevel',
994
+ required: false,
995
+ },
996
+ {
997
+ name: 'priority',
998
+ required: false,
999
+ },
1000
+ {
1001
+ name: 'siteId',
1002
+ required: false,
1003
+ },
1004
+ ];
1005
+ expect(sortByRequired(fields, ['siteId', 'displayName', 'loginName', 'email'])).toEqual([
1006
+ {
1007
+ name: 'displayName',
1008
+ required: true,
1009
+ },
1010
+ {
1011
+ name: 'loginName',
1012
+ required: true,
1013
+ },
1014
+ {
1015
+ name: 'email',
1016
+ required: true,
1017
+ },
1018
+ {
1019
+ name: 'space',
1020
+ required: false,
1021
+ },
1022
+ {
1023
+ name: 'type',
1024
+ required: false,
1025
+ },
1026
+ {
1027
+ name: 'depIds',
1028
+ required: false,
1029
+ },
1030
+ {
1031
+ name: 'depNames',
1032
+ required: false,
1033
+ },
1034
+ {
1035
+ name: 'password',
1036
+ required: false,
1037
+ },
1038
+ {
1039
+ name: 'pwdControl',
1040
+ required: false,
1041
+ },
1042
+ {
1043
+ name: 'csfLevel',
1044
+ required: false,
1045
+ },
1046
+ {
1047
+ name: 'priority',
1048
+ required: false,
1049
+ },
1050
+ {
1051
+ name: 'siteId',
1052
+ required: false,
1053
+ },
1054
+ ]);
1055
+ expect(sortByRequired(fields, ['email', 'displayName'])).toEqual([
1056
+ {
1057
+ name: 'email',
1058
+ required: true,
1059
+ },
1060
+ {
1061
+ name: 'displayName',
1062
+ required: true,
1063
+ },
1064
+ {
1065
+ name: 'loginName',
1066
+ required: true,
1067
+ },
1068
+ {
1069
+ name: 'space',
1070
+ required: false,
1071
+ },
1072
+ {
1073
+ name: 'type',
1074
+ required: false,
1075
+ },
1076
+ {
1077
+ name: 'depIds',
1078
+ required: false,
1079
+ },
1080
+ {
1081
+ name: 'depNames',
1082
+ required: false,
1083
+ },
1084
+ {
1085
+ name: 'password',
1086
+ required: false,
1087
+ },
1088
+ {
1089
+ name: 'pwdControl',
1090
+ required: false,
1091
+ },
1092
+ {
1093
+ name: 'csfLevel',
1094
+ required: false,
1095
+ },
1096
+ {
1097
+ name: 'priority',
1098
+ required: false,
1099
+ },
1100
+ {
1101
+ name: 'siteId',
1102
+ required: false,
1103
+ },
1104
+ ]);
1105
+ expect(sortByRequired(fields, ['displayName'])).toEqual([
1106
+ {
1107
+ name: 'displayName',
1108
+ required: true,
1109
+ },
1110
+ {
1111
+ name: 'loginName',
1112
+ required: true,
1113
+ },
1114
+ {
1115
+ name: 'email',
1116
+ required: true,
1117
+ },
1118
+ {
1119
+ name: 'space',
1120
+ required: false,
1121
+ },
1122
+ {
1123
+ name: 'type',
1124
+ required: false,
1125
+ },
1126
+ {
1127
+ name: 'depIds',
1128
+ required: false,
1129
+ },
1130
+ {
1131
+ name: 'depNames',
1132
+ required: false,
1133
+ },
1134
+ {
1135
+ name: 'password',
1136
+ required: false,
1137
+ },
1138
+ {
1139
+ name: 'pwdControl',
1140
+ required: false,
1141
+ },
1142
+ {
1143
+ name: 'csfLevel',
1144
+ required: false,
1145
+ },
1146
+ {
1147
+ name: 'priority',
1148
+ required: false,
1149
+ },
1150
+ {
1151
+ name: 'siteId',
1152
+ required: false,
1153
+ },
1154
+ ]);
1155
+ });
1156
+ });
1157
+ describe('OpenAPI getContentWithLegacyExamles', () => {
1158
+ it('should return undefined if no x-examples/x-example and no content', () => {
1159
+ expect(getContentWithLegacyExamples({})).toBeUndefined();
1160
+ });
1161
+ it('should return unmodified object if no x-examples or x-example', () => {
1162
+ const info = {
1163
+ content: {
1164
+ 'application/json': {},
1165
+ },
1166
+ };
1167
+ const content = getContentWithLegacyExamples(info);
1168
+ expect(content).toStrictEqual(info.content);
1169
+ });
1170
+ it('should create a new content object if no content and x-examples', () => {
1171
+ const info = {
1172
+ 'x-examples': {
1173
+ 'application/json': {
1174
+ name: {
1175
+ value: 'test',
1176
+ },
1177
+ },
1178
+ },
1179
+ };
1180
+ const content = getContentWithLegacyExamples(info);
1181
+ expect(content).toEqual({
1182
+ 'application/json': {
1183
+ examples: {
1184
+ name: {
1185
+ value: 'test',
1186
+ },
1187
+ },
1188
+ },
1189
+ });
1190
+ });
1191
+ it('should create a new content object if no content and x-example', () => {
1192
+ const info = {
1193
+ 'x-example': {
1194
+ 'application/json': 'test',
1195
+ },
1196
+ };
1197
+ const content = getContentWithLegacyExamples(info);
1198
+ expect(content).toEqual({
1199
+ 'application/json': { example: 'test' },
1200
+ });
1201
+ });
1202
+ it('should return copy of content with injected x-example', () => {
1203
+ const info = {
1204
+ 'x-example': {
1205
+ 'application/json': 'test',
1206
+ },
1207
+ content: {
1208
+ 'application/json': {
1209
+ schema: { type: 'string' },
1210
+ },
1211
+ 'text/plain': { schema: { type: 'string' } },
1212
+ },
1213
+ };
1214
+ const content = getContentWithLegacyExamples(info);
1215
+ expect(content).toEqual({
1216
+ 'application/json': { schema: { type: 'string' }, example: 'test' },
1217
+ 'text/plain': { schema: { type: 'string' } },
1218
+ });
1219
+ expect(content).not.toStrictEqual(info.content);
1220
+ expect(content['application/json']).not.toStrictEqual(info.content['application/json']);
1221
+ expect(content['text/plain']).toStrictEqual(info.content['text/plain']);
1222
+ });
1223
+ it('should prefer x-examples over x-example', () => {
1224
+ const info = {
1225
+ 'x-example': {
1226
+ 'application/json': 'test',
1227
+ },
1228
+ 'x-examples': {
1229
+ 'application/json': { name: { value: 'test' } },
1230
+ },
1231
+ content: {
1232
+ 'application/json': {
1233
+ schema: { type: 'string' },
1234
+ },
1235
+ 'text/plain': { schema: { type: 'string' } },
1236
+ },
1237
+ };
1238
+ const content = getContentWithLegacyExamples(info);
1239
+ expect(content).toEqual({
1240
+ 'application/json': { schema: { type: 'string' }, examples: { name: { value: 'test' } } },
1241
+ 'text/plain': { schema: { type: 'string' } },
1242
+ });
1243
+ expect(content).not.toStrictEqual(info.content);
1244
+ expect(content['application/json']).not.toStrictEqual(info.content['application/json']);
1245
+ expect(content['text/plain']).toStrictEqual(info.content['text/plain']);
1246
+ });
1247
+ });
1248
+ describe('getDefinitionName', () => {
1249
+ test('should return the name if pointer match regex', () => {
1250
+ expect(getDefinitionName('#/components/schemas/Call')).toEqual('Call');
1251
+ });
1252
+ test("should return the `undefined` if pointer not match regex or it's absent", () => {
1253
+ expect(getDefinitionName('#/test/path/Call')).toBeUndefined();
1254
+ expect(getDefinitionName()).toBeUndefined();
1255
+ });
1256
+ });
1257
+ describe('isSequentialMediaType', () => {
1258
+ it('should return true for streaming media types', () => {
1259
+ expect(isSequentialMediaType('application/jsonl')).toBe(true);
1260
+ expect(isSequentialMediaType('application/x-ndjson')).toBe(true);
1261
+ expect(isSequentialMediaType('application/json-seq')).toBe(true);
1262
+ expect(isSequentialMediaType('text/event-stream')).toBe(true);
1263
+ expect(isSequentialMediaType('multipart/mixed')).toBe(true);
1264
+ });
1265
+ it('should return false for non-streaming media types', () => {
1266
+ expect(isSequentialMediaType('application/json')).toBe(false);
1267
+ expect(isSequentialMediaType('text/plain')).toBe(false);
1268
+ expect(isSequentialMediaType('application/xml')).toBe(false);
1269
+ expect(isSequentialMediaType('application/octet-stream')).toBe(false);
1270
+ });
1271
+ });
1272
+ describe('langFromMime', () => {
1273
+ it('should return correct language for streaming media types', () => {
1274
+ expect(langFromMime('application/jsonl')).toBe('jsonl');
1275
+ expect(langFromMime('text/event-stream')).toBe('yaml');
1276
+ expect(langFromMime('multipart/mixed')).toBe('multipart-mixed');
1277
+ });
1278
+ it('should return correct language for other media types', () => {
1279
+ expect(langFromMime('application/xml')).toBe('xml');
1280
+ expect(langFromMime('application/json')).toBe('json');
1281
+ expect(langFromMime('text/plain')).toBe('clike');
1282
+ });
1283
+ });
1284
+ describe('OpenAPI 3.2 components/mediaTypes', () => {
1285
+ it('should dereference $ref in content to components/mediaTypes', () => {
1286
+ const definition = {
1287
+ openapi: '3.2.0',
1288
+ info: { title: 'Test', version: '1.0.0' },
1289
+ paths: {},
1290
+ components: {
1291
+ mediaTypes: {
1292
+ PatchResponse: {
1293
+ 'application/json': {
1294
+ schema: { type: 'object', properties: { id: { type: 'string' } } },
1295
+ examples: {
1296
+ default_example: { value: { id: '123' } },
1297
+ },
1298
+ },
1299
+ },
1300
+ },
1301
+ },
1302
+ };
1303
+ const parser = new OpenAPIParser(definition, undefined, normalizeOptions({}));
1304
+ const info = {
1305
+ content: {
1306
+ $ref: '#/components/mediaTypes/PatchResponse',
1307
+ },
1308
+ };
1309
+ const content = getContent(parser, info);
1310
+ expect(content).toEqual({
1311
+ 'application/json': {
1312
+ schema: { type: 'object', properties: { id: { type: 'string' } } },
1313
+ examples: {
1314
+ default_example: { value: { id: '123' } },
1315
+ },
1316
+ },
1317
+ });
1318
+ });
1319
+ it('should return $ref unchanged if content is not a ref', () => {
1320
+ const definition = {
1321
+ openapi: '3.2.0',
1322
+ info: { title: 'Test', version: '1.0.0' },
1323
+ paths: {},
1324
+ };
1325
+ const parser = new OpenAPIParser(definition, undefined, normalizeOptions({}));
1326
+ const info = {
1327
+ content: {
1328
+ 'application/json': {
1329
+ schema: { type: 'string' },
1330
+ },
1331
+ },
1332
+ };
1333
+ const content = getContent(parser, info);
1334
+ expect(content).toEqual({
1335
+ 'application/json': {
1336
+ schema: { type: 'string' },
1337
+ },
1338
+ });
1339
+ });
1340
+ it('should handle $ref in content with x-examples', () => {
1341
+ const definition = {
1342
+ openapi: '3.2.0',
1343
+ info: { title: 'Test', version: '1.0.0' },
1344
+ paths: {},
1345
+ components: {
1346
+ mediaTypes: {
1347
+ PatchResponse: {
1348
+ 'application/json': {
1349
+ schema: { type: 'object' },
1350
+ },
1351
+ },
1352
+ },
1353
+ },
1354
+ };
1355
+ const parser = new OpenAPIParser(definition, undefined, normalizeOptions({}));
1356
+ const info = {
1357
+ content: {
1358
+ $ref: '#/components/mediaTypes/PatchResponse',
1359
+ },
1360
+ 'x-examples': {
1361
+ 'application/json': {
1362
+ test: { value: { id: 'test' } },
1363
+ },
1364
+ },
1365
+ };
1366
+ const content = getContent(parser, info);
1367
+ expect(content).toEqual({
1368
+ 'application/json': {
1369
+ schema: { type: 'object' },
1370
+ examples: {
1371
+ test: { value: { id: 'test' } },
1372
+ },
1373
+ },
1374
+ });
1375
+ });
1376
+ });
1377
+ });
1378
+ //# sourceMappingURL=openapi.test.js.map