@scalar/workspace-store 0.41.2 → 0.43.0

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 (261) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/client.d.ts.map +1 -1
  3. package/dist/client.js +5 -1
  4. package/dist/events/definitions/operation.d.ts +6 -1
  5. package/dist/events/definitions/operation.d.ts.map +1 -1
  6. package/dist/events/definitions/server.d.ts +5 -1
  7. package/dist/events/definitions/server.d.ts.map +1 -1
  8. package/dist/events/definitions/ui.d.ts +5 -3
  9. package/dist/events/definitions/ui.d.ts.map +1 -1
  10. package/dist/helpers/get-resolved-ref-deep.d.ts +27 -0
  11. package/dist/helpers/get-resolved-ref-deep.d.ts.map +1 -0
  12. package/dist/helpers/get-resolved-ref-deep.js +49 -0
  13. package/dist/mutators/operation/operation.d.ts +1 -1
  14. package/dist/mutators/operation/operation.d.ts.map +1 -1
  15. package/dist/mutators/operation/operation.js +4 -4
  16. package/dist/mutators/server.d.ts +1 -1
  17. package/dist/mutators/server.d.ts.map +1 -1
  18. package/dist/mutators/server.js +5 -2
  19. package/dist/navigation/helpers/traverse-description.d.ts.map +1 -1
  20. package/dist/navigation/helpers/traverse-description.js +19 -21
  21. package/dist/navigation/helpers/utils.js +2 -2
  22. package/dist/request-example/builder/body/build-request-body.d.ts +42 -0
  23. package/dist/request-example/builder/body/build-request-body.d.ts.map +1 -0
  24. package/dist/request-example/builder/body/build-request-body.js +134 -0
  25. package/dist/request-example/builder/body/get-request-body-example.d.ts +6 -0
  26. package/dist/request-example/builder/body/get-request-body-example.d.ts.map +1 -0
  27. package/dist/request-example/builder/body/get-request-body-example.js +31 -0
  28. package/dist/request-example/builder/body/get-selected-body-content-type.d.ts +10 -0
  29. package/dist/request-example/builder/body/get-selected-body-content-type.d.ts.map +1 -0
  30. package/dist/request-example/builder/body/get-selected-body-content-type.js +10 -0
  31. package/dist/request-example/builder/build-request.d.ts +9 -0
  32. package/dist/request-example/builder/build-request.d.ts.map +1 -0
  33. package/dist/request-example/builder/build-request.js +135 -0
  34. package/dist/request-example/builder/header/build-request-cookie-header.d.ts +25 -0
  35. package/dist/request-example/builder/header/build-request-cookie-header.d.ts.map +1 -0
  36. package/dist/request-example/builder/header/build-request-cookie-header.js +39 -0
  37. package/dist/request-example/builder/header/build-request-parameters.d.ts +24 -0
  38. package/dist/request-example/builder/header/build-request-parameters.d.ts.map +1 -0
  39. package/dist/request-example/builder/header/build-request-parameters.js +215 -0
  40. package/dist/request-example/builder/header/de-serialize-parameter.d.ts +4 -0
  41. package/dist/request-example/builder/header/de-serialize-parameter.d.ts.map +1 -0
  42. package/dist/request-example/builder/header/de-serialize-parameter.js +49 -0
  43. package/dist/request-example/builder/header/filter-global-cookies.d.ts +14 -0
  44. package/dist/request-example/builder/header/filter-global-cookies.d.ts.map +1 -0
  45. package/dist/request-example/builder/header/filter-global-cookies.js +26 -0
  46. package/dist/request-example/builder/header/is-param-disabled.d.ts +13 -0
  47. package/dist/request-example/builder/header/is-param-disabled.d.ts.map +1 -0
  48. package/dist/request-example/builder/header/is-param-disabled.js +19 -0
  49. package/dist/request-example/builder/header/matches-domain.d.ts +9 -0
  50. package/dist/request-example/builder/header/matches-domain.d.ts.map +1 -0
  51. package/dist/request-example/builder/header/matches-domain.js +27 -0
  52. package/dist/request-example/builder/header/serialize-parameter.d.ts +96 -0
  53. package/dist/request-example/builder/header/serialize-parameter.d.ts.map +1 -0
  54. package/dist/request-example/builder/header/serialize-parameter.js +222 -0
  55. package/dist/request-example/builder/helpers/apply-allow-reserved-to-url.d.ts +6 -0
  56. package/dist/request-example/builder/helpers/apply-allow-reserved-to-url.d.ts.map +1 -0
  57. package/dist/request-example/builder/helpers/apply-allow-reserved-to-url.js +69 -0
  58. package/dist/request-example/builder/helpers/get-environment-variables.d.ts +9 -0
  59. package/dist/request-example/builder/helpers/get-environment-variables.d.ts.map +1 -0
  60. package/dist/request-example/builder/helpers/get-environment-variables.js +12 -0
  61. package/dist/request-example/builder/helpers/get-example-from-schema.d.ts +40 -0
  62. package/dist/request-example/builder/helpers/get-example-from-schema.d.ts.map +1 -0
  63. package/dist/request-example/builder/helpers/get-example-from-schema.js +568 -0
  64. package/dist/request-example/builder/helpers/get-example.d.ts +10 -0
  65. package/dist/request-example/builder/helpers/get-example.d.ts.map +1 -0
  66. package/dist/request-example/builder/helpers/get-example.js +66 -0
  67. package/dist/request-example/builder/helpers/get-resolved-url.d.ts +20 -0
  68. package/dist/request-example/builder/helpers/get-resolved-url.d.ts.map +1 -0
  69. package/dist/request-example/builder/helpers/get-resolved-url.js +19 -0
  70. package/dist/request-example/builder/helpers/get-server-variables.d.ts +10 -0
  71. package/dist/request-example/builder/helpers/get-server-variables.d.ts.map +1 -0
  72. package/dist/request-example/builder/helpers/get-server-variables.js +19 -0
  73. package/dist/request-example/builder/index.d.ts +15 -0
  74. package/dist/request-example/builder/index.d.ts.map +1 -0
  75. package/dist/request-example/builder/index.js +13 -0
  76. package/dist/request-example/builder/request-factory.d.ts +60 -0
  77. package/dist/request-example/builder/request-factory.d.ts.map +1 -0
  78. package/dist/request-example/builder/request-factory.js +78 -0
  79. package/dist/request-example/builder/security/build-request-security.d.ts +24 -0
  80. package/dist/request-example/builder/security/build-request-security.d.ts.map +1 -0
  81. package/dist/request-example/builder/security/build-request-security.js +79 -0
  82. package/dist/request-example/builder/security/secret-types.d.ts +25 -0
  83. package/dist/request-example/builder/security/secret-types.d.ts.map +1 -0
  84. package/dist/request-example/builder/security/secret-types.js +1 -0
  85. package/dist/request-example/context/environment.d.ts +21 -0
  86. package/dist/request-example/context/environment.d.ts.map +1 -0
  87. package/dist/request-example/context/environment.js +49 -0
  88. package/dist/request-example/context/get-request-example-context.d.ts +57 -0
  89. package/dist/request-example/context/get-request-example-context.d.ts.map +1 -0
  90. package/dist/request-example/context/get-request-example-context.js +115 -0
  91. package/dist/request-example/context/headers.d.ts +33 -0
  92. package/dist/request-example/context/headers.d.ts.map +1 -0
  93. package/dist/request-example/context/headers.js +54 -0
  94. package/dist/request-example/context/helpers/combine-params.d.ts +4 -0
  95. package/dist/request-example/context/helpers/combine-params.d.ts.map +1 -0
  96. package/dist/request-example/context/helpers/combine-params.js +21 -0
  97. package/dist/request-example/context/index.d.ts +12 -0
  98. package/dist/request-example/context/index.d.ts.map +1 -0
  99. package/dist/request-example/context/index.js +10 -0
  100. package/dist/request-example/context/proxy.d.ts +18 -0
  101. package/dist/request-example/context/proxy.d.ts.map +1 -0
  102. package/dist/request-example/context/proxy.js +26 -0
  103. package/dist/request-example/context/security/extract-security-scheme-secrets.d.ts +10 -0
  104. package/dist/request-example/context/security/extract-security-scheme-secrets.d.ts.map +1 -0
  105. package/dist/request-example/context/security/extract-security-scheme-secrets.js +167 -0
  106. package/dist/request-example/context/security/get-security-requirements.d.ts +12 -0
  107. package/dist/request-example/context/security/get-security-requirements.d.ts.map +1 -0
  108. package/dist/request-example/context/security/get-security-requirements.js +16 -0
  109. package/dist/request-example/context/security/get-security-schemes.d.ts +9 -0
  110. package/dist/request-example/context/security/get-security-schemes.d.ts.map +1 -0
  111. package/dist/request-example/context/security/get-security-schemes.js +13 -0
  112. package/dist/request-example/context/security/get-selected-security.d.ts +15 -0
  113. package/dist/request-example/context/security/get-selected-security.d.ts.map +1 -0
  114. package/dist/request-example/context/security/get-selected-security.js +49 -0
  115. package/dist/request-example/context/security/is-auth-optional.d.ts +4 -0
  116. package/dist/request-example/context/security/is-auth-optional.d.ts.map +1 -0
  117. package/dist/request-example/context/security/is-auth-optional.js +6 -0
  118. package/dist/request-example/context/security/merge-security.d.ts +9 -0
  119. package/dist/request-example/context/security/merge-security.d.ts.map +1 -0
  120. package/dist/request-example/context/security/merge-security.js +29 -0
  121. package/dist/request-example/context/servers.d.ts +26 -0
  122. package/dist/request-example/context/servers.d.ts.map +1 -0
  123. package/dist/request-example/context/servers.js +89 -0
  124. package/dist/request-example/index.d.ts +5 -0
  125. package/dist/request-example/index.d.ts.map +1 -0
  126. package/dist/request-example/index.js +2 -0
  127. package/dist/request-example/types.d.ts +14 -0
  128. package/dist/request-example/types.d.ts.map +1 -0
  129. package/dist/request-example/types.js +1 -0
  130. package/dist/schemas/extensions/document/x-internal.d.ts +3 -0
  131. package/dist/schemas/extensions/document/x-internal.d.ts.map +1 -1
  132. package/dist/schemas/extensions/document/x-internal.js +7 -0
  133. package/dist/schemas/extensions/document/x-scalar-environments.d.ts +31 -0
  134. package/dist/schemas/extensions/document/x-scalar-environments.d.ts.map +1 -1
  135. package/dist/schemas/extensions/document/x-scalar-environments.js +25 -0
  136. package/dist/schemas/extensions/document/x-scalar-icon.d.ts +3 -0
  137. package/dist/schemas/extensions/document/x-scalar-icon.d.ts.map +1 -1
  138. package/dist/schemas/extensions/document/x-scalar-icon.js +7 -0
  139. package/dist/schemas/extensions/document/x-scalar-ignore.d.ts +4 -1
  140. package/dist/schemas/extensions/document/x-scalar-ignore.d.ts.map +1 -1
  141. package/dist/schemas/extensions/document/x-scalar-ignore.js +7 -0
  142. package/dist/schemas/extensions/document/x-scalar-is-dirty.d.ts +3 -0
  143. package/dist/schemas/extensions/document/x-scalar-is-dirty.d.ts.map +1 -1
  144. package/dist/schemas/extensions/document/x-scalar-is-dirty.js +9 -0
  145. package/dist/schemas/extensions/document/x-scalar-original-document-hash.d.ts +3 -0
  146. package/dist/schemas/extensions/document/x-scalar-original-document-hash.d.ts.map +1 -1
  147. package/dist/schemas/extensions/document/x-scalar-original-document-hash.js +7 -0
  148. package/dist/schemas/extensions/document/x-scalar-registry-meta.d.ts +6 -0
  149. package/dist/schemas/extensions/document/x-scalar-registry-meta.d.ts.map +1 -1
  150. package/dist/schemas/extensions/document/x-scalar-registry-meta.js +25 -10
  151. package/dist/schemas/extensions/document/x-scalar-sdk-installation.d.ts +7 -0
  152. package/dist/schemas/extensions/document/x-scalar-sdk-installation.d.ts.map +1 -1
  153. package/dist/schemas/extensions/document/x-scalar-sdk-installation.js +23 -5
  154. package/dist/schemas/extensions/document/x-scalar-watch-mode.d.ts +3 -0
  155. package/dist/schemas/extensions/document/x-scalar-watch-mode.d.ts.map +1 -1
  156. package/dist/schemas/extensions/document/x-scalar-watch-mode.js +7 -0
  157. package/dist/schemas/extensions/document/x-tags.d.ts +4 -1
  158. package/dist/schemas/extensions/document/x-tags.d.ts.map +1 -1
  159. package/dist/schemas/extensions/document/x-tags.js +8 -1
  160. package/dist/schemas/extensions/example/x-disabled.d.ts +7 -1
  161. package/dist/schemas/extensions/example/x-disabled.d.ts.map +1 -1
  162. package/dist/schemas/extensions/example/x-disabled.js +8 -1
  163. package/dist/schemas/extensions/general/x-scalar-active-environment.d.ts +3 -0
  164. package/dist/schemas/extensions/general/x-scalar-active-environment.d.ts.map +1 -1
  165. package/dist/schemas/extensions/general/x-scalar-active-environment.js +7 -0
  166. package/dist/schemas/extensions/general/x-scalar-cookies.d.ts +16 -0
  167. package/dist/schemas/extensions/general/x-scalar-cookies.d.ts.map +1 -1
  168. package/dist/schemas/extensions/general/x-scalar-cookies.js +19 -0
  169. package/dist/schemas/extensions/general/x-scalar-order.d.ts +3 -0
  170. package/dist/schemas/extensions/general/x-scalar-order.d.ts.map +1 -1
  171. package/dist/schemas/extensions/general/x-scalar-order.js +7 -0
  172. package/dist/schemas/extensions/operation/index.d.ts +2 -1
  173. package/dist/schemas/extensions/operation/index.d.ts.map +1 -1
  174. package/dist/schemas/extensions/operation/index.js +1 -0
  175. package/dist/schemas/extensions/operation/x-badge.d.ts +12 -0
  176. package/dist/schemas/extensions/operation/x-badge.d.ts.map +1 -1
  177. package/dist/schemas/extensions/operation/x-badge.js +23 -0
  178. package/dist/schemas/extensions/operation/x-code-samples.d.ts +22 -0
  179. package/dist/schemas/extensions/operation/x-code-samples.d.ts.map +1 -1
  180. package/dist/schemas/extensions/operation/x-code-samples.js +17 -0
  181. package/dist/schemas/extensions/operation/x-draft-examples.d.ts +3 -0
  182. package/dist/schemas/extensions/operation/x-draft-examples.d.ts.map +1 -1
  183. package/dist/schemas/extensions/operation/x-draft-examples.js +7 -0
  184. package/dist/schemas/extensions/operation/x-post-response.d.ts +3 -0
  185. package/dist/schemas/extensions/operation/x-post-response.d.ts.map +1 -1
  186. package/dist/schemas/extensions/operation/x-post-response.js +9 -0
  187. package/dist/schemas/extensions/operation/x-scalar-disable-parameters.d.ts +9 -0
  188. package/dist/schemas/extensions/operation/x-scalar-disable-parameters.d.ts.map +1 -1
  189. package/dist/schemas/extensions/operation/x-scalar-disable-parameters.js +17 -0
  190. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.d.ts +3 -0
  191. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.d.ts.map +1 -1
  192. package/dist/schemas/extensions/operation/x-scalar-selected-content-type.js +9 -0
  193. package/dist/schemas/extensions/operation/x-scalar-stability.d.ts +3 -0
  194. package/dist/schemas/extensions/operation/x-scalar-stability.d.ts.map +1 -1
  195. package/dist/schemas/extensions/operation/x-scalar-stability.js +9 -0
  196. package/dist/schemas/extensions/parameter/x-global.d.ts +7 -1
  197. package/dist/schemas/extensions/parameter/x-global.d.ts.map +1 -1
  198. package/dist/schemas/extensions/parameter/x-global.js +8 -1
  199. package/dist/schemas/extensions/schema/x-additional-properties-name.d.ts +3 -0
  200. package/dist/schemas/extensions/schema/x-additional-properties-name.d.ts.map +1 -1
  201. package/dist/schemas/extensions/schema/x-additional-properties-name.js +7 -0
  202. package/dist/schemas/extensions/schema/x-enum-descriptions.d.ts +4 -0
  203. package/dist/schemas/extensions/schema/x-enum-descriptions.d.ts.map +1 -1
  204. package/dist/schemas/extensions/schema/x-enum-descriptions.js +9 -0
  205. package/dist/schemas/extensions/schema/x-enum-varnames.d.ts +4 -0
  206. package/dist/schemas/extensions/schema/x-enum-varnames.d.ts.map +1 -1
  207. package/dist/schemas/extensions/schema/x-enum-varnames.js +8 -0
  208. package/dist/schemas/extensions/schema/x-examples.d.ts +3 -0
  209. package/dist/schemas/extensions/schema/x-examples.d.ts.map +1 -1
  210. package/dist/schemas/extensions/schema/x-examples.js +7 -0
  211. package/dist/schemas/extensions/schema/x-variable.d.ts +3 -0
  212. package/dist/schemas/extensions/schema/x-variable.d.ts.map +1 -1
  213. package/dist/schemas/extensions/schema/x-variable.js +7 -0
  214. package/dist/schemas/extensions/security/x-default-scopes.d.ts +3 -0
  215. package/dist/schemas/extensions/security/x-default-scopes.d.ts.map +1 -1
  216. package/dist/schemas/extensions/security/x-default-scopes.js +7 -0
  217. package/dist/schemas/extensions/security/x-scalar-credentials-location.d.ts +3 -0
  218. package/dist/schemas/extensions/security/x-scalar-credentials-location.d.ts.map +1 -1
  219. package/dist/schemas/extensions/security/x-scalar-credentials-location.js +7 -0
  220. package/dist/schemas/extensions/security/x-scalar-security-body.d.ts +3 -0
  221. package/dist/schemas/extensions/security/x-scalar-security-body.d.ts.map +1 -1
  222. package/dist/schemas/extensions/security/x-scalar-security-body.js +7 -0
  223. package/dist/schemas/extensions/security/x-scalar-security-query.d.ts +3 -0
  224. package/dist/schemas/extensions/security/x-scalar-security-query.d.ts.map +1 -1
  225. package/dist/schemas/extensions/security/x-scalar-security-query.js +7 -0
  226. package/dist/schemas/extensions/security/x-scalar-security-secrets.d.ts +25 -0
  227. package/dist/schemas/extensions/security/x-scalar-security-secrets.d.ts.map +1 -1
  228. package/dist/schemas/extensions/security/x-scalar-security-secrets.js +50 -0
  229. package/dist/schemas/extensions/security/x-tokenName.d.ts +3 -0
  230. package/dist/schemas/extensions/security/x-tokenName.d.ts.map +1 -1
  231. package/dist/schemas/extensions/security/x-tokenName.js +7 -0
  232. package/dist/schemas/extensions/security/x-use-pkce.d.ts +3 -0
  233. package/dist/schemas/extensions/security/x-use-pkce.d.ts.map +1 -1
  234. package/dist/schemas/extensions/security/x-use-pkce.js +9 -0
  235. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts +3 -0
  236. package/dist/schemas/extensions/server/x-scalar-selected-server.d.ts.map +1 -1
  237. package/dist/schemas/extensions/server/x-scalar-selected-server.js +7 -0
  238. package/dist/schemas/extensions/tag/x-display-name.d.ts +3 -0
  239. package/dist/schemas/extensions/tag/x-display-name.d.ts.map +1 -1
  240. package/dist/schemas/extensions/tag/x-display-name.js +7 -0
  241. package/dist/schemas/extensions/tag/x-tag-groups.d.ts +14 -0
  242. package/dist/schemas/extensions/tag/x-tag-groups.d.ts.map +1 -1
  243. package/dist/schemas/extensions/tag/x-tag-groups.js +22 -1
  244. package/dist/schemas/extensions/workspace/x-scalar-active-proxy.d.ts +3 -0
  245. package/dist/schemas/extensions/workspace/x-scalar-active-proxy.d.ts.map +1 -1
  246. package/dist/schemas/extensions/workspace/x-scalar-active-proxy.js +7 -0
  247. package/dist/schemas/extensions/workspace/x-scalar-tabs.d.ts +13 -0
  248. package/dist/schemas/extensions/workspace/x-scalar-tabs.d.ts.map +1 -1
  249. package/dist/schemas/extensions/workspace/x-scalar-tabs.js +20 -0
  250. package/dist/schemas/v3.1/openapi/index.d.ts +112 -0
  251. package/dist/schemas/v3.1/openapi/index.d.ts.map +1 -0
  252. package/dist/schemas/v3.1/openapi/index.js +645 -0
  253. package/dist/schemas/v3.1/openapi/reference.d.ts +4 -0
  254. package/dist/schemas/v3.1/openapi/reference.d.ts.map +1 -0
  255. package/dist/schemas/v3.1/openapi/reference.js +29 -0
  256. package/dist/schemas/v3.1/strict/example.js +2 -2
  257. package/dist/schemas/v3.1/strict/parameter.js +2 -2
  258. package/dist/schemas/v3.1/strict/schema.d.ts +1 -1
  259. package/dist/schemas/v3.1/strict/schema.d.ts.map +1 -1
  260. package/dist/schemas/v3.1/strict/schema.js +2 -2
  261. package/package.json +16 -9
@@ -0,0 +1,568 @@
1
+ import { isDefined } from '@scalar/helpers/array/is-defined';
2
+ import { unpackProxyObject } from '../../../helpers/unpack-proxy.js';
3
+ import { resolve } from '../../../resolve.js';
4
+ /** Maximum recursion depth to prevent infinite loops in circular references */
5
+ const MAX_LEVELS_DEEP = 10;
6
+ /** Default name used for additional properties when no custom name is provided */
7
+ const DEFAULT_ADDITIONAL_PROPERTIES_NAME = 'additionalProperty';
8
+ /**
9
+ * Pre-computed date/time values to avoid expensive Date operations on every call.
10
+ * These are calculated once at module load time for better performance.
11
+ */
12
+ const currentISOString = new Date().toISOString();
13
+ const currentDateString = currentISOString.split('T')[0];
14
+ const currentTimeString = currentISOString.split('T')[1].split('.')[0];
15
+ /**
16
+ * Mapping of OpenAPI string formats to example values.
17
+ * Used to generate realistic examples for different string formats.
18
+ */
19
+ const genericExampleValues = {
20
+ 'date-time': currentISOString,
21
+ 'date': currentDateString,
22
+ 'email': 'hello@example.com',
23
+ 'hostname': 'example.com',
24
+ // https://tools.ietf.org/html/rfc6531#section-3.3
25
+ 'idn-email': 'jane.doe@example.com',
26
+ // https://tools.ietf.org/html/rfc5890#section-2.3.2.3
27
+ 'idn-hostname': 'example.com',
28
+ 'ipv4': '127.0.0.1',
29
+ 'ipv6': '51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998',
30
+ 'iri-reference': '/entitiy/1',
31
+ // https://tools.ietf.org/html/rfc3987
32
+ 'iri': 'https://example.com/entity/123',
33
+ 'json-pointer': '/nested/objects',
34
+ 'password': 'super-secret',
35
+ 'regex': '/[a-z]/',
36
+ // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01
37
+ 'relative-json-pointer': '1/nested/objects',
38
+ // full-time in https://tools.ietf.org/html/rfc3339#section-5.6
39
+ 'time': currentTimeString,
40
+ // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1
41
+ 'uri-reference': '../folder',
42
+ 'uri-template': 'https://example.com/{id}',
43
+ 'uri': 'https://example.com',
44
+ 'uuid': '123e4567-e89b-12d3-a456-426614174000',
45
+ 'object-id': '6592008029c8c3e4dc76256c',
46
+ };
47
+ /**
48
+ * Extract enum values from the propertyNames keyword of an object schema.
49
+ * JSON Schema's propertyNames constrains which keys are valid in a map/dict.
50
+ */
51
+ const getPropertyNamesEnumValues = (schema) => {
52
+ if (!('propertyNames' in schema) || !schema.propertyNames) {
53
+ return undefined;
54
+ }
55
+ const resolved = resolve.schema(schema.propertyNames);
56
+ if (resolved && 'enum' in resolved && Array.isArray(resolved.enum) && resolved.enum.length > 0) {
57
+ return resolved.enum;
58
+ }
59
+ return undefined;
60
+ };
61
+ /**
62
+ * Generate example values for string types based on their format.
63
+ * Special handling for binary format which returns a File object.
64
+ */
65
+ const guessFromFormat = (schema, makeUpRandomData = false, fallback = '') => {
66
+ // Handle binary format specially - return a File object
67
+ if ('type' in schema && schema.type === 'string' && 'format' in schema && schema.format === 'binary') {
68
+ return '@filename';
69
+ }
70
+ // Return format-specific example if we have one and are making up data
71
+ if (makeUpRandomData && 'format' in schema && schema.format) {
72
+ return genericExampleValues[schema.format] ?? fallback;
73
+ }
74
+ return fallback;
75
+ };
76
+ /**
77
+ * WeakMap cache for memoizing resolved example results.
78
+ * Uses the resolved schema object as the key for efficient lookups.
79
+ */
80
+ const resultCache = new WeakMap();
81
+ /** Cache required property names per parent schema for O(1) membership checks */
82
+ const requiredNamesCache = new WeakMap();
83
+ /** Normalize schema identity for cache and cycle tracking */
84
+ const getSchemaCacheTarget = (schema) => unpackProxyObject(schema, { depth: 1 });
85
+ /**
86
+ * Retrieves the set of required property names from a schema.
87
+ * Caches the result in a WeakMap for efficient lookups.
88
+ */
89
+ const getRequiredNames = (parentSchema) => {
90
+ if (!parentSchema) {
91
+ return undefined;
92
+ }
93
+ const cached = requiredNamesCache.get(parentSchema);
94
+ if (cached) {
95
+ return cached;
96
+ }
97
+ if ('required' in parentSchema) {
98
+ const required = parentSchema.required;
99
+ if (Array.isArray(required) && required.length > 0) {
100
+ const set = new Set(required);
101
+ requiredNamesCache.set(parentSchema, set);
102
+ return set;
103
+ }
104
+ }
105
+ return undefined;
106
+ };
107
+ /**
108
+ * Cache the result for a schema if it is an object type.
109
+ * Primitive values are not cached to avoid unnecessary WeakMap operations.
110
+ * Stores a map of cacheKey strings which is made up of the options object.
111
+ */
112
+ const cache = (schema, result, cacheKey) => {
113
+ if (typeof result !== 'object' || result === null) {
114
+ return result;
115
+ }
116
+ const rawSchema = getSchemaCacheTarget(schema);
117
+ const cacheMap = resultCache.get(rawSchema) ?? new Map();
118
+ if (cacheMap) {
119
+ cacheMap.set(cacheKey, result);
120
+ }
121
+ resultCache.set(rawSchema, cacheMap);
122
+ return result;
123
+ };
124
+ /**
125
+ * Check if a schema uses composition keywords (allOf, oneOf, anyOf).
126
+ * These require special handling for merging or selecting schemas.
127
+ */
128
+ const isComposed = (schema) => !!(schema.allOf || schema.oneOf || schema.anyOf);
129
+ /**
130
+ * Determine if a property should be omitted based on the options.
131
+ * Properties are omitted if they are not required and the option is enabled.
132
+ */
133
+ const shouldOmitProperty = (schema, parentSchema, propertyName, options) => {
134
+ // Early exits for schemas that should not be included (deprecated, readOnly, writeOnly)
135
+ if (schema.deprecated ||
136
+ (options?.mode === 'write' && schema.readOnly) ||
137
+ (options?.mode === 'read' && schema.writeOnly)) {
138
+ return true;
139
+ }
140
+ if (options?.omitEmptyAndOptionalProperties !== true) {
141
+ return false;
142
+ }
143
+ // Never omit container types (objects/arrays) or composed schemas
144
+ const isContainer = ('type' in schema && (schema.type === 'object' || schema.type === 'array')) || isComposed(schema);
145
+ if (isContainer) {
146
+ return false;
147
+ }
148
+ // Do not omit if explicit example-like values are present
149
+ if (('examples' in schema && Array.isArray(schema.examples) && schema.examples.length > 0) ||
150
+ ('example' in schema && schema.example !== undefined) ||
151
+ ('default' in schema && schema.default !== undefined) ||
152
+ ('const' in schema && schema.const !== undefined) ||
153
+ ('enum' in schema && Array.isArray(schema.enum) && schema.enum.length > 0)) {
154
+ return false;
155
+ }
156
+ // Check if the property is required
157
+ const name = propertyName ?? schema.title ?? '';
158
+ const requiredNames = getRequiredNames(parentSchema);
159
+ const isRequired = requiredNames ? requiredNames.has(name) : false;
160
+ return !isRequired;
161
+ };
162
+ /**
163
+ * Merge two example values with predictable semantics.
164
+ * Arrays are concatenated, objects are merged, otherwise the new value wins.
165
+ */
166
+ const mergeExamples = (baseValue, newValue) => {
167
+ if (Array.isArray(baseValue) && Array.isArray(newValue)) {
168
+ return [...baseValue, ...newValue];
169
+ }
170
+ if (baseValue && typeof baseValue === 'object' && newValue && typeof newValue === 'object') {
171
+ return { ...baseValue, ...newValue };
172
+ }
173
+ return newValue;
174
+ };
175
+ const getCompositionSelectionKey = (schemaPath, composition) => [...schemaPath, composition].join('.');
176
+ const getCompositionSelectionIndex = (schemaPath, composition, options, length) => {
177
+ const rawIndex = options?.compositionSelection?.[getCompositionSelectionKey(schemaPath, composition)];
178
+ if (typeof rawIndex !== 'number' || Number.isNaN(rawIndex)) {
179
+ return undefined;
180
+ }
181
+ return Math.max(0, Math.min(rawIndex, length - 1));
182
+ };
183
+ /**
184
+ * Build an example for an object schema, including properties, patternProperties,
185
+ * additionalProperties, and composition (allOf/oneOf/anyOf) merging.
186
+ */
187
+ const handleObjectSchema = (schema, options, level, seen, cacheKey, schemaPath) => {
188
+ const response = {};
189
+ if ('properties' in schema && schema.properties) {
190
+ const propertyNames = Object.keys(schema.properties);
191
+ const limit = propertyNames.length;
192
+ for (let i = 0; i < limit; i++) {
193
+ const propertyName = propertyNames[i];
194
+ const propertySchema = resolve.schema(schema.properties[propertyName]);
195
+ if (!propertySchema) {
196
+ continue;
197
+ }
198
+ const propertyXmlName = options?.xml && 'xml' in propertySchema ? propertySchema.xml?.name : undefined;
199
+ const value = getExampleFromSchema(propertySchema, options, {
200
+ level: level + 1,
201
+ parentSchema: schema,
202
+ name: propertyName,
203
+ schemaPath: [...schemaPath, propertyName],
204
+ seen,
205
+ });
206
+ if (typeof value !== 'undefined') {
207
+ response[propertyXmlName ?? propertyName] = value;
208
+ }
209
+ }
210
+ }
211
+ if ('patternProperties' in schema && schema.patternProperties) {
212
+ for (const pattern of Object.keys(schema.patternProperties)) {
213
+ const propertySchema = resolve.schema(schema.patternProperties[pattern]);
214
+ if (!propertySchema) {
215
+ continue;
216
+ }
217
+ response[pattern] = getExampleFromSchema(propertySchema, options, {
218
+ level: level + 1,
219
+ parentSchema: schema,
220
+ name: pattern,
221
+ schemaPath: [...schemaPath, pattern],
222
+ seen,
223
+ });
224
+ }
225
+ }
226
+ if ('additionalProperties' in schema && schema.additionalProperties) {
227
+ const additional = typeof schema.additionalProperties === 'boolean'
228
+ ? schema.additionalProperties
229
+ : resolve.schema(schema.additionalProperties);
230
+ const isAnyType = schema.additionalProperties === true ||
231
+ (typeof schema.additionalProperties === 'object' && Object.keys(schema.additionalProperties).length === 0);
232
+ // Check for explicit x-additionalPropertiesName first
233
+ const hasCustomName = typeof additional === 'object' &&
234
+ 'x-additionalPropertiesName' in additional &&
235
+ typeof additional['x-additionalPropertiesName'] === 'string' &&
236
+ additional['x-additionalPropertiesName'].trim().length > 0;
237
+ // Use propertyNames enum values as example keys when no custom name is set
238
+ const propertyNamesEnum = hasCustomName ? undefined : getPropertyNamesEnumValues(schema);
239
+ const additionalName = hasCustomName
240
+ ? additional['x-additionalPropertiesName'].trim()
241
+ : DEFAULT_ADDITIONAL_PROPERTIES_NAME;
242
+ const additionalValue = isAnyType
243
+ ? 'anything'
244
+ : typeof additional === 'object'
245
+ ? getExampleFromSchema(additional, options, {
246
+ level: level + 1,
247
+ schemaPath: [...schemaPath, additionalName],
248
+ seen,
249
+ })
250
+ : 'anything';
251
+ if (propertyNamesEnum && propertyNamesEnum.length > 0) {
252
+ // Use the first enum value as a realistic example key
253
+ response[String(propertyNamesEnum[0])] = additionalValue;
254
+ }
255
+ else {
256
+ response[additionalName] = additionalValue;
257
+ }
258
+ }
259
+ const compositionKeyword = schema.oneOf ? 'oneOf' : schema.anyOf ? 'anyOf' : undefined;
260
+ const oneOfAnyOf = compositionKeyword ? schema[compositionKeyword] : undefined;
261
+ if (compositionKeyword && oneOfAnyOf?.length) {
262
+ const index = getCompositionSelectionIndex(schemaPath, compositionKeyword, options, oneOfAnyOf.length) ?? 0;
263
+ const chosen = resolve.schema(oneOfAnyOf[index]);
264
+ if (chosen) {
265
+ Object.assign(response, getExampleFromSchema(chosen, options, {
266
+ level: level + 1,
267
+ schemaPath,
268
+ seen,
269
+ }));
270
+ }
271
+ }
272
+ // allOf
273
+ else if (Array.isArray(schema.allOf) && schema.allOf.length > 0) {
274
+ let merged = response;
275
+ for (const item of schema.allOf) {
276
+ const ex = getExampleFromSchema(resolve.schema(item), options, {
277
+ level: level + 1,
278
+ parentSchema: schema,
279
+ seen,
280
+ });
281
+ merged = mergeExamples(merged, ex);
282
+ }
283
+ if (merged && typeof merged === 'object') {
284
+ Object.assign(response, merged);
285
+ }
286
+ }
287
+ if (options?.xml && 'xml' in schema && schema.xml?.name && level === 0) {
288
+ const wrapped = {};
289
+ wrapped[schema.xml.name] = response;
290
+ return cache(schema, wrapped, cacheKey);
291
+ }
292
+ return cache(schema, response, cacheKey);
293
+ };
294
+ /** Build an example for an array schema, including items, allOf, oneOf/anyOf, and XML wrapping */
295
+ const handleArraySchema = (schema, options, level, seen, cacheKey, schemaPath) => {
296
+ const items = 'items' in schema ? resolve.schema(schema.items) : undefined;
297
+ const itemsSchemaPath = [...schemaPath, 'items'];
298
+ const itemsXmlTagName = items && typeof items === 'object' && 'xml' in items ? items.xml?.name : undefined;
299
+ const wrapItems = !!(options?.xml && 'xml' in schema && schema.xml?.wrapped && itemsXmlTagName);
300
+ if (schema.example !== undefined) {
301
+ return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example, cacheKey);
302
+ }
303
+ if (items && typeof items === 'object') {
304
+ if (Array.isArray(items.allOf) && items.allOf.length > 0) {
305
+ const allOf = items.allOf.filter(isDefined);
306
+ const first = resolve.schema(allOf[0]);
307
+ if (first && typeof first === 'object' && 'type' in first && first.type === 'object') {
308
+ const combined = { type: 'object', allOf };
309
+ const merged = getExampleFromSchema(combined, options, {
310
+ level: level + 1,
311
+ parentSchema: schema,
312
+ schemaPath: itemsSchemaPath,
313
+ seen,
314
+ });
315
+ return cache(schema, wrapItems ? [{ [itemsXmlTagName]: merged }] : [merged], cacheKey);
316
+ }
317
+ const examples = allOf
318
+ .map((s) => getExampleFromSchema(resolve.schema(s), options, {
319
+ level: level + 1,
320
+ parentSchema: schema,
321
+ schemaPath: itemsSchemaPath,
322
+ seen,
323
+ }))
324
+ .filter(isDefined);
325
+ return cache(schema, wrapItems ? examples.map((e) => ({ [itemsXmlTagName]: e })) : examples, cacheKey);
326
+ }
327
+ const compositionKeyword = items.oneOf ? 'oneOf' : items.anyOf ? 'anyOf' : undefined;
328
+ const union = compositionKeyword ? items[compositionKeyword] : undefined;
329
+ if (compositionKeyword && union && union.length > 0) {
330
+ const selectedIndex = getCompositionSelectionIndex(itemsSchemaPath, compositionKeyword, options, union.length) ?? 0;
331
+ const selected = union[selectedIndex];
332
+ const ex = getExampleFromSchema(resolve.schema(selected), options, {
333
+ level: level + 1,
334
+ parentSchema: schema,
335
+ schemaPath: itemsSchemaPath,
336
+ seen,
337
+ });
338
+ return cache(schema, wrapItems ? [{ [itemsXmlTagName]: ex }] : [ex], cacheKey);
339
+ }
340
+ }
341
+ const isObject = items && typeof items === 'object' && (('type' in items && items.type === 'object') || 'properties' in items);
342
+ const isArray = items && typeof items === 'object' && (('type' in items && items.type === 'array') || 'items' in items);
343
+ if (items && typeof items === 'object' && (('type' in items && items.type) || isObject || isArray)) {
344
+ const ex = getExampleFromSchema(items, options, {
345
+ level: level + 1,
346
+ schemaPath: itemsSchemaPath,
347
+ seen,
348
+ });
349
+ return cache(schema, wrapItems ? [{ [itemsXmlTagName]: ex }] : [ex], cacheKey);
350
+ }
351
+ return cache(schema, [], cacheKey);
352
+ };
353
+ /** Return primitive example value for single-type schemas, or undefined if not primitive */
354
+ const getPrimitiveValue = (schema, makeUpRandomData, emptyString) => {
355
+ if ('type' in schema && schema.type && !Array.isArray(schema.type)) {
356
+ switch (schema.type) {
357
+ case 'string':
358
+ return guessFromFormat(schema, makeUpRandomData, emptyString ?? '');
359
+ case 'boolean':
360
+ return true;
361
+ case 'integer':
362
+ return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1;
363
+ case 'number':
364
+ return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1;
365
+ case 'array':
366
+ return [];
367
+ default:
368
+ return undefined;
369
+ }
370
+ }
371
+ return undefined;
372
+ };
373
+ /** Return primitive example value for union-type schemas (type: string[]) */
374
+ const getUnionPrimitiveValue = (schema, makeUpRandomData, emptyString) => {
375
+ if ('type' in schema && Array.isArray(schema.type)) {
376
+ if (schema.type.includes('null')) {
377
+ return null;
378
+ }
379
+ const first = schema.type[0];
380
+ if (first) {
381
+ switch (first) {
382
+ case 'string':
383
+ return guessFromFormat(schema, makeUpRandomData, emptyString ?? '');
384
+ case 'boolean':
385
+ return true;
386
+ case 'integer':
387
+ return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1;
388
+ case 'number':
389
+ return 'minimum' in schema && typeof schema.minimum === 'number' ? schema.minimum : 1;
390
+ case 'null':
391
+ return null;
392
+ default:
393
+ return undefined;
394
+ }
395
+ }
396
+ }
397
+ return undefined;
398
+ };
399
+ /** Create stable cache key from the options object */
400
+ const createOptionsCacheKey = (options) => JSON.stringify({
401
+ emptyString: options?.emptyString,
402
+ xml: options?.xml,
403
+ mode: options?.mode,
404
+ variables: options?.variables,
405
+ omitEmptyAndOptionalProperties: options?.omitEmptyAndOptionalProperties,
406
+ compositionSelection: options?.compositionSelection
407
+ ? Object.entries(options.compositionSelection).sort(([a], [b]) => a.localeCompare(b))
408
+ : undefined,
409
+ });
410
+ /**
411
+ * Generate an example value from a given OpenAPI SchemaObject.
412
+ *
413
+ * This function recursively processes OpenAPI schemas to create realistic example data.
414
+ * It handles all OpenAPI schema types including primitives, objects, arrays, and
415
+ * composition schemas (allOf, oneOf, anyOf).
416
+ * Uses a tonne of caching for maximum performance.
417
+ *
418
+ * @param schema - The OpenAPI SchemaObject to generate an example from.
419
+ * @param options - Options to customize example generation.
420
+ * @param level - The current recursion depth.
421
+ * @param parentSchema - The parent schema, if any.
422
+ * @param name - The name of the property being processed.
423
+ * @returns An example value for the given schema.
424
+ */
425
+ export const getExampleFromSchema = (schema, options, { level = 0, parentSchema, name, seen = new WeakSet(), schemaPath = [], } = {}) => {
426
+ // Resolve any $ref references to get the actual schema
427
+ const _schema = resolve.schema(schema);
428
+ if (!isDefined(_schema)) {
429
+ return undefined;
430
+ }
431
+ // Unpack from all proxies to get the raw schema object for cycle detection
432
+ const targetValue = getSchemaCacheTarget(_schema);
433
+ if (seen.has(targetValue)) {
434
+ return undefined;
435
+ }
436
+ seen.add(targetValue);
437
+ /** Make the cache key unique per options and schema path */
438
+ const cacheKey = createOptionsCacheKey(options) + (schemaPath.length > 0 ? `:path:${schemaPath.join('.')}` : '');
439
+ // Check cache first for performance - avoid recomputing the same schema
440
+ const cached = resultCache.get(targetValue)?.get(cacheKey);
441
+ if (typeof cached !== 'undefined') {
442
+ seen.delete(targetValue);
443
+ return cached;
444
+ }
445
+ // Prevent infinite recursion in circular references
446
+ if (level > MAX_LEVELS_DEEP) {
447
+ seen.delete(targetValue);
448
+ return '[Max Depth Exceeded]';
449
+ }
450
+ // Determine if we should generate realistic example data
451
+ const makeUpRandomData = !!options?.emptyString;
452
+ // Early exits for schemas that should not be included (deprecated, readOnly, writeOnly, omitEmptyAndOptionalProperties)
453
+ if (shouldOmitProperty(_schema, parentSchema, name, options)) {
454
+ seen.delete(targetValue);
455
+ return undefined;
456
+ }
457
+ // Handle custom variables (x-variable extension)
458
+ if ('x-variable' in _schema && _schema['x-variable']) {
459
+ const value = options?.variables?.[_schema['x-variable']];
460
+ if (value !== undefined) {
461
+ // Type coercion for numeric types
462
+ if ('type' in _schema && (_schema.type === 'number' || _schema.type === 'integer')) {
463
+ seen.delete(targetValue);
464
+ return cache(_schema, Number(value), cacheKey);
465
+ }
466
+ seen.delete(targetValue);
467
+ return cache(_schema, value, cacheKey);
468
+ }
469
+ }
470
+ // Priority order: examples > example > default > const > enum
471
+ if (Array.isArray(_schema.examples) && _schema.examples.length > 0) {
472
+ seen.delete(targetValue);
473
+ return cache(_schema, _schema.examples[0], cacheKey);
474
+ }
475
+ if (_schema.example !== undefined) {
476
+ seen.delete(targetValue);
477
+ return cache(_schema, _schema.example, cacheKey);
478
+ }
479
+ if (_schema.default !== undefined) {
480
+ seen.delete(targetValue);
481
+ return cache(_schema, _schema.default, cacheKey);
482
+ }
483
+ if (_schema.const !== undefined) {
484
+ seen.delete(targetValue);
485
+ return cache(_schema, _schema.const, cacheKey);
486
+ }
487
+ if (Array.isArray(_schema.enum) && _schema.enum.length > 0) {
488
+ seen.delete(targetValue);
489
+ return cache(_schema, _schema.enum[0], cacheKey);
490
+ }
491
+ // Handle object types - check for properties to identify objects
492
+ if ('properties' in _schema || ('type' in _schema && _schema.type === 'object')) {
493
+ const result = handleObjectSchema(_schema, options, level, seen, cacheKey, schemaPath);
494
+ seen.delete(targetValue);
495
+ return result;
496
+ }
497
+ // Handle array types
498
+ if (('type' in _schema && _schema.type === 'array') || 'items' in _schema) {
499
+ const result = handleArraySchema(_schema, options, level, seen, cacheKey, schemaPath);
500
+ seen.delete(targetValue);
501
+ return result;
502
+ }
503
+ // Handle primitive types without allocating temporary objects
504
+ const primitive = getPrimitiveValue(_schema, makeUpRandomData, options?.emptyString);
505
+ if (primitive !== undefined) {
506
+ seen.delete(targetValue);
507
+ return cache(_schema, primitive, cacheKey);
508
+ }
509
+ // Handle composition schemas (oneOf, anyOf)
510
+ const compositionKeyword = _schema.oneOf ? 'oneOf' : _schema.anyOf ? 'anyOf' : undefined;
511
+ const discriminate = compositionKeyword ? _schema[compositionKeyword] : undefined;
512
+ if (compositionKeyword && Array.isArray(discriminate) && discriminate.length > 0) {
513
+ const index = getCompositionSelectionIndex(schemaPath, compositionKeyword, options, discriminate.length);
514
+ const candidate = index !== undefined
515
+ ? discriminate[index]
516
+ : discriminate.find((item) => {
517
+ const resolved = resolve.schema(item);
518
+ return resolved && (!('type' in resolved) || resolved.type !== 'null');
519
+ });
520
+ if (candidate) {
521
+ const resolved = resolve.schema(candidate);
522
+ if (resolved) {
523
+ seen.delete(targetValue);
524
+ return cache(_schema, getExampleFromSchema(resolved, options, {
525
+ level: level + 1,
526
+ schemaPath,
527
+ seen,
528
+ }), cacheKey);
529
+ }
530
+ }
531
+ seen.delete(targetValue);
532
+ return cache(_schema, null, cacheKey);
533
+ }
534
+ // Handle allOf at root level (non-object/array schemas)
535
+ if (Array.isArray(_schema.allOf) && _schema.allOf.length > 0) {
536
+ let merged = undefined;
537
+ const items = _schema.allOf;
538
+ for (const item of items) {
539
+ const ex = getExampleFromSchema(item, options, {
540
+ level: level + 1,
541
+ parentSchema: _schema,
542
+ schemaPath,
543
+ seen,
544
+ });
545
+ if (merged === undefined) {
546
+ merged = ex;
547
+ }
548
+ else if (merged && typeof merged === 'object' && ex && typeof ex === 'object') {
549
+ merged = mergeExamples(merged, ex);
550
+ }
551
+ else if (ex !== undefined) {
552
+ // Prefer the latest defined primitive value
553
+ merged = ex;
554
+ }
555
+ }
556
+ seen.delete(targetValue);
557
+ return cache(_schema, merged ?? null, cacheKey);
558
+ }
559
+ // Handle union types (array of types)
560
+ const unionPrimitive = getUnionPrimitiveValue(_schema, makeUpRandomData, options?.emptyString);
561
+ if (unionPrimitive !== undefined) {
562
+ seen.delete(targetValue);
563
+ return cache(_schema, unionPrimitive, cacheKey);
564
+ }
565
+ // Default fallback
566
+ seen.delete(targetValue);
567
+ return cache(_schema, null, cacheKey);
568
+ };
@@ -0,0 +1,10 @@
1
+ import type { ExampleObject, MediaTypeObject, ParameterObject, RequestBodyObject } from '@scalar/workspace-store/schemas/v3.1/strict/openapi-document';
2
+ /**
3
+ * Resolve an example value for a parameter or requestBody from either `examples` or `content.*.examples`.
4
+ * Or the [deprecated] `example` field.
5
+ * If no exampleKey is provided it will fallback to the first example in the examples object then the [deprecated]
6
+ * `example` field.
7
+ * Used both for send-request and generating code snippets.
8
+ */
9
+ export declare const getExample: (param: ParameterObject | RequestBodyObject | MediaTypeObject, exampleName: string | undefined, contentType: string | undefined) => ExampleObject | undefined;
10
+ //# sourceMappingURL=get-example.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-example.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/get-example.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,iBAAiB,EAClB,MAAM,8DAA8D,CAAA;AAgCrE;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,eAAe,GAAG,iBAAiB,GAAG,eAAe,EAC5D,aAAa,MAAM,GAAG,SAAS,EAC/B,aAAa,MAAM,GAAG,SAAS,KAC9B,aAAa,GAAG,SA6ClB,CAAA"}
@@ -0,0 +1,66 @@
1
+ import { getResolvedRef } from '../../../helpers/get-resolved-ref.js';
2
+ /** Helper to get example from examples object with fallback to example field */
3
+ const getExampleFromExamples = (examples, exampleField, exampleName) => {
4
+ if (!examples && !exampleField) {
5
+ return undefined;
6
+ }
7
+ const hasExamples = !!examples && Object.keys(examples).length > 0;
8
+ // Grab the example key
9
+ const key = exampleName || Object.keys(examples ?? {})[0] || '';
10
+ const example = getResolvedRef(examples?.[key]);
11
+ if (example !== undefined) {
12
+ return example;
13
+ }
14
+ // Fallback to example field when no examples map exists,
15
+ // or when no specific example key was requested.
16
+ if ((!hasExamples || !exampleName) && exampleField !== undefined) {
17
+ return { value: getResolvedRef(exampleField) };
18
+ }
19
+ return undefined;
20
+ };
21
+ /**
22
+ * Resolve an example value for a parameter or requestBody from either `examples` or `content.*.examples`.
23
+ * Or the [deprecated] `example` field.
24
+ * If no exampleKey is provided it will fallback to the first example in the examples object then the [deprecated]
25
+ * `example` field.
26
+ * Used both for send-request and generating code snippets.
27
+ */
28
+ export const getExample = (param, exampleName, contentType) => {
29
+ // Content based parameters
30
+ if ('content' in param) {
31
+ const content = param.content?.[contentType ?? Object.keys(param.content)[0] ?? ''];
32
+ const result = getExampleFromExamples(content?.examples, content?.example, exampleName);
33
+ if (result !== undefined) {
34
+ return result;
35
+ }
36
+ }
37
+ // Schema based parameters
38
+ if ('examples' in param || 'example' in param) {
39
+ const result = getExampleFromExamples(param.examples, param.example, exampleName);
40
+ if (result !== undefined) {
41
+ return result;
42
+ }
43
+ }
44
+ // Derive value from the schema
45
+ const resolvedParam = getResolvedRef(param);
46
+ if ('schema' in resolvedParam && resolvedParam.schema) {
47
+ const schema = resolvedParam.schema;
48
+ // Default value
49
+ if ('default' in schema && schema.default !== undefined) {
50
+ return { value: schema.default };
51
+ }
52
+ // Enum value
53
+ if ('enum' in schema && schema.enum?.[0] !== undefined) {
54
+ return { value: schema.enum[0] };
55
+ }
56
+ // Examples value
57
+ if ('examples' in schema && schema.examples?.[0] !== undefined) {
58
+ return { value: schema.examples[0] };
59
+ }
60
+ // Example value
61
+ if ('example' in schema && schema.example !== undefined) {
62
+ return { value: schema.example };
63
+ }
64
+ }
65
+ return undefined;
66
+ };
@@ -0,0 +1,20 @@
1
+ import type { ServerObject } from '../../../schemas/v3.1/strict/server.js';
2
+ /**
3
+ * Resolves the full request URL by:
4
+ * 1. Applying OpenAPI server variables to the server URL template.
5
+ * 2. Merging the resolved server URL with the OpenAPI path and optional URL parameters.
6
+ * 3. Applying "allowReserved" query parameter logic if needed (for RFC3986 reserved chars).
7
+ *
8
+ * @param server - The OpenAPI server object or null
9
+ * @param path - The OpenAPI operation path (may contain {variables})
10
+ * @param urlParams - Optional URLSearchParams to include as query parameters
11
+ * @param allowReservedQueryParameters - Optional set of parameter names for which reserved characters should not be percent-encoded
12
+ * @returns The resolved URL as a string
13
+ */
14
+ export declare const getResolvedUrl: ({ server, path, urlParams, }: {
15
+ server: ServerObject | null;
16
+ path: string;
17
+ urlParams?: URLSearchParams;
18
+ allowReservedQueryParameters?: Set<string>;
19
+ }) => string;
20
+ //# sourceMappingURL=get-resolved-url.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-resolved-url.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/helpers/get-resolved-url.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAEhE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,cAAc,GAAI,8BAI5B;IACD,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,eAAe,CAAA;IAC3B,4BAA4B,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAC3C,WAGA,CAAA"}