@redocly/openapi-docs 3.24.1 → 3.24.2

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 (260) hide show
  1. package/lib/telemetry/RedocTelemetry.js +1 -31
  2. package/package.json +4 -4
  3. package/lib/components/ApiInfo/__tests__/ApiInfo.test.d.ts +0 -1
  4. package/lib/components/ApiInfo/__tests__/ApiInfo.test.js +0 -46
  5. package/lib/components/Callbacks/__tests__/Callbacks.test.d.ts +0 -1
  6. package/lib/components/Callbacks/__tests__/Callbacks.test.js +0 -46
  7. package/lib/components/Content/__tests__/useAutoScroll.test.d.ts +0 -1
  8. package/lib/components/Content/__tests__/useAutoScroll.test.js +0 -88
  9. package/lib/components/ContentItem/__tests__/useIsExpanded.test.d.ts +0 -1
  10. package/lib/components/ContentItem/__tests__/useIsExpanded.test.js +0 -123
  11. package/lib/components/ContentItems/__tests__/Items.test.d.ts +0 -1
  12. package/lib/components/ContentItems/__tests__/Items.test.js +0 -66
  13. package/lib/components/ContentItems/__tests__/VirtualList.test.d.ts +0 -1
  14. package/lib/components/ContentItems/__tests__/VirtualList.test.js +0 -135
  15. package/lib/components/Discriminator/__tests__/DiscriminatorDropdown.test.d.ts +0 -1
  16. package/lib/components/Discriminator/__tests__/DiscriminatorDropdown.test.js +0 -63
  17. package/lib/components/Download/__tests__/DownloadSpecification.test.d.ts +0 -1
  18. package/lib/components/Download/__tests__/DownloadSpecification.test.js +0 -52
  19. package/lib/components/ExpandAllButton/__tests__/ExpandAllButton.test.d.ts +0 -1
  20. package/lib/components/ExpandAllButton/__tests__/ExpandAllButton.test.js +0 -60
  21. package/lib/components/ExpandAllButton/__tests__/helpers.test.d.ts +0 -1
  22. package/lib/components/ExpandAllButton/__tests__/helpers.test.js +0 -133
  23. package/lib/components/Language/__tests__/LanguageDropdown.test.d.ts +0 -1
  24. package/lib/components/Language/__tests__/LanguageDropdown.test.js +0 -23
  25. package/lib/components/Markdown/__tests__/Markdown.test.d.ts +0 -1
  26. package/lib/components/Markdown/__tests__/Markdown.test.js +0 -34
  27. package/lib/components/McpOverview/__tests__/McpOverview.test.d.ts +0 -1
  28. package/lib/components/McpOverview/__tests__/McpOverview.test.js +0 -66
  29. package/lib/components/McpTool/__tests__/McpPrompt.test.d.ts +0 -1
  30. package/lib/components/McpTool/__tests__/McpPrompt.test.js +0 -57
  31. package/lib/components/McpTool/__tests__/McpResource.test.d.ts +0 -1
  32. package/lib/components/McpTool/__tests__/McpResource.test.js +0 -81
  33. package/lib/components/McpTool/__tests__/McpTool.test.d.ts +0 -1
  34. package/lib/components/McpTool/__tests__/McpTool.test.js +0 -82
  35. package/lib/components/MediaTypeSwitch/__tests__/MediaTypesSwitch.test.d.ts +0 -1
  36. package/lib/components/MediaTypeSwitch/__tests__/MediaTypesSwitch.test.js +0 -79
  37. package/lib/components/OperationItem/__tests__/OperationItem.test.d.ts +0 -1
  38. package/lib/components/OperationItem/__tests__/OperationItem.test.js +0 -70
  39. package/lib/components/OperationItem/__tests__/__mocks__/mock-intersection-observer.d.ts +0 -16
  40. package/lib/components/OperationItem/__tests__/__mocks__/mock-intersection-observer.js +0 -42
  41. package/lib/components/Overview/__tests__/Overview.test.d.ts +0 -1
  42. package/lib/components/Overview/__tests__/Overview.test.js +0 -59
  43. package/lib/components/PayloadSamples/__tests__/Example.test.d.ts +0 -1
  44. package/lib/components/PayloadSamples/__tests__/Example.test.js +0 -36
  45. package/lib/components/PayloadSamples/__tests__/ExampleValue.test.d.ts +0 -1
  46. package/lib/components/PayloadSamples/__tests__/ExampleValue.test.js +0 -197
  47. package/lib/components/PayloadSamples/__tests__/PayloadSamples.test.d.ts +0 -1
  48. package/lib/components/PayloadSamples/__tests__/PayloadSamples.test.js +0 -38
  49. package/lib/components/PropertyDetails/__tests__/Extensions.test.d.ts +0 -1
  50. package/lib/components/PropertyDetails/__tests__/Extensions.test.js +0 -21
  51. package/lib/components/PropertyDetails/__tests__/FieldDetail.test.d.ts +0 -1
  52. package/lib/components/PropertyDetails/__tests__/FieldDetail.test.js +0 -52
  53. package/lib/components/PropertyDetails/__tests__/FieldDetails.test.d.ts +0 -1
  54. package/lib/components/PropertyDetails/__tests__/FieldDetails.test.js +0 -191
  55. package/lib/components/PropertyDetails/__tests__/PropertyDetails.test.d.ts +0 -1
  56. package/lib/components/PropertyDetails/__tests__/PropertyDetails.test.js +0 -365
  57. package/lib/components/PropertyDetails/__tests__/cycleColorsByLevel.test.d.ts +0 -1
  58. package/lib/components/PropertyDetails/__tests__/cycleColorsByLevel.test.js +0 -23
  59. package/lib/components/RedoclyOpenAPIDocs/__tests__/AppProvider.test.d.ts +0 -1
  60. package/lib/components/RedoclyOpenAPIDocs/__tests__/AppProvider.test.js +0 -16
  61. package/lib/components/RedoclyOpenAPIDocs/__tests__/RedoclyOpenAPIDocs.test.d.ts +0 -1
  62. package/lib/components/RedoclyOpenAPIDocs/__tests__/RedoclyOpenAPIDocs.test.js +0 -104
  63. package/lib/components/RenderHook/__tests__/RenderHook.test.d.ts +0 -1
  64. package/lib/components/RenderHook/__tests__/RenderHook.test.js +0 -15
  65. package/lib/components/Replay/__tests__/utils.test.d.ts +0 -1
  66. package/lib/components/Replay/__tests__/utils.test.js +0 -526
  67. package/lib/components/Request/__tests__/RequestDetails.test.d.ts +0 -1
  68. package/lib/components/Request/__tests__/RequestDetails.test.js +0 -98
  69. package/lib/components/RequestSamples/__tests__/Example.test.d.ts +0 -1
  70. package/lib/components/RequestSamples/__tests__/Example.test.js +0 -384
  71. package/lib/components/RequestSamples/__tests__/RequestSamples.test.d.ts +0 -1
  72. package/lib/components/RequestSamples/__tests__/RequestSamples.test.js +0 -226
  73. package/lib/components/RequestSamples/__tests__/useCodeSamples.test.d.ts +0 -1
  74. package/lib/components/RequestSamples/__tests__/useCodeSamples.test.js +0 -64
  75. package/lib/components/ResponseSamples/__tests__/ResponseSamples.test.d.ts +0 -1
  76. package/lib/components/ResponseSamples/__tests__/ResponseSamples.test.js +0 -29
  77. package/lib/components/Responses/__tests__/OperationResponseList.test.d.ts +0 -1
  78. package/lib/components/Responses/__tests__/OperationResponseList.test.js +0 -89
  79. package/lib/components/Responses/__tests__/ResponseDetails.test.d.ts +0 -1
  80. package/lib/components/Responses/__tests__/ResponseDetails.test.js +0 -111
  81. package/lib/components/Responses/__tests__/ResponsesHeaders.test.d.ts +0 -1
  82. package/lib/components/Responses/__tests__/ResponsesHeaders.test.js +0 -26
  83. package/lib/components/Schema/__tests__/ArraySchema.test.d.ts +0 -1
  84. package/lib/components/Schema/__tests__/ArraySchema.test.js +0 -93
  85. package/lib/components/Schema/__tests__/ObjectSchema.test.d.ts +0 -1
  86. package/lib/components/Schema/__tests__/ObjectSchema.test.js +0 -115
  87. package/lib/components/Schema/__tests__/OneOfSchema.test.d.ts +0 -1
  88. package/lib/components/Schema/__tests__/OneOfSchema.test.js +0 -33
  89. package/lib/components/Schema/__tests__/Schema.test.d.ts +0 -1
  90. package/lib/components/Schema/__tests__/Schema.test.js +0 -67
  91. package/lib/components/Schema/__tests__/useOneOfLocationIdx.test.d.ts +0 -1
  92. package/lib/components/Schema/__tests__/useOneOfLocationIdx.test.js +0 -22
  93. package/lib/components/SchemaCatalogLink/__tests__/SchemaCatalogLink.test.d.ts +0 -1
  94. package/lib/components/SchemaCatalogLink/__tests__/SchemaCatalogLink.test.js +0 -95
  95. package/lib/components/Security/__tests__/Security.test.d.ts +0 -1
  96. package/lib/components/Security/__tests__/Security.test.js +0 -38
  97. package/lib/components/Security/__tests__/SecurityButton.test.d.ts +0 -1
  98. package/lib/components/Security/__tests__/SecurityButton.test.js +0 -92
  99. package/lib/components/Security/__tests__/SecurityModal.test.d.ts +0 -1
  100. package/lib/components/Security/__tests__/SecurityModal.test.js +0 -172
  101. package/lib/components/ServerList/__tests__/ServerList.test.d.ts +0 -1
  102. package/lib/components/ServerList/__tests__/ServerList.test.js +0 -83
  103. package/lib/components/Tabs/__tests__/Tabs.test.d.ts +0 -1
  104. package/lib/components/Tabs/__tests__/Tabs.test.js +0 -27
  105. package/lib/components/ViewNested/__tests__/ViewNested.test.d.ts +0 -1
  106. package/lib/components/ViewNested/__tests__/ViewNested.test.js +0 -42
  107. package/lib/components/__tests__/Samples/ExampleSwitch.test.d.ts +0 -1
  108. package/lib/components/__tests__/Samples/ExampleSwitch.test.js +0 -45
  109. package/lib/components/__tests__/Samples/use-example-key.test.d.ts +0 -1
  110. package/lib/components/__tests__/Samples/use-example-key.test.js +0 -28
  111. package/lib/components/__tests__/common/ClearButton.test.d.ts +0 -1
  112. package/lib/components/__tests__/common/ClearButton.test.js +0 -18
  113. package/lib/components/__tests__/common/Dropdown.test.d.ts +0 -1
  114. package/lib/components/__tests__/common/Dropdown.test.js +0 -52
  115. package/lib/components/__tests__/mocks/examples.d.ts +0 -4
  116. package/lib/components/__tests__/mocks/examples.js +0 -115
  117. package/lib/components/common/__tests__/Dropdown.test.d.ts +0 -1
  118. package/lib/components/common/__tests__/Dropdown.test.js +0 -129
  119. package/lib/components/common/__tests__/LinkToField.test.d.ts +0 -1
  120. package/lib/components/common/__tests__/LinkToField.test.js +0 -39
  121. package/lib/jotai/__tests__/app.test.d.ts +0 -1
  122. package/lib/jotai/__tests__/app.test.js +0 -53
  123. package/lib/models/__tests__/Callback.test.d.ts +0 -1
  124. package/lib/models/__tests__/Callback.test.js +0 -15
  125. package/lib/models/__tests__/FieldModel.test.d.ts +0 -1
  126. package/lib/models/__tests__/FieldModel.test.js +0 -117
  127. package/lib/models/__tests__/MediaContent.test.d.ts +0 -1
  128. package/lib/models/__tests__/MediaContent.test.js +0 -105
  129. package/lib/models/__tests__/Operation.test.d.ts +0 -1
  130. package/lib/models/__tests__/Operation.test.js +0 -459
  131. package/lib/models/__tests__/Response.test.d.ts +0 -1
  132. package/lib/models/__tests__/Response.test.js +0 -221
  133. package/lib/models/__tests__/Schema.circular.test.d.ts +0 -1
  134. package/lib/models/__tests__/Schema.circular.test.js +0 -694
  135. package/lib/models/__tests__/Schema.test.d.ts +0 -1
  136. package/lib/models/__tests__/Schema.test.js +0 -1395
  137. package/lib/models/__tests__/example.test.d.ts +0 -1
  138. package/lib/models/__tests__/example.test.js +0 -90
  139. package/lib/models/__tests__/group.test.d.ts +0 -1
  140. package/lib/models/__tests__/group.test.js +0 -52
  141. package/lib/models/__tests__/helpers.d.ts +0 -5
  142. package/lib/models/__tests__/helpers.js +0 -62
  143. package/lib/models/__tests__/request.test.d.ts +0 -1
  144. package/lib/models/__tests__/request.test.js +0 -119
  145. package/lib/services/__tests__/OpenAPIParser.test.d.ts +0 -1
  146. package/lib/services/__tests__/OpenAPIParser.test.js +0 -80
  147. package/lib/services/__tests__/check.test.d.ts +0 -1
  148. package/lib/services/__tests__/check.test.js +0 -22
  149. package/lib/services/__tests__/utils.test.d.ts +0 -1
  150. package/lib/services/__tests__/utils.test.js +0 -42
  151. package/lib/services/code-samples/__tests__/apply-environments.test.d.ts +0 -1
  152. package/lib/services/code-samples/__tests__/apply-environments.test.js +0 -64
  153. package/lib/services/code-samples/__tests__/build-code-samples.test.d.ts +0 -1
  154. package/lib/services/code-samples/__tests__/build-code-samples.test.js +0 -70
  155. package/lib/services/code-samples/__tests__/convertSampleToString.test.d.ts +0 -1
  156. package/lib/services/code-samples/__tests__/convertSampleToString.test.js +0 -116
  157. package/lib/services/code-samples/__tests__/generator-data-value.test.d.ts +0 -1
  158. package/lib/services/code-samples/__tests__/generator-data-value.test.js +0 -277
  159. package/lib/services/code-samples/__tests__/generator-serialized-value.test.d.ts +0 -1
  160. package/lib/services/code-samples/__tests__/generator-serialized-value.test.js +0 -258
  161. package/lib/services/code-samples/__tests__/generator-value.test.d.ts +0 -1
  162. package/lib/services/code-samples/__tests__/generator-value.test.js +0 -273
  163. package/lib/services/code-samples/__tests__/generator.test.d.ts +0 -249
  164. package/lib/services/code-samples/__tests__/generator.test.js +0 -1201
  165. package/lib/services/code-samples/__tests__/get-example-value-by-mime-type.test.d.ts +0 -1
  166. package/lib/services/code-samples/__tests__/get-example-value-by-mime-type.test.js +0 -31
  167. package/lib/services/code-samples/httpsnippet/__tests__/device-authorization.test.d.ts +0 -1
  168. package/lib/services/code-samples/httpsnippet/__tests__/device-authorization.test.js +0 -222
  169. package/lib/services/code-samples/httpsnippet/helpers/__tests__/code-helpers.test.d.ts +0 -1
  170. package/lib/services/code-samples/httpsnippet/helpers/__tests__/code-helpers.test.js +0 -129
  171. package/lib/services/code-samples/httpsnippet/helpers/__tests__/string-utility.test.d.ts +0 -1
  172. package/lib/services/code-samples/httpsnippet/helpers/__tests__/string-utility.test.js +0 -49
  173. package/lib/services/code-samples/httpsnippet/targets/csharp/__tests__/httpclient.test.d.ts +0 -1
  174. package/lib/services/code-samples/httpsnippet/targets/csharp/__tests__/httpclient.test.js +0 -172
  175. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/__tests__/httpclient.test.d.ts +0 -1
  176. package/lib/services/code-samples/httpsnippet/targets/csharpNewtonsoft/__tests__/httpclient.test.js +0 -172
  177. package/lib/services/code-samples/httpsnippet/targets/go/__tests__/native.test.d.ts +0 -1
  178. package/lib/services/code-samples/httpsnippet/targets/go/__tests__/native.test.js +0 -130
  179. package/lib/services/code-samples/httpsnippet/targets/java/__tests__/httpclient.test.d.ts +0 -1
  180. package/lib/services/code-samples/httpsnippet/targets/java/__tests__/httpclient.test.js +0 -191
  181. package/lib/services/code-samples/httpsnippet/targets/java8/__tests__/apachehttp.test.d.ts +0 -1
  182. package/lib/services/code-samples/httpsnippet/targets/java8/__tests__/apachehttp.test.js +0 -172
  183. package/lib/services/code-samples/httpsnippet/targets/javascript/__tests__/fetch.test.d.ts +0 -1
  184. package/lib/services/code-samples/httpsnippet/targets/javascript/__tests__/fetch.test.js +0 -85
  185. package/lib/services/code-samples/httpsnippet/targets/node/__tests__/fetch.test.d.ts +0 -1
  186. package/lib/services/code-samples/httpsnippet/targets/node/__tests__/fetch.test.js +0 -85
  187. package/lib/services/code-samples/httpsnippet/targets/php/__tests__/curl.test.d.ts +0 -1
  188. package/lib/services/code-samples/httpsnippet/targets/php/__tests__/curl.test.js +0 -126
  189. package/lib/services/code-samples/httpsnippet/targets/python/__tests__/requests.test.d.ts +0 -1
  190. package/lib/services/code-samples/httpsnippet/targets/python/__tests__/requests.test.js +0 -105
  191. package/lib/services/code-samples/httpsnippet/targets/r/__tests__/httr.test.d.ts +0 -1
  192. package/lib/services/code-samples/httpsnippet/targets/r/__tests__/httr.test.js +0 -126
  193. package/lib/services/code-samples/httpsnippet/targets/ruby/__tests__/native.test.d.ts +0 -1
  194. package/lib/services/code-samples/httpsnippet/targets/ruby/__tests__/native.test.js +0 -129
  195. package/lib/services/code-samples/httpsnippet/targets/shell/__tests__/curl.test.d.ts +0 -1
  196. package/lib/services/code-samples/httpsnippet/targets/shell/__tests__/curl.test.js +0 -129
  197. package/lib/services/config-options/__tests__/helpers.test.d.ts +0 -1
  198. package/lib/services/config-options/__tests__/helpers.test.js +0 -234
  199. package/lib/services/history/__tests__/helpers.test.d.ts +0 -1
  200. package/lib/services/history/__tests__/helpers.test.js +0 -19
  201. package/lib/services/menu/__tests__/buildNestedTagsItems.test.d.ts +0 -1
  202. package/lib/services/menu/__tests__/buildNestedTagsItems.test.js +0 -109
  203. package/lib/services/menu/__tests__/builder.test.d.ts +0 -1
  204. package/lib/services/menu/__tests__/builder.test.js +0 -307
  205. package/lib/services/menu/__tests__/operation.test.d.ts +0 -1
  206. package/lib/services/menu/__tests__/operation.test.js +0 -240
  207. package/lib/services/menu/__tests__/tags.test.d.ts +0 -1
  208. package/lib/services/menu/__tests__/tags.test.js +0 -71
  209. package/lib/telemetry/__tests__/RedocTelemetry.test.d.ts +0 -1
  210. package/lib/telemetry/__tests__/RedocTelemetry.test.js +0 -107
  211. package/lib/testProviders.d.ts +0 -6
  212. package/lib/testProviders.js +0 -14
  213. package/lib/utils/__tests__/areArraysEqual.test.d.ts +0 -1
  214. package/lib/utils/__tests__/areArraysEqual.test.js +0 -33
  215. package/lib/utils/__tests__/argValuesHelpers.d.ts +0 -1
  216. package/lib/utils/__tests__/argValuesHelpers.js +0 -56
  217. package/lib/utils/__tests__/calculateMaxLength.test.d.ts +0 -1
  218. package/lib/utils/__tests__/calculateMaxLength.test.js +0 -119
  219. package/lib/utils/__tests__/configure-helpers.test.d.ts +0 -1
  220. package/lib/utils/__tests__/configure-helpers.test.js +0 -356
  221. package/lib/utils/__tests__/convertSwagger2OpenAPI.test.d.ts +0 -1
  222. package/lib/utils/__tests__/convertSwagger2OpenAPI.test.js +0 -392
  223. package/lib/utils/__tests__/debounce.test.d.ts +0 -1
  224. package/lib/utils/__tests__/debounce.test.js +0 -54
  225. package/lib/utils/__tests__/debug.test.d.ts +0 -1
  226. package/lib/utils/__tests__/debug.test.js +0 -23
  227. package/lib/utils/__tests__/dom.test.d.ts +0 -1
  228. package/lib/utils/__tests__/dom.test.js +0 -108
  229. package/lib/utils/__tests__/getBreadcrumbs.test.d.ts +0 -1
  230. package/lib/utils/__tests__/getBreadcrumbs.test.js +0 -98
  231. package/lib/utils/__tests__/hasNestedFields.test.d.ts +0 -1
  232. package/lib/utils/__tests__/hasNestedFields.test.js +0 -147
  233. package/lib/utils/__tests__/helpers.test.d.ts +0 -1
  234. package/lib/utils/__tests__/helpers.test.js +0 -174
  235. package/lib/utils/__tests__/isMobile.test.d.ts +0 -1
  236. package/lib/utils/__tests__/isMobile.test.js +0 -28
  237. package/lib/utils/__tests__/loadAndBundleSpec.test.d.ts +0 -1
  238. package/lib/utils/__tests__/loadAndBundleSpec.test.js +0 -22
  239. package/lib/utils/__tests__/local-storage.test.d.ts +0 -1
  240. package/lib/utils/__tests__/local-storage.test.js +0 -48
  241. package/lib/utils/__tests__/object.test.d.ts +0 -1
  242. package/lib/utils/__tests__/object.test.js +0 -45
  243. package/lib/utils/__tests__/openapi.test.d.ts +0 -1
  244. package/lib/utils/__tests__/openapi.test.js +0 -1378
  245. package/lib/utils/__tests__/path.test.d.ts +0 -1
  246. package/lib/utils/__tests__/path.test.js +0 -16
  247. package/lib/utils/__tests__/queryString.test.d.ts +0 -1
  248. package/lib/utils/__tests__/queryString.test.js +0 -60
  249. package/lib/utils/__tests__/replaceVariables.test.d.ts +0 -1
  250. package/lib/utils/__tests__/replaceVariables.test.js +0 -46
  251. package/lib/utils/__tests__/simplifyAstStructure.test.d.ts +0 -1
  252. package/lib/utils/__tests__/simplifyAstStructure.test.js +0 -26
  253. package/lib/utils/__tests__/sort.test.d.ts +0 -1
  254. package/lib/utils/__tests__/sort.test.js +0 -16
  255. package/lib/utils/__tests__/string.test.d.ts +0 -1
  256. package/lib/utils/__tests__/string.test.js +0 -16
  257. package/lib/utils/__tests__/theme-helpers.test.d.ts +0 -1
  258. package/lib/utils/__tests__/theme-helpers.test.js +0 -24
  259. package/lib/utils/__tests__/url.test.d.ts +0 -1
  260. package/lib/utils/__tests__/url.test.js +0 -134
@@ -1 +0,0 @@
1
- export {};
@@ -1,90 +0,0 @@
1
- import { getExamples } from '../example.js';
2
- import { normalizeOptions, OpenAPIParser } from '../../services/index.js';
3
- describe('Models', () => {
4
- describe('getExamples', () => {
5
- const testDefinition = {
6
- openapi: '3.2.0',
7
- info: {
8
- title: 'Test API',
9
- version: '1.0.0',
10
- },
11
- paths: {},
12
- };
13
- const opts = normalizeOptions({});
14
- const parser = new OpenAPIParser(testDefinition, undefined, opts);
15
- describe('OpenAPI 3.2 field priority', () => {
16
- it('should prioritize dataValue over serializedValue and value', () => {
17
- const exampleInput = {
18
- dataValue: { foo: 'bar', count: 42 },
19
- serializedValue: '{"foo":"baz"}',
20
- value: { foo: 'old' },
21
- };
22
- const result = getExamples({
23
- parser,
24
- infoOrRef: exampleInput,
25
- mime: 'application/json',
26
- });
27
- expect(result.value).toEqual({ foo: 'bar', count: 42 });
28
- expect(result.rawValue).toEqual({ foo: 'bar', count: 42 });
29
- });
30
- it('should prioritize serializedValue over value when dataValue is absent', () => {
31
- const exampleInput = {
32
- serializedValue: 'flag=true',
33
- value: { flag: false },
34
- };
35
- const result = getExamples({
36
- parser,
37
- infoOrRef: exampleInput,
38
- mime: 'application/x-www-form-urlencoded',
39
- });
40
- expect(result.value).toBe('flag=true');
41
- expect(result.rawValue).toBe('flag=true');
42
- });
43
- it('should use value for backward compatibility when dataValue and serializedValue are absent', () => {
44
- const exampleInput = {
45
- value: { name: 'John', age: 30 },
46
- };
47
- const result = getExamples({
48
- parser,
49
- infoOrRef: exampleInput,
50
- mime: 'application/json',
51
- });
52
- expect(result.value).toEqual({ name: 'John', age: 30 });
53
- expect(result.rawValue).toEqual({ name: 'John', age: 30 });
54
- });
55
- });
56
- describe('dataValue handling', () => {
57
- it('should handle dataValue with objects and arrays', () => {
58
- const objectExample = getExamples({
59
- parser,
60
- infoOrRef: { value: {}, dataValue: { author: 'A. Writer', title: 'Book' } },
61
- mime: 'application/json',
62
- });
63
- const arrayExample = getExamples({
64
- parser,
65
- infoOrRef: { value: [], dataValue: [1, 2, 3] },
66
- mime: 'application/json',
67
- });
68
- expect(objectExample.value).toEqual({ author: 'A. Writer', title: 'Book' });
69
- expect(arrayExample.value).toEqual([1, 2, 3]);
70
- });
71
- });
72
- describe('serializedValue handling', () => {
73
- it('should handle serializedValue with different formats', () => {
74
- const urlEncodedExample = getExamples({
75
- parser,
76
- infoOrRef: { value: '', serializedValue: 'name=John+Doe&age=30' },
77
- mime: 'application/x-www-form-urlencoded',
78
- });
79
- const xmlExample = getExamples({
80
- parser,
81
- infoOrRef: { value: '', serializedValue: '<user><name>John</name></user>' },
82
- mime: 'application/xml',
83
- });
84
- expect(urlEncodedExample.value).toBe('name=John+Doe&age=30');
85
- expect(xmlExample.value).toBe('<user><name>John</name></user>');
86
- });
87
- });
88
- });
89
- });
90
- //# sourceMappingURL=example.test.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,52 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { getTagOrGroup } from '../group.js';
3
- import { joinWithSeparator } from '../../services/index.js';
4
- import { safeSlugify } from '../../utils/index.js';
5
- describe('getTagOrGroup', () => {
6
- describe('ID generation - new branch for tag/group types', () => {
7
- it('should use joinWithSeparator for tag type with parent id', () => {
8
- const parent = {
9
- id: 'parent-id',
10
- href: '/parent',
11
- name: 'Parent',
12
- type: 'tag',
13
- items: [],
14
- depth: 0,
15
- level: 1,
16
- };
17
- const tag = {
18
- name: 'test-tag',
19
- };
20
- const result = getTagOrGroup('tag', tag, parent);
21
- const expectedId = joinWithSeparator(parent.id, safeSlugify(tag.name));
22
- expect(result.id).toBe(expectedId.toLowerCase());
23
- });
24
- });
25
- describe('Name priority - summary first', () => {
26
- it('should prioritize summary over x-displayName and name', () => {
27
- const tag = {
28
- name: 'fallback-name',
29
- summary: 'summary-name',
30
- 'x-displayName': 'display-name',
31
- };
32
- const result = getTagOrGroup('tag', tag);
33
- expect(result.name).toBe('summary-name');
34
- });
35
- it('should fallback to x-displayName when summary is not present', () => {
36
- const tag = {
37
- name: 'fallback-name',
38
- 'x-displayName': 'display-name',
39
- };
40
- const result = getTagOrGroup('tag', tag);
41
- expect(result.name).toBe('display-name');
42
- });
43
- it('should fallback to name when summary and x-displayName are not present', () => {
44
- const tag = {
45
- name: 'fallback-name',
46
- };
47
- const result = getTagOrGroup('tag', tag);
48
- expect(result.name).toBe('fallback-name');
49
- });
50
- });
51
- });
52
- //# sourceMappingURL=group.test.js.map
@@ -1,5 +0,0 @@
1
- import type { SchemaModel } from '../types';
2
- export declare function circularDetailsPrinter(schema: SchemaModel): string;
3
- export declare function enumDetailsPrinter(schema: SchemaModel): string;
4
- export declare function printSchema(schema: SchemaModel, detailsPrinter?: (schema: SchemaModel) => string, identLevel?: number, inline?: boolean): string;
5
- export declare const replaceCircularJson: () => (_: unknown, value: unknown) => unknown;
@@ -1,62 +0,0 @@
1
- function printType(type) {
2
- return `<${type}>`;
3
- }
4
- function printDescription(description) {
5
- return description ? ` (${description})` : '';
6
- }
7
- export function circularDetailsPrinter(schema) {
8
- return schema.isCircular ? ' !circular' : '';
9
- }
10
- export function enumDetailsPrinter(schema) {
11
- return schema.enum ? `enum: [${schema.enum.toString()}]` : '';
12
- }
13
- export function printSchema(schema, detailsPrinter = () => '', identLevel = 0, inline = false) {
14
- if (!schema)
15
- return '';
16
- const ident = ' '.repeat(identLevel);
17
- if (schema.isPrimitive || schema.isCircular) {
18
- if (schema.type === 'array' && schema.items) {
19
- return `${inline ? ' ' : ident}[${printType(schema.items.type)}${detailsPrinter(schema.items)}]${printDescription(schema.items.description)}`;
20
- }
21
- else {
22
- return `${inline ? ' ' : ident}${printType(schema.displayType)}${detailsPrinter(schema)}${printDescription(schema.description)}`;
23
- }
24
- }
25
- if (schema.oneOf) {
26
- return (`${inline ? ' ' : ident}oneOf\n` +
27
- schema.oneOf
28
- .map((sub) => {
29
- return (`${ident} ${sub.title || sub.displayType} ->` +
30
- printSchema(sub, detailsPrinter, identLevel + 2, true));
31
- })
32
- .join('\n'));
33
- }
34
- if (schema.fields) {
35
- const prefix = inline ? '\n' : '';
36
- return (prefix +
37
- schema.fields
38
- .map((f) => {
39
- return `${ident}${f.name}${f.required ? '*' : ''}:${printSchema(f.schema, detailsPrinter, identLevel + 1, true)}`;
40
- })
41
- .join('\n'));
42
- }
43
- if (schema.items) {
44
- return (`${inline ? ' ' : ident}[\n` +
45
- printSchema(schema.items, detailsPrinter, identLevel) +
46
- `\n${inline ? ident.slice(0, -2) : ident}]`);
47
- }
48
- return ' error';
49
- }
50
- export const replaceCircularJson = () => {
51
- const visited = new WeakSet();
52
- return (_, value) => {
53
- if (typeof value === 'object' && value !== null) {
54
- if (visited.has(value)) {
55
- return;
56
- }
57
- visited.add(value);
58
- }
59
- return value;
60
- };
61
- };
62
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,119 +0,0 @@
1
- import { parseYaml } from '@redocly/openapi-core';
2
- import { outdent } from 'outdent';
3
- import { getRequestBody } from '../request.js';
4
- import { normalizeOptions, OpenAPIParser } from '../../services/index.js';
5
- const opts = normalizeOptions({});
6
- describe('request', () => {
7
- describe('getRequestBody', () => {
8
- let parser, props;
9
- beforeEach(() => {
10
- parser = new OpenAPIParser({ openapi: '3.0.0' }, undefined, opts);
11
- props = {
12
- parser,
13
- infoOrRef: {},
14
- options: opts,
15
- isEvent: false,
16
- };
17
- });
18
- test('should work with default props', () => {
19
- const consoleError = vi.spyOn(global.console, 'error');
20
- const req = getRequestBody(props);
21
- expect(consoleError).not.toHaveBeenCalled();
22
- expect(req).toEqual({ description: '', required: undefined });
23
- });
24
- test('should work with set required', () => {
25
- const consoleError = vi.spyOn(global.console, 'error');
26
- props.infoOrRef.required = false;
27
- const req = getRequestBody(props);
28
- expect(consoleError).not.toHaveBeenCalled();
29
- expect(req).toEqual({ description: '', required: false });
30
- });
31
- test('should have correct field property when it includes allOf', () => {
32
- const spec = parseYaml(outdent `
33
- openapi: 3.0.0
34
- paths:
35
- /user:
36
- post:
37
- tags:
38
- - user
39
- summary: Create user
40
- description: This can only be done by the logged in user.
41
- operationId: createUser
42
- requestBody:
43
- content:
44
- application/json:
45
- schema:
46
- $ref: '#/components/schemas/User'
47
- description: Created user object
48
- required: true
49
- components:
50
- schemas:
51
- User:
52
- allOf:
53
- - type: object
54
- properties:
55
- name:
56
- type: string
57
- description: correct description name
58
- readOnly: false
59
- writeOnly: false
60
- allOf:
61
- - $ref: '#/components/schemas/NameField'
62
- NameField:
63
- description: name description
64
- readOnly: true
65
- writeOnly: true
66
- `);
67
- parser = new OpenAPIParser(spec, undefined, opts);
68
- const req = getRequestBody({
69
- parser,
70
- infoOrRef: spec.paths['/user'].post.requestBody,
71
- options: opts,
72
- isEvent: false,
73
- operation: {},
74
- });
75
- expect(req.content?.mediaTypes[0].schema?.fields?.[0].schema.readOnly).toBe(false);
76
- expect(req.content?.mediaTypes[0].schema?.fields?.[0].schema.writeOnly).toBe(false);
77
- expect(req.content?.mediaTypes[0].schema?.fields?.[0].description).toMatchInlineSnapshot(`"correct description name"`);
78
- });
79
- test('should dereference $ref in requestBody content to components/mediaTypes (OpenAPI 3.2)', () => {
80
- const spec = parseYaml(outdent `
81
- openapi: 3.2.0
82
- info:
83
- title: Test
84
- version: 1.0.0
85
- paths:
86
- /test:
87
- post:
88
- operationId: test
89
- requestBody:
90
- required: true
91
- content:
92
- $ref: '#/components/mediaTypes/PatchRequest'
93
- responses:
94
- '204':
95
- description: No content
96
- components:
97
- mediaTypes:
98
- PatchRequest:
99
- application/json:
100
- schema:
101
- type: string
102
- `);
103
- parser = new OpenAPIParser(spec, undefined, opts);
104
- const req = getRequestBody({
105
- parser,
106
- infoOrRef: spec.paths['/test'].post.requestBody,
107
- options: opts,
108
- isEvent: false,
109
- operation: { pointer: '#/paths/~1test/post' },
110
- });
111
- expect(req.required).toBe(true);
112
- expect(req.content).toBeDefined();
113
- expect(req.content?.mediaTypes).toHaveLength(1);
114
- expect(req.content?.mediaTypes[0].name).toBe('application/json');
115
- expect(req.content?.mediaTypes[0].schema?.type).toBe('string');
116
- });
117
- });
118
- });
119
- //# sourceMappingURL=request.test.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,80 +0,0 @@
1
- import { OpenAPIParser } from '../OpenAPIParser.js';
2
- import { normalizeOptions } from '../config-options/index.js';
3
- const opts = normalizeOptions({});
4
- describe('Models', () => {
5
- describe('Schema', () => {
6
- let parser;
7
- test('should hoist oneOfs when mergin allOf', async () => {
8
- const spec = (await import('./fixtures/oneOfHoist.json'))
9
- .default;
10
- parser = new OpenAPIParser(spec, undefined, opts);
11
- expect(parser.mergeAllOf(spec.components?.schemas?.test)).toMatchSnapshot();
12
- });
13
- test('should not crash on self-referencing array in allOf', async () => {
14
- const spec = (await import('./fixtures/allOfSelfReferencingArray.json'))
15
- .default;
16
- parser = new OpenAPIParser(spec, undefined, opts);
17
- expect(parser.mergeAllOf(spec.components?.schemas?.Test)).toMatchSnapshot();
18
- });
19
- test('should get schema name from named schema', async () => {
20
- const spec = (await import('./fixtures/mergeAllOf.json'))
21
- .default;
22
- parser = new OpenAPIParser(spec, undefined, opts);
23
- const schema = parser.mergeAllOf(spec.components?.schemas?.Case1, '#/components/schemas/Case1');
24
- expect(schema.title).toEqual('Case1');
25
- });
26
- test('should get schema name from first allOf', async () => {
27
- const spec = (await import('./fixtures/mergeAllOf.json'))
28
- .default;
29
- parser = new OpenAPIParser(spec, undefined, opts);
30
- const Case2 = spec.components?.schemas?.Case2;
31
- const schema = parser.mergeAllOf(Case2.properties.a, '#components/schemas/Case2/properties/a');
32
- expect(schema.title).toEqual('Bar');
33
- });
34
- test('should get schema name from named schema in allOf', async () => {
35
- const spec = (await import('./fixtures/mergeAllOf.json'))
36
- .default;
37
- parser = new OpenAPIParser(spec, undefined, opts);
38
- const schema = parser.mergeAllOf(spec.components?.schemas?.Case3?.schemas?.Foo, '#components/schemas/Case3/schemas/Foo');
39
- expect(schema.title).toEqual('Foo');
40
- });
41
- test('should merge oneOf to inside allOff', async () => {
42
- // TODO: should hoist
43
- const spec = (await import('./fixtures/mergeAllOf.json'))
44
- .default;
45
- parser = new OpenAPIParser(spec, undefined, opts);
46
- const schema = parser.mergeAllOf(spec.components?.schemas?.Case4);
47
- expect(schema.title).toEqual('Foo');
48
- expect(schema['x-parentRefs']).toHaveLength(1);
49
- expect(schema['x-parentRefs'][0]).toEqual('#/components/schemas/Ref');
50
- expect(schema.oneOf).toEqual([{ title: 'Bar' }, { title: 'Baz' }]);
51
- });
52
- test('should preserve discriminated union when OAS 3.1 mergeRefs wraps $ref in allOf', async () => {
53
- const spec = (await import('./fixtures/discriminatorWithSiblingRef.json'))
54
- .default;
55
- parser = new OpenAPIParser(spec, undefined, opts);
56
- const merged = parser.mergeAllOf(spec.components?.schemas?.WithSiblingRef, '#/components/schemas/WithSiblingRef');
57
- const expectedDiscriminator = (spec.components?.schemas).Discriminated.discriminator;
58
- expect(merged.discriminator).toEqual(expectedDiscriminator);
59
- expect(merged.oneOf).toHaveLength(2);
60
- expect(merged.oneOf?.[0]).toMatchObject({ $ref: '#/components/schemas/OptionA' });
61
- expect(merged.oneOf?.[1]).toMatchObject({ $ref: '#/components/schemas/OptionB' });
62
- });
63
- test('should preserve discriminated union for the same allOf on OAS 3.0 (no mergeRefs)', async () => {
64
- const loaded = (await import('./fixtures/discriminatorWithSiblingRef.json'))
65
- .default;
66
- const spec = {
67
- ...loaded,
68
- openapi: '3.0.3',
69
- };
70
- parser = new OpenAPIParser(spec, undefined, opts);
71
- const merged = parser.mergeAllOf(spec.components?.schemas?.WithSiblingRef, '#/components/schemas/WithSiblingRef');
72
- const expectedDiscriminator = (spec.components?.schemas).Discriminated.discriminator;
73
- expect(merged.discriminator).toEqual(expectedDiscriminator);
74
- expect(merged.oneOf).toHaveLength(2);
75
- expect(merged.oneOf?.[0]).toMatchObject({ $ref: '#/components/schemas/OptionA' });
76
- expect(merged.oneOf?.[1]).toMatchObject({ $ref: '#/components/schemas/OptionB' });
77
- });
78
- });
79
- });
80
- //# sourceMappingURL=OpenAPIParser.test.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,22 +0,0 @@
1
- import { isHostAllowed } from '../check.js';
2
- describe('license check', () => {
3
- test('isHostAllowed should work properly', () => {
4
- expect(isHostAllowed('', [])).toBe(false);
5
- expect(isHostAllowed('dummyHost', [])).toBe(false);
6
- expect(isHostAllowed('localhost', [])).toBe(true);
7
- expect(isHostAllowed('.localhost', [])).toBe(true);
8
- expect(isHostAllowed('127.0.0.1', [])).toBe(true);
9
- expect(isHostAllowed('acme.com', ['acme.com'])).toBe(true);
10
- expect(isHostAllowed('sub.acme.com', ['acme.com'])).toBe(true);
11
- expect(isHostAllowed('fakeacme.com', ['acme.com'])).toBe(false);
12
- expect(isHostAllowed('fakeacme.com', ['.acme.com'])).toBe(false);
13
- expect(isHostAllowed('acme.com', ['acme*'])).toBe(false);
14
- expect(isHostAllowed('acme.app.com', ['acme*com'])).toBe(false);
15
- expect(isHostAllowed('acme.app.com', ['acme*acme.com'])).toBe(false);
16
- expect(isHostAllowed('start-fakeAcmeVercel.com', ['start*Vercel.com'])).toBe(false);
17
- expect(isHostAllowed('start-middle-end.vercel.com', ['start*end.vercel.com'])).toBe(true);
18
- expect(isHostAllowed('start-acme.vercel.com', ['start*.vercel.com'])).toBe(true);
19
- expect(isHostAllowed('api-acme.vercel.com', ['*acme.vercel.com'])).toBe(true);
20
- });
21
- });
22
- //# sourceMappingURL=check.test.js.map
@@ -1 +0,0 @@
1
- export {};
@@ -1,42 +0,0 @@
1
- import { isSameMime, normalizeMimeType, unescapeServerVariables, arrayMergeStrategy, } from '../utils.js';
2
- describe('services utils', () => {
3
- test('isSameMime should equal mime', () => {
4
- expect(isSameMime('application/json;charset', 'application/json;charset=UTF-8')).toBeTruthy();
5
- expect(isSameMime('app/json;charset', 'application/json;charset=UTF-8')).toBeFalsy();
6
- expect(isSameMime('app/json;charset', '')).toBeFalsy();
7
- });
8
- test('normalizeMimeType should return correct value', () => {
9
- expect(normalizeMimeType('application/json;charset')).toBe('application/json');
10
- expect(normalizeMimeType('')).toBeUndefined();
11
- expect(normalizeMimeType('application')).toBe('application');
12
- });
13
- test('unescapeServerVariables should return string with escaped brackets', () => {
14
- expect(unescapeServerVariables('https://%7BsomeVar%7D/dev/echo/case-11_1')).toBe('https://{someVar}/dev/echo/case-11_1');
15
- expect(unescapeServerVariables('https://{someVar}/dev/echo/case-11_1')).toBe('https://{someVar}/dev/echo/case-11_1');
16
- expect(unescapeServerVariables('https://api./{someVar}/dev/echo/case-11_1')).toBe('https://api.{someVar}/dev/echo/case-11_1');
17
- });
18
- test('arrayMergeStrategy should leave the second array value if two arrays of primitives provided', () => {
19
- expect(arrayMergeStrategy(['test1'], ['test2'])).toEqual(['test2']);
20
- });
21
- test('arrayMergeStrategy should leave the second array value if two arrays of primitives with different length provided', () => {
22
- expect(arrayMergeStrategy(['test1', 'test2'], ['test3'])).toEqual(['test3']);
23
- });
24
- test('arrayMergeStrategy should merge two arrays of arrays into one', () => {
25
- expect(arrayMergeStrategy([['test1']], [['test2']])).toEqual([['test1'], ['test2']]);
26
- });
27
- test('arrayMergeStrategy should merge two arrays of objects into one', () => {
28
- expect(arrayMergeStrategy([{ id: 0, name: 'test1' }], [{ name: 'test2' }])).toEqual([
29
- { id: 0, name: 'test2' },
30
- ]);
31
- });
32
- test('arrayMergeStrategy should merge two arrays of objects even if the first array is empty', () => {
33
- expect(arrayMergeStrategy([], [{ name: 'test1' }])).toEqual([{ name: 'test1' }]);
34
- });
35
- test('arrayMergeStrategy should merge two arrays of of objects of a different length', () => {
36
- expect(arrayMergeStrategy([{ id: 0, name: 'test1' }], [{ name: 'test2' }, { id: 1, name: 'test3' }])).toEqual([
37
- { id: 0, name: 'test2' },
38
- { id: 1, name: 'test3' },
39
- ]);
40
- });
41
- });
42
- //# sourceMappingURL=utils.test.js.map
@@ -1,64 +0,0 @@
1
- import { applyEnvironments } from '../apply-environments.js';
2
- describe('applyEnvironments', () => {
3
- it('returns the same array when there are no env variables', () => {
4
- const samples = [{ lang: 'curl', source: 'curl {{host}}' }];
5
- expect(applyEnvironments(samples, undefined)).toBe(samples);
6
- });
7
- it('returns the same array when there are no samples', () => {
8
- const samples = [];
9
- expect(applyEnvironments(samples, { values: { host: 'example.com' } })).toBe(samples);
10
- });
11
- it('returns the same array when env values are empty', () => {
12
- const samples = [{ source: 'curl {{host}}' }];
13
- expect(applyEnvironments(samples, { values: {} })).toBe(samples);
14
- });
15
- it('substitutes {{var}} placeholders from env values', () => {
16
- const [result] = applyEnvironments([{ source: 'curl https://{{host}}/v1' }], {
17
- values: { host: 'api.example.com' },
18
- });
19
- expect(result.source).toBe('curl https://api.example.com/v1');
20
- });
21
- it('keeps the original placeholder when no env value matches', () => {
22
- const [result] = applyEnvironments([{ source: 'curl {{missing}}' }], {
23
- values: { host: 'api.example.com' },
24
- });
25
- expect(result.source).toBe('curl {{missing}}');
26
- });
27
- it('overrides defaults with server-specific values for the current server', () => {
28
- const envVariables = {
29
- values: { token: 'default-token' },
30
- serverValues: { 'https://prod.example.com': { token: 'prod-token' } },
31
- };
32
- const [result] = applyEnvironments([{ source: '{{token}}' }], envVariables, {
33
- server: 'https://prod.example.com',
34
- });
35
- expect(result.source).toBe('prod-token');
36
- });
37
- it('uses default values when the current server has no overrides', () => {
38
- const envVariables = {
39
- values: { token: 'default-token' },
40
- serverValues: { 'https://prod.example.com': { token: 'prod-token' } },
41
- };
42
- const [result] = applyEnvironments([{ source: '{{token}}' }], envVariables, {
43
- server: 'https://staging.example.com',
44
- });
45
- expect(result.source).toBe('default-token');
46
- });
47
- it('leaves entries without a string source untouched (reused across sample shapes)', () => {
48
- const samples = [
49
- { source: '{{host}}' },
50
- { label: 'no source' },
51
- { source: 42 },
52
- ];
53
- const result = applyEnvironments(samples, { values: { host: 'api.example.com' } });
54
- expect(result[0].source).toBe('api.example.com');
55
- expect(result[1]).toEqual({ label: 'no source' });
56
- expect(result[2]).toEqual({ source: 42 });
57
- });
58
- it('does not mutate the original samples', () => {
59
- const samples = [{ source: '{{host}}' }];
60
- applyEnvironments(samples, { values: { host: 'api.example.com' } });
61
- expect(samples[0].source).toBe('{{host}}');
62
- });
63
- });
64
- //# sourceMappingURL=apply-environments.test.js.map
@@ -1,70 +0,0 @@
1
- import { vi } from 'vitest';
2
- vi.mock('../generator.js', () => ({
3
- getCodeSample: vi.fn(),
4
- }));
5
- import { buildCodeSamples } from '../build-code-samples.js';
6
- import { getCodeSample } from '../generator.js';
7
- const mockGetCodeSample = vi.mocked(getCodeSample);
8
- const translate = ((key) => key);
9
- const definition = {};
10
- function buildOptions(languages) {
11
- return {
12
- codeSamples: { languages, skipOptionalParameters: false, withOAuth2Call: false },
13
- generatedSamplesMaxDepth: 1,
14
- };
15
- }
16
- function buildOperation(partial) {
17
- return { definitionSamples: [], isWebhook: false, ...partial };
18
- }
19
- describe('buildCodeSamples', () => {
20
- beforeEach(() => {
21
- mockGetCodeSample.mockReset();
22
- mockGetCodeSample.mockImplementation((params) => `generated:${params.lang}`);
23
- });
24
- it('generates a sample for each configured language, in order', () => {
25
- const result = buildCodeSamples(buildOperation({}), buildOptions([{ lang: 'curl' }, { lang: 'Python' }]), definition, {}, translate);
26
- expect(result).toEqual([
27
- { lang: 'curl', label: undefined, source: 'generated:curl' },
28
- { lang: 'Python', label: undefined, source: 'generated:Python' },
29
- ]);
30
- });
31
- it('prefers definition (x-codeSamples) samples over generating the same language', () => {
32
- const result = buildCodeSamples(buildOperation({ definitionSamples: [{ lang: 'curl', source: 'curl from definition' }] }), buildOptions([{ lang: 'curl' }, { lang: 'Python' }]), definition, {}, translate);
33
- expect(result).toEqual([
34
- { lang: 'curl', source: 'curl from definition' },
35
- { lang: 'Python', label: undefined, source: 'generated:Python' },
36
- ]);
37
- expect(mockGetCodeSample).toHaveBeenCalledTimes(1);
38
- expect(mockGetCodeSample).toHaveBeenCalledWith(expect.objectContaining({ lang: 'Python' }));
39
- });
40
- it('skips the Payload language when generating samples', () => {
41
- const result = buildCodeSamples(buildOperation({}), buildOptions([{ lang: 'curl' }, { lang: 'Payload' }]), definition, {}, translate);
42
- expect(result.map((sample) => sample.lang)).toEqual(['curl']);
43
- });
44
- it('does not generate samples for webhooks', () => {
45
- const result = buildCodeSamples(buildOperation({
46
- isWebhook: true,
47
- definitionSamples: [{ lang: 'curl', source: 'curl from definition' }],
48
- }), buildOptions([{ lang: 'curl' }, { lang: 'Python' }]), definition, {}, translate);
49
- expect(result).toEqual([{ lang: 'curl', source: 'curl from definition' }]);
50
- expect(mockGetCodeSample).not.toHaveBeenCalled();
51
- });
52
- it('sorts the combined samples by the configured language order', () => {
53
- const result = buildCodeSamples(buildOperation({ definitionSamples: [{ lang: 'Python', source: 'py from definition' }] }), buildOptions([{ lang: 'curl' }, { lang: 'Python' }, { lang: 'Go' }]), definition, {}, translate);
54
- expect(result.map((sample) => sample.lang)).toEqual(['curl', 'Python', 'Go']);
55
- });
56
- it('filters out samples with an empty source', () => {
57
- mockGetCodeSample.mockReturnValue('');
58
- const result = buildCodeSamples(buildOperation({ definitionSamples: [{ lang: 'curl', source: 'curl from definition' }] }), buildOptions([{ lang: 'curl' }, { lang: 'Python' }]), definition, {}, translate);
59
- // curl comes from the definition (non-empty); the generated Python sample is empty -> dropped
60
- expect(result.map((sample) => sample.lang)).toEqual(['curl']);
61
- });
62
- it('applies environment variables to definition samples (reuses applyEnvironments)', () => {
63
- const result = buildCodeSamples(buildOperation({
64
- definitionSamples: [{ lang: 'curl', source: 'curl https://{{host}}/v1' }],
65
- envVariables: { values: { host: 'api.example.com' } },
66
- }), buildOptions([{ lang: 'curl' }]), definition, { environment: 'prod', environments: { prod: {} } }, translate);
67
- expect(result[0].source).toBe('curl https://api.example.com/v1');
68
- });
69
- });
70
- //# sourceMappingURL=build-code-samples.test.js.map