@scalar/oas-utils 0.2.140 → 0.2.141

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 (280) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/entities/cookie/cookie.js +14 -13
  3. package/dist/entities/cookie/cookie.js.map +7 -0
  4. package/dist/entities/cookie/index.d.ts +1 -1
  5. package/dist/entities/cookie/index.d.ts.map +1 -1
  6. package/dist/entities/cookie/index.js +5 -1
  7. package/dist/entities/cookie/index.js.map +7 -0
  8. package/dist/entities/environment/environment.js +10 -9
  9. package/dist/entities/environment/environment.js.map +7 -0
  10. package/dist/entities/environment/index.d.ts +1 -1
  11. package/dist/entities/environment/index.d.ts.map +1 -1
  12. package/dist/entities/environment/index.js +5 -1
  13. package/dist/entities/environment/index.js.map +7 -0
  14. package/dist/entities/hotkeys/hotkeys.js +109 -116
  15. package/dist/entities/hotkeys/hotkeys.js.map +7 -0
  16. package/dist/entities/hotkeys/index.d.ts +1 -1
  17. package/dist/entities/hotkeys/index.d.ts.map +1 -1
  18. package/dist/entities/hotkeys/index.js +6 -1
  19. package/dist/entities/hotkeys/index.js.map +7 -0
  20. package/dist/entities/shared/index.d.ts +1 -1
  21. package/dist/entities/shared/index.d.ts.map +1 -1
  22. package/dist/entities/shared/index.js +7 -1
  23. package/dist/entities/shared/index.js.map +7 -0
  24. package/dist/entities/shared/utility.js +9 -12
  25. package/dist/entities/shared/utility.js.map +7 -0
  26. package/dist/entities/spec/collection.d.ts.map +1 -1
  27. package/dist/entities/spec/collection.js +91 -94
  28. package/dist/entities/spec/collection.js.map +7 -0
  29. package/dist/entities/spec/index.d.ts +8 -8
  30. package/dist/entities/spec/index.d.ts.map +1 -1
  31. package/dist/entities/spec/index.js +59 -9
  32. package/dist/entities/spec/index.js.map +7 -0
  33. package/dist/entities/spec/operation.d.ts +1 -1
  34. package/dist/entities/spec/operation.d.ts.map +1 -1
  35. package/dist/entities/spec/operation.js +5 -8
  36. package/dist/entities/spec/operation.js.map +7 -0
  37. package/dist/entities/spec/operation.test.js +43 -0
  38. package/dist/entities/spec/operation.test.js.map +7 -0
  39. package/dist/entities/spec/parameters.d.ts +1 -1
  40. package/dist/entities/spec/parameters.d.ts.map +1 -1
  41. package/dist/entities/spec/parameters.js +40 -38
  42. package/dist/entities/spec/parameters.js.map +7 -0
  43. package/dist/entities/spec/parameters.test.js +71 -0
  44. package/dist/entities/spec/parameters.test.js.map +7 -0
  45. package/dist/entities/spec/request-example.test.js +637 -0
  46. package/dist/entities/spec/request-example.test.js.map +7 -0
  47. package/dist/entities/spec/request-examples.d.ts +3 -3
  48. package/dist/entities/spec/request-examples.d.ts.map +1 -1
  49. package/dist/entities/spec/request-examples.js +323 -338
  50. package/dist/entities/spec/request-examples.js.map +7 -0
  51. package/dist/entities/spec/requests.d.ts +6 -8
  52. package/dist/entities/spec/requests.d.ts.map +1 -1
  53. package/dist/entities/spec/requests.js +80 -101
  54. package/dist/entities/spec/requests.js.map +7 -0
  55. package/dist/entities/spec/server.js +47 -63
  56. package/dist/entities/spec/server.js.map +7 -0
  57. package/dist/entities/spec/server.test.js +120 -0
  58. package/dist/entities/spec/server.test.js.map +7 -0
  59. package/dist/entities/spec/spec-objects.d.ts.map +1 -1
  60. package/dist/entities/spec/spec-objects.js +77 -121
  61. package/dist/entities/spec/spec-objects.js.map +7 -0
  62. package/dist/entities/spec/spec-objects.test.js +205 -0
  63. package/dist/entities/spec/spec-objects.test.js.map +7 -0
  64. package/dist/entities/spec/x-scalar-environments.js +21 -18
  65. package/dist/entities/spec/x-scalar-environments.js.map +7 -0
  66. package/dist/entities/spec/x-scalar-environments.test.js +11 -0
  67. package/dist/entities/spec/x-scalar-environments.test.js.map +7 -0
  68. package/dist/entities/spec/x-scalar-secrets.js +8 -6
  69. package/dist/entities/spec/x-scalar-secrets.js.map +7 -0
  70. package/dist/entities/spec/x-scalar-secrets.test.js +11 -0
  71. package/dist/entities/spec/x-scalar-secrets.test.js.map +7 -0
  72. package/dist/entities/workspace/index.d.ts +1 -1
  73. package/dist/entities/workspace/index.d.ts.map +1 -1
  74. package/dist/entities/workspace/index.js +7 -1
  75. package/dist/entities/workspace/index.js.map +7 -0
  76. package/dist/entities/workspace/workspace.js +46 -50
  77. package/dist/entities/workspace/workspace.js.map +7 -0
  78. package/dist/helpers/create-hash.js +15 -18
  79. package/dist/helpers/create-hash.js.map +7 -0
  80. package/dist/helpers/ensure-protocol.js +9 -10
  81. package/dist/helpers/ensure-protocol.js.map +7 -0
  82. package/dist/helpers/ensure-protocol.test.js +70 -0
  83. package/dist/helpers/ensure-protocol.test.js.map +7 -0
  84. package/dist/helpers/fetch-document.js +24 -32
  85. package/dist/helpers/fetch-document.js.map +7 -0
  86. package/dist/helpers/fetch-document.test.js +63 -0
  87. package/dist/helpers/fetch-document.test.js.map +7 -0
  88. package/dist/helpers/fetch-with-proxy-fallback.js +20 -28
  89. package/dist/helpers/fetch-with-proxy-fallback.js.map +7 -0
  90. package/dist/helpers/find-variables.d.ts +1 -1
  91. package/dist/helpers/find-variables.d.ts.map +1 -1
  92. package/dist/helpers/find-variables.js +6 -8
  93. package/dist/helpers/find-variables.js.map +7 -0
  94. package/dist/helpers/find-variables.test.js +20 -0
  95. package/dist/helpers/find-variables.test.js.map +7 -0
  96. package/dist/helpers/http-methods.d.ts +1 -1
  97. package/dist/helpers/http-methods.d.ts.map +1 -1
  98. package/dist/helpers/http-methods.js +60 -66
  99. package/dist/helpers/http-methods.js.map +7 -0
  100. package/dist/helpers/http-status-codes.js +319 -317
  101. package/dist/helpers/http-status-codes.js.map +7 -0
  102. package/dist/helpers/index.d.ts +27 -27
  103. package/dist/helpers/index.d.ts.map +1 -1
  104. package/dist/helpers/index.js +73 -27
  105. package/dist/helpers/index.js.map +7 -0
  106. package/dist/helpers/is-defined.js +5 -14
  107. package/dist/helpers/is-defined.js.map +7 -0
  108. package/dist/helpers/is-defined.test.js +37 -0
  109. package/dist/helpers/is-defined.test.js.map +7 -0
  110. package/dist/helpers/is-local-url.js +11 -16
  111. package/dist/helpers/is-local-url.js.map +7 -0
  112. package/dist/helpers/is-local-url.test.js +40 -0
  113. package/dist/helpers/is-local-url.test.js.map +7 -0
  114. package/dist/helpers/is-valid-url.js +9 -18
  115. package/dist/helpers/is-valid-url.js.map +7 -0
  116. package/dist/helpers/is-valid-url.test.js +17 -0
  117. package/dist/helpers/is-valid-url.test.js.map +7 -0
  118. package/dist/helpers/iterate-title.js +11 -15
  119. package/dist/helpers/iterate-title.js.map +7 -0
  120. package/dist/helpers/json2xml.js +40 -47
  121. package/dist/helpers/json2xml.js.map +7 -0
  122. package/dist/helpers/json2xml.test.js +19 -0
  123. package/dist/helpers/json2xml.test.js.map +7 -0
  124. package/dist/helpers/local-storage.js +13 -15
  125. package/dist/helpers/local-storage.js.map +7 -0
  126. package/dist/helpers/make-url-absolute.js +11 -17
  127. package/dist/helpers/make-url-absolute.js.map +7 -0
  128. package/dist/helpers/make-url-absolute.test.js +61 -0
  129. package/dist/helpers/make-url-absolute.test.js.map +7 -0
  130. package/dist/helpers/merge-urls.js +50 -75
  131. package/dist/helpers/merge-urls.js.map +7 -0
  132. package/dist/helpers/merge-urls.test.js +339 -0
  133. package/dist/helpers/merge-urls.test.js.map +7 -0
  134. package/dist/helpers/normalize-mime-type-object.js +21 -31
  135. package/dist/helpers/normalize-mime-type-object.js.map +7 -0
  136. package/dist/helpers/normalize-mime-type-object.test.js +53 -0
  137. package/dist/helpers/normalize-mime-type-object.test.js.map +7 -0
  138. package/dist/helpers/normalize-mime-type.js +8 -18
  139. package/dist/helpers/normalize-mime-type.js.map +7 -0
  140. package/dist/helpers/normalize-mime-type.test.js +33 -0
  141. package/dist/helpers/normalize-mime-type.test.js.map +7 -0
  142. package/dist/helpers/object.js +12 -18
  143. package/dist/helpers/object.js.map +7 -0
  144. package/dist/helpers/omit-undefined-values.js +17 -19
  145. package/dist/helpers/omit-undefined-values.js.map +7 -0
  146. package/dist/helpers/omit-undefined-values.test.js +89 -0
  147. package/dist/helpers/omit-undefined-values.test.js.map +7 -0
  148. package/dist/helpers/parse.js +71 -83
  149. package/dist/helpers/parse.js.map +7 -0
  150. package/dist/helpers/parse.test.js +45 -0
  151. package/dist/helpers/parse.test.js.map +7 -0
  152. package/dist/helpers/pretty-print-json.js +31 -35
  153. package/dist/helpers/pretty-print-json.js.map +7 -0
  154. package/dist/helpers/pretty-print-json.test.js +28 -0
  155. package/dist/helpers/pretty-print-json.test.js.map +7 -0
  156. package/dist/helpers/redirect-to-proxy.js +46 -83
  157. package/dist/helpers/redirect-to-proxy.js.map +7 -0
  158. package/dist/helpers/redirect-to-proxy.test.js +54 -0
  159. package/dist/helpers/redirect-to-proxy.test.js.map +7 -0
  160. package/dist/helpers/regex-helpers.js +11 -9
  161. package/dist/helpers/regex-helpers.js.map +7 -0
  162. package/dist/helpers/regex-helpers.test.js +154 -0
  163. package/dist/helpers/regex-helpers.test.js.map +7 -0
  164. package/dist/helpers/replace-variables.js +13 -16
  165. package/dist/helpers/replace-variables.js.map +7 -0
  166. package/dist/helpers/replace-variables.test.js +30 -0
  167. package/dist/helpers/replace-variables.test.js.map +7 -0
  168. package/dist/helpers/schema-model.js +15 -14
  169. package/dist/helpers/schema-model.js.map +7 -0
  170. package/dist/helpers/security/get-schemes.d.ts +1 -1
  171. package/dist/helpers/security/get-schemes.d.ts.map +1 -1
  172. package/dist/helpers/security/get-schemes.js +7 -9
  173. package/dist/helpers/security/get-schemes.js.map +7 -0
  174. package/dist/helpers/security/get-schemes.test.js +71 -0
  175. package/dist/helpers/security/get-schemes.test.js.map +7 -0
  176. package/dist/helpers/security/has-token.js +18 -19
  177. package/dist/helpers/security/has-token.js.map +7 -0
  178. package/dist/helpers/security/has-token.test.js +157 -0
  179. package/dist/helpers/security/has-token.test.js.map +7 -0
  180. package/dist/helpers/security/index.d.ts +2 -2
  181. package/dist/helpers/security/index.d.ts.map +1 -1
  182. package/dist/helpers/security/index.js +7 -2
  183. package/dist/helpers/security/index.js.map +7 -0
  184. package/dist/helpers/should-ignore-entity.d.ts +2 -2
  185. package/dist/helpers/should-ignore-entity.d.ts.map +1 -1
  186. package/dist/helpers/should-ignore-entity.js +5 -6
  187. package/dist/helpers/should-ignore-entity.js.map +7 -0
  188. package/dist/helpers/ssr-state.js +6 -6
  189. package/dist/helpers/ssr-state.js.map +7 -0
  190. package/dist/helpers/string.js +6 -18
  191. package/dist/helpers/string.js.map +7 -0
  192. package/dist/migrations/data-version.js +7 -17
  193. package/dist/migrations/data-version.js.map +7 -0
  194. package/dist/migrations/generate-types.js +56 -0
  195. package/dist/migrations/generate-types.js.map +7 -0
  196. package/dist/migrations/index.d.ts +3 -3
  197. package/dist/migrations/index.d.ts.map +1 -1
  198. package/dist/migrations/index.js +10 -3
  199. package/dist/migrations/index.js.map +7 -0
  200. package/dist/migrations/local-storage.d.ts +1 -1
  201. package/dist/migrations/local-storage.d.ts.map +1 -1
  202. package/dist/migrations/local-storage.js +27 -32
  203. package/dist/migrations/local-storage.js.map +7 -0
  204. package/dist/migrations/migrator.d.ts +1 -1
  205. package/dist/migrations/migrator.d.ts.map +1 -1
  206. package/dist/migrations/migrator.js +51 -58
  207. package/dist/migrations/migrator.js.map +7 -0
  208. package/dist/migrations/semver.js +23 -25
  209. package/dist/migrations/semver.js.map +7 -0
  210. package/dist/migrations/semver.test.js +21 -0
  211. package/dist/migrations/semver.test.js.map +7 -0
  212. package/dist/migrations/v-0.0.0/types.generated.js +1 -0
  213. package/dist/migrations/v-0.0.0/types.generated.js.map +7 -0
  214. package/dist/migrations/v-2.1.0/migration.d.ts +2 -2
  215. package/dist/migrations/v-2.1.0/migration.d.ts.map +1 -1
  216. package/dist/migrations/v-2.1.0/migration.js +256 -273
  217. package/dist/migrations/v-2.1.0/migration.js.map +7 -0
  218. package/dist/migrations/v-2.1.0/types.generated.js +1 -0
  219. package/dist/migrations/v-2.1.0/types.generated.js.map +7 -0
  220. package/dist/migrations/v-2.2.0/migration.d.ts +2 -2
  221. package/dist/migrations/v-2.2.0/migration.d.ts.map +1 -1
  222. package/dist/migrations/v-2.2.0/migration.js +95 -100
  223. package/dist/migrations/v-2.2.0/migration.js.map +7 -0
  224. package/dist/migrations/v-2.2.0/types.generated.js +1 -0
  225. package/dist/migrations/v-2.2.0/types.generated.js.map +7 -0
  226. package/dist/migrations/v-2.3.0/migration.d.ts +2 -2
  227. package/dist/migrations/v-2.3.0/migration.d.ts.map +1 -1
  228. package/dist/migrations/v-2.3.0/migration.js +47 -46
  229. package/dist/migrations/v-2.3.0/migration.js.map +7 -0
  230. package/dist/migrations/v-2.3.0/types.generated.js +1 -0
  231. package/dist/migrations/v-2.3.0/types.generated.js.map +7 -0
  232. package/dist/migrations/v-2.4.0/migration.d.ts +2 -2
  233. package/dist/migrations/v-2.4.0/migration.d.ts.map +1 -1
  234. package/dist/migrations/v-2.4.0/migration.js +24 -26
  235. package/dist/migrations/v-2.4.0/migration.js.map +7 -0
  236. package/dist/migrations/v-2.4.0/migration.test.js +90 -0
  237. package/dist/migrations/v-2.4.0/migration.test.js.map +7 -0
  238. package/dist/migrations/v-2.4.0/types.generated.js +1 -0
  239. package/dist/migrations/v-2.4.0/types.generated.js.map +7 -0
  240. package/dist/migrations/v-2.5.0/migration.d.ts +2 -2
  241. package/dist/migrations/v-2.5.0/migration.d.ts.map +1 -1
  242. package/dist/migrations/v-2.5.0/migration.js +135 -119
  243. package/dist/migrations/v-2.5.0/migration.js.map +7 -0
  244. package/dist/migrations/v-2.5.0/migration.test.js +108 -0
  245. package/dist/migrations/v-2.5.0/migration.test.js.map +7 -0
  246. package/dist/migrations/v-2.5.0/types.generated.d.ts +8 -8
  247. package/dist/migrations/v-2.5.0/types.generated.d.ts.map +1 -1
  248. package/dist/migrations/v-2.5.0/types.generated.js +1 -0
  249. package/dist/migrations/v-2.5.0/types.generated.js.map +7 -0
  250. package/dist/spec-getters/get-example-from-schema.js +206 -268
  251. package/dist/spec-getters/get-example-from-schema.js.map +7 -0
  252. package/dist/spec-getters/get-example-from-schema.test.js +1092 -0
  253. package/dist/spec-getters/get-example-from-schema.test.js.map +7 -0
  254. package/dist/spec-getters/get-parameters-from-operation.js +22 -42
  255. package/dist/spec-getters/get-parameters-from-operation.js.map +7 -0
  256. package/dist/spec-getters/get-parameters-from-operation.test.js +178 -0
  257. package/dist/spec-getters/get-parameters-from-operation.test.js.map +7 -0
  258. package/dist/spec-getters/get-request-body-from-operation.js +110 -162
  259. package/dist/spec-getters/get-request-body-from-operation.js.map +7 -0
  260. package/dist/spec-getters/get-request-body-from-operation.test.js +289 -0
  261. package/dist/spec-getters/get-request-body-from-operation.test.js.map +7 -0
  262. package/dist/spec-getters/get-server-variable-examples.d.ts +1 -1
  263. package/dist/spec-getters/get-server-variable-examples.d.ts.map +1 -1
  264. package/dist/spec-getters/get-server-variable-examples.js +12 -11
  265. package/dist/spec-getters/get-server-variable-examples.js.map +7 -0
  266. package/dist/spec-getters/index.d.ts +4 -4
  267. package/dist/spec-getters/index.d.ts.map +1 -1
  268. package/dist/spec-getters/index.js +11 -4
  269. package/dist/spec-getters/index.js.map +7 -0
  270. package/dist/transforms/import-spec.d.ts +6 -6
  271. package/dist/transforms/import-spec.d.ts.map +1 -1
  272. package/dist/transforms/import-spec.js +313 -425
  273. package/dist/transforms/import-spec.js.map +7 -0
  274. package/dist/transforms/import-spec.test.js +1124 -0
  275. package/dist/transforms/import-spec.test.js.map +7 -0
  276. package/dist/transforms/index.d.ts +1 -1
  277. package/dist/transforms/index.d.ts.map +1 -1
  278. package/dist/transforms/index.js +7 -1
  279. package/dist/transforms/index.js.map +7 -0
  280. package/package.json +9 -10
@@ -1,282 +1,220 @@
1
- /** Hard limit for rendering circular references */
2
1
  const MAX_LEVELS_DEEP = 5;
3
- /** Sets the max number of properties after the third level to prevent exponential horizontal growth */
4
2
  const MAX_PROPERTIES = 10;
5
3
  const genericExampleValues = {
6
- // 'date-time': '1970-01-01T00:00:00Z',
7
- 'date-time': new Date().toISOString(),
8
- // 'date': '1970-01-01',
9
- 'date': new Date().toISOString().split('T')[0],
10
- 'email': 'hello@example.com',
11
- 'hostname': 'example.com',
12
- // https://tools.ietf.org/html/rfc6531#section-3.3
13
- 'idn-email': 'jane.doe@example.com',
14
- // https://tools.ietf.org/html/rfc5890#section-2.3.2.3
15
- 'idn-hostname': 'example.com',
16
- 'ipv4': '127.0.0.1',
17
- 'ipv6': '51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998',
18
- 'iri-reference': '/entitiy/1',
19
- // https://tools.ietf.org/html/rfc3987
20
- 'iri': 'https://example.com/entity/123',
21
- 'json-pointer': '/nested/objects',
22
- 'password': 'super-secret',
23
- 'regex': '/[a-z]/',
24
- // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01
25
- 'relative-json-pointer': '1/nested/objects',
26
- // full-time in https://tools.ietf.org/html/rfc3339#section-5.6
27
- // 'time': '00:00:00Z',
28
- 'time': new Date().toISOString().split('T')[1].split('.')[0],
29
- // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1
30
- 'uri-reference': '../folder',
31
- 'uri-template': 'https://example.com/{id}',
32
- 'uri': 'https://example.com',
33
- 'uuid': '123e4567-e89b-12d3-a456-426614174000',
34
- 'object-id': '6592008029c8c3e4dc76256c',
4
+ // 'date-time': '1970-01-01T00:00:00Z',
5
+ "date-time": (/* @__PURE__ */ new Date()).toISOString(),
6
+ // 'date': '1970-01-01',
7
+ "date": (/* @__PURE__ */ new Date()).toISOString().split("T")[0],
8
+ "email": "hello@example.com",
9
+ "hostname": "example.com",
10
+ // https://tools.ietf.org/html/rfc6531#section-3.3
11
+ "idn-email": "jane.doe@example.com",
12
+ // https://tools.ietf.org/html/rfc5890#section-2.3.2.3
13
+ "idn-hostname": "example.com",
14
+ "ipv4": "127.0.0.1",
15
+ "ipv6": "51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998",
16
+ "iri-reference": "/entitiy/1",
17
+ // https://tools.ietf.org/html/rfc3987
18
+ "iri": "https://example.com/entity/123",
19
+ "json-pointer": "/nested/objects",
20
+ "password": "super-secret",
21
+ "regex": "/[a-z]/",
22
+ // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01
23
+ "relative-json-pointer": "1/nested/objects",
24
+ // full-time in https://tools.ietf.org/html/rfc3339#section-5.6
25
+ // 'time': '00:00:00Z',
26
+ "time": (/* @__PURE__ */ new Date()).toISOString().split("T")[1].split(".")[0],
27
+ // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1
28
+ "uri-reference": "../folder",
29
+ "uri-template": "https://example.com/{id}",
30
+ "uri": "https://example.com",
31
+ "uuid": "123e4567-e89b-12d3-a456-426614174000",
32
+ "object-id": "6592008029c8c3e4dc76256c"
35
33
  };
36
- /**
37
- * We can use the `format` to generate some random values.
38
- */
39
- function guessFromFormat(schema, fallback = '') {
40
- return genericExampleValues[schema.format] ?? fallback;
34
+ function guessFromFormat(schema, fallback = "") {
35
+ return genericExampleValues[schema.format] ?? fallback;
41
36
  }
42
- /** Map of all the results */
43
- const resultCache = new WeakMap();
44
- /** Store result in the cache, and return the result */
37
+ const resultCache = /* @__PURE__ */ new WeakMap();
45
38
  function cache(schema, result) {
46
- // Avoid unnecessary WeakMap operations for primitive values
47
- if (typeof result !== 'object' || result === null) {
48
- return result;
49
- }
50
- resultCache.set(schema, result);
39
+ if (typeof result !== "object" || result === null) {
51
40
  return result;
41
+ }
42
+ resultCache.set(schema, result);
43
+ return result;
52
44
  }
53
- /**
54
- * This function takes an OpenAPI schema and generates an example from it
55
- */
56
45
  const getExampleFromSchema = (schema, options, level = 0, parentSchema, name) => {
57
- // Check if the result is already cached
58
- if (resultCache.has(schema)) {
59
- return resultCache.get(schema);
60
- }
61
- // Check whether it’s a circular reference
62
- if (level === MAX_LEVELS_DEEP + 1) {
63
- try {
64
- // Fails if it contains a circular reference
65
- JSON.stringify(schema);
66
- }
67
- catch {
68
- return '[Circular Reference]';
69
- }
70
- }
71
- // Sometimes, we just want the structure and no values.
72
- // But if `emptyString` is set, we do want to see some values.
73
- const makeUpRandomData = !!options?.emptyString;
74
- // If the property is deprecated anyway, we don’t want to show it.
75
- if (schema.deprecated) {
76
- return undefined;
77
- }
78
- // Check if the property is read-only/write-only
79
- if ((options?.mode === 'write' && schema.readOnly) || (options?.mode === 'read' && schema.writeOnly)) {
80
- return undefined;
81
- }
82
- // Use given variables as values
83
- if (schema['x-variable']) {
84
- const value = options?.variables?.[schema['x-variable']];
85
- // Return the value if it’s defined
86
- if (value !== undefined) {
87
- // Type-casting
88
- if (schema.type === 'number' || schema.type === 'integer') {
89
- return Number.parseInt(value, 10);
90
- }
91
- return cache(schema, value);
92
- }
93
- }
94
- // Use the first example, if there’s an array
95
- if (Array.isArray(schema.examples) && schema.examples.length > 0) {
96
- return cache(schema, schema.examples[0]);
97
- }
98
- // Use an example, if there’s one
99
- if (schema.example !== undefined) {
100
- return cache(schema, schema.example);
101
- }
102
- // Use a default value, if there’s one
103
- if (schema.default !== undefined) {
104
- return cache(schema, schema.default);
105
- }
106
- // enum: [ 'available', 'pending', 'sold' ]
107
- if (Array.isArray(schema.enum) && schema.enum.length > 0) {
108
- return cache(schema, schema.enum[0]);
109
- }
110
- // Check if the property is required
111
- const isObjectOrArray = schema.type === 'object' ||
112
- schema.type === 'array' ||
113
- !!schema.allOf?.at?.(0) ||
114
- !!schema.anyOf?.at?.(0) ||
115
- !!schema.oneOf?.at?.(0);
116
- if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {
117
- const isRequired = schema.required === true ||
118
- parentSchema?.required === true ||
119
- parentSchema?.required?.includes(name ?? schema.name);
120
- if (!isRequired) {
121
- return undefined;
122
- }
123
- }
124
- // Object
125
- if (schema.type === 'object' || schema.properties !== undefined) {
126
- const response = {};
127
- let propertyCount = 0;
128
- // Regular properties
129
- if (schema.properties !== undefined) {
130
- for (const propertyName in schema.properties) {
131
- if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
132
- // Only apply property limit for nested levels (level > 0)
133
- if (level > 3 && propertyCount >= MAX_PROPERTIES) {
134
- response['...'] = '[Additional Properties Truncated]';
135
- break;
136
- }
137
- const property = schema.properties[propertyName];
138
- const propertyXmlTagName = options?.xml ? property.xml?.name : undefined;
139
- const value = getExampleFromSchema(property, options, level + 1, schema, propertyName);
140
- if (typeof value !== 'undefined') {
141
- response[propertyXmlTagName ?? propertyName] = value;
142
- propertyCount++;
143
- }
144
- }
145
- }
46
+ if (resultCache.has(schema)) {
47
+ return resultCache.get(schema);
48
+ }
49
+ if (level === MAX_LEVELS_DEEP + 1) {
50
+ try {
51
+ JSON.stringify(schema);
52
+ } catch {
53
+ return "[Circular Reference]";
54
+ }
55
+ }
56
+ const makeUpRandomData = !!options?.emptyString;
57
+ if (schema.deprecated) {
58
+ return void 0;
59
+ }
60
+ if (options?.mode === "write" && schema.readOnly || options?.mode === "read" && schema.writeOnly) {
61
+ return void 0;
62
+ }
63
+ if (schema["x-variable"]) {
64
+ const value = options?.variables?.[schema["x-variable"]];
65
+ if (value !== void 0) {
66
+ if (schema.type === "number" || schema.type === "integer") {
67
+ return Number.parseInt(value, 10);
68
+ }
69
+ return cache(schema, value);
70
+ }
71
+ }
72
+ if (Array.isArray(schema.examples) && schema.examples.length > 0) {
73
+ return cache(schema, schema.examples[0]);
74
+ }
75
+ if (schema.example !== void 0) {
76
+ return cache(schema, schema.example);
77
+ }
78
+ if (schema.default !== void 0) {
79
+ return cache(schema, schema.default);
80
+ }
81
+ if (Array.isArray(schema.enum) && schema.enum.length > 0) {
82
+ return cache(schema, schema.enum[0]);
83
+ }
84
+ const isObjectOrArray = schema.type === "object" || schema.type === "array" || !!schema.allOf?.at?.(0) || !!schema.anyOf?.at?.(0) || !!schema.oneOf?.at?.(0);
85
+ if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {
86
+ const isRequired = schema.required === true || parentSchema?.required === true || parentSchema?.required?.includes(name ?? schema.name);
87
+ if (!isRequired) {
88
+ return void 0;
89
+ }
90
+ }
91
+ if (schema.type === "object" || schema.properties !== void 0) {
92
+ const response = {};
93
+ let propertyCount = 0;
94
+ if (schema.properties !== void 0) {
95
+ for (const propertyName in schema.properties) {
96
+ if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {
97
+ if (level > 3 && propertyCount >= MAX_PROPERTIES) {
98
+ response["..."] = "[Additional Properties Truncated]";
99
+ break;
100
+ }
101
+ const property = schema.properties[propertyName];
102
+ const propertyXmlTagName = options?.xml ? property.xml?.name : void 0;
103
+ const value = getExampleFromSchema(property, options, level + 1, schema, propertyName);
104
+ if (typeof value !== "undefined") {
105
+ response[propertyXmlTagName ?? propertyName] = value;
106
+ propertyCount++;
107
+ }
146
108
  }
147
- // Pattern properties (regex)
148
- if (schema.patternProperties !== undefined) {
149
- for (const pattern in schema.patternProperties) {
150
- if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {
151
- const property = schema.patternProperties[pattern];
152
- // Use the regex pattern as an example key
153
- const exampleKey = pattern;
154
- response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey);
155
- }
156
- }
109
+ }
110
+ }
111
+ if (schema.patternProperties !== void 0) {
112
+ for (const pattern in schema.patternProperties) {
113
+ if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {
114
+ const property = schema.patternProperties[pattern];
115
+ const exampleKey = pattern;
116
+ response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey);
157
117
  }
158
- // Additional properties
159
- if (schema.additionalProperties !== undefined) {
160
- const anyTypeIsValid =
161
- // true
162
- schema.additionalProperties === true ||
163
- // or an empty object {}
164
- (typeof schema.additionalProperties === 'object' && !Object.keys(schema.additionalProperties).length);
165
- if (anyTypeIsValid) {
166
- response['ANY_ADDITIONAL_PROPERTY'] = 'anything';
167
- }
168
- else if (schema.additionalProperties !== false) {
169
- response['ANY_ADDITIONAL_PROPERTY'] = getExampleFromSchema(schema.additionalProperties, options, level + 1);
170
- }
118
+ }
119
+ }
120
+ if (schema.additionalProperties !== void 0) {
121
+ const anyTypeIsValid = (
122
+ // true
123
+ schema.additionalProperties === true || // or an empty object {}
124
+ typeof schema.additionalProperties === "object" && !Object.keys(schema.additionalProperties).length
125
+ );
126
+ if (anyTypeIsValid) {
127
+ response["ANY_ADDITIONAL_PROPERTY"] = "anything";
128
+ } else if (schema.additionalProperties !== false) {
129
+ response["ANY_ADDITIONAL_PROPERTY"] = getExampleFromSchema(schema.additionalProperties, options, level + 1);
130
+ }
131
+ }
132
+ if (schema.anyOf !== void 0) {
133
+ Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1));
134
+ } else if (schema.oneOf !== void 0) {
135
+ Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1));
136
+ } else if (schema.allOf !== void 0) {
137
+ Object.assign(
138
+ response,
139
+ ...schema.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema)).filter((item) => item !== void 0)
140
+ );
141
+ }
142
+ return cache(schema, response);
143
+ }
144
+ if (schema.type === "array" || schema.items !== void 0) {
145
+ const itemsXmlTagName = schema?.items?.xml?.name;
146
+ const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName);
147
+ if (schema.example !== void 0) {
148
+ return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example);
149
+ }
150
+ if (schema.items) {
151
+ if (schema.items.allOf) {
152
+ if (schema.items.allOf[0].type === "object") {
153
+ const mergedExample = getExampleFromSchema(
154
+ { type: "object", allOf: schema.items.allOf },
155
+ options,
156
+ level + 1,
157
+ schema
158
+ );
159
+ return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample]);
171
160
  }
172
- if (schema.anyOf !== undefined) {
173
- Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1));
161
+ const examples = schema.items.allOf.map((item) => getExampleFromSchema(item, options, level + 1, schema)).filter((item) => item !== void 0);
162
+ return cache(schema, wrapItems ? examples.map((example) => ({ [itemsXmlTagName]: example })) : examples);
163
+ }
164
+ const rules = ["anyOf", "oneOf"];
165
+ for (const rule of rules) {
166
+ if (!schema.items[rule]) {
167
+ continue;
174
168
  }
175
- else if (schema.oneOf !== undefined) {
176
- Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1));
177
- }
178
- else if (schema.allOf !== undefined) {
179
- Object.assign(response, ...schema.allOf
180
- .map((item) => getExampleFromSchema(item, options, level + 1, schema))
181
- .filter((item) => item !== undefined));
182
- }
183
- return cache(schema, response);
184
- }
185
- // Array
186
- if (schema.type === 'array' || schema.items !== undefined) {
187
- const itemsXmlTagName = schema?.items?.xml?.name;
188
- const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName);
189
- if (schema.example !== undefined) {
190
- return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example);
191
- }
192
- // Check whether the array has a anyOf, oneOf, or allOf rule
193
- if (schema.items) {
194
- // First handle allOf separately since it needs special handling
195
- if (schema.items.allOf) {
196
- // If the first item is an object type, merge all schemas
197
- if (schema.items.allOf[0].type === 'object') {
198
- const mergedExample = getExampleFromSchema({ type: 'object', allOf: schema.items.allOf }, options, level + 1, schema);
199
- return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample]);
200
- }
201
- // For non-objects (like strings), collect all examples
202
- const examples = schema.items.allOf
203
- .map((item) => getExampleFromSchema(item, options, level + 1, schema))
204
- .filter((item) => item !== undefined);
205
- return cache(schema, wrapItems ? examples.map((example) => ({ [itemsXmlTagName]: example })) : examples);
206
- }
207
- // Handle other rules (anyOf, oneOf)
208
- const rules = ['anyOf', 'oneOf'];
209
- for (const rule of rules) {
210
- if (!schema.items[rule]) {
211
- continue;
212
- }
213
- const schemas = schema.items[rule].slice(0, 1);
214
- const exampleFromRule = schemas
215
- .map((item) => getExampleFromSchema(item, options, level + 1, schema))
216
- .filter((item) => item !== undefined);
217
- return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule);
218
- }
219
- }
220
- if (schema.items?.type) {
221
- const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1);
222
- return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
223
- }
224
- return [];
225
- }
226
- const exampleValues = {
227
- string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : '',
228
- boolean: true,
229
- integer: schema.min ?? 1,
230
- number: schema.min ?? 1,
231
- array: [],
232
- };
233
- if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {
234
- return cache(schema, exampleValues[schema.type]);
235
- }
236
- const discriminateSchema = schema.oneOf || schema.anyOf;
237
- // Check if property has the `oneOf` | `anyOf` key
238
- if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
239
- // Get the first item from the `oneOf` | `anyOf` array
240
- const firstOneOfItem = discriminateSchema[0];
241
- // Return an example for the first item
242
- return getExampleFromSchema(firstOneOfItem, options, level + 1);
243
- }
244
- // Check if schema has the `allOf` key
245
- if (Array.isArray(schema.allOf)) {
246
- let example = null;
247
- // Loop through all `allOf` schemas
248
- schema.allOf.forEach((allOfItem) => {
249
- // Return an example from the schema
250
- const newExample = getExampleFromSchema(allOfItem, options, level + 1);
251
- // Merge or overwrite the example
252
- example =
253
- typeof newExample === 'object' && typeof example === 'object'
254
- ? {
255
- ...(example ?? {}),
256
- ...newExample,
257
- }
258
- : Array.isArray(newExample) && Array.isArray(example)
259
- ? [...(example ?? {}), ...newExample]
260
- : newExample;
261
- });
262
- return cache(schema, example);
263
- }
264
- // Check if schema is a union type
265
- if (Array.isArray(schema.type)) {
266
- // Return null if the type is nullable
267
- if (schema.type.includes('null')) {
268
- return null;
269
- }
270
- // Return an example for the first type in the union
271
- const exampleValue = exampleValues[schema.type[0]];
272
- if (exampleValue !== undefined) {
273
- return cache(schema, exampleValue);
274
- }
275
- }
276
- // Warn if the type is unknown …
277
- // console.warn(`[getExampleFromSchema] Unknown property type "${schema.type}".`)
278
- // … and just return null for now.
279
- return null;
169
+ const schemas = schema.items[rule].slice(0, 1);
170
+ const exampleFromRule = schemas.map((item) => getExampleFromSchema(item, options, level + 1, schema)).filter((item) => item !== void 0);
171
+ return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule);
172
+ }
173
+ }
174
+ if (schema.items?.type) {
175
+ const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1);
176
+ return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema];
177
+ }
178
+ return [];
179
+ }
180
+ const exampleValues = {
181
+ string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : "",
182
+ boolean: true,
183
+ integer: schema.min ?? 1,
184
+ number: schema.min ?? 1,
185
+ array: []
186
+ };
187
+ if (schema.type !== void 0 && exampleValues[schema.type] !== void 0) {
188
+ return cache(schema, exampleValues[schema.type]);
189
+ }
190
+ const discriminateSchema = schema.oneOf || schema.anyOf;
191
+ if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {
192
+ const firstOneOfItem = discriminateSchema[0];
193
+ return getExampleFromSchema(firstOneOfItem, options, level + 1);
194
+ }
195
+ if (Array.isArray(schema.allOf)) {
196
+ let example = null;
197
+ schema.allOf.forEach((allOfItem) => {
198
+ const newExample = getExampleFromSchema(allOfItem, options, level + 1);
199
+ example = typeof newExample === "object" && typeof example === "object" ? {
200
+ ...example ?? {},
201
+ ...newExample
202
+ } : Array.isArray(newExample) && Array.isArray(example) ? [...example ?? {}, ...newExample] : newExample;
203
+ });
204
+ return cache(schema, example);
205
+ }
206
+ if (Array.isArray(schema.type)) {
207
+ if (schema.type.includes("null")) {
208
+ return null;
209
+ }
210
+ const exampleValue = exampleValues[schema.type[0]];
211
+ if (exampleValue !== void 0) {
212
+ return cache(schema, exampleValue);
213
+ }
214
+ }
215
+ return null;
216
+ };
217
+ export {
218
+ getExampleFromSchema
280
219
  };
281
-
282
- export { getExampleFromSchema };
220
+ //# sourceMappingURL=get-example-from-schema.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/spec-getters/get-example-from-schema.ts"],
4
+ "sourcesContent": ["/** Hard limit for rendering circular references */\nconst MAX_LEVELS_DEEP = 5\n/** Sets the max number of properties after the third level to prevent exponential horizontal growth */\nconst MAX_PROPERTIES = 10\n\nconst genericExampleValues: Record<string, string> = {\n // 'date-time': '1970-01-01T00:00:00Z',\n 'date-time': new Date().toISOString(),\n // 'date': '1970-01-01',\n 'date': new Date().toISOString().split('T')[0]!,\n 'email': 'hello@example.com',\n 'hostname': 'example.com',\n // https://tools.ietf.org/html/rfc6531#section-3.3\n 'idn-email': 'jane.doe@example.com',\n // https://tools.ietf.org/html/rfc5890#section-2.3.2.3\n 'idn-hostname': 'example.com',\n 'ipv4': '127.0.0.1',\n 'ipv6': '51d4:7fab:bfbf:b7d7:b2cb:d4b4:3dad:d998',\n 'iri-reference': '/entitiy/1',\n // https://tools.ietf.org/html/rfc3987\n 'iri': 'https://example.com/entity/123',\n 'json-pointer': '/nested/objects',\n 'password': 'super-secret',\n 'regex': '/[a-z]/',\n // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01\n 'relative-json-pointer': '1/nested/objects',\n // full-time in https://tools.ietf.org/html/rfc3339#section-5.6\n // 'time': '00:00:00Z',\n 'time': new Date().toISOString().split('T')[1]!.split('.')[0]!,\n // either a URI or relative-reference https://tools.ietf.org/html/rfc3986#section-4.1\n 'uri-reference': '../folder',\n 'uri-template': 'https://example.com/{id}',\n 'uri': 'https://example.com',\n 'uuid': '123e4567-e89b-12d3-a456-426614174000',\n 'object-id': '6592008029c8c3e4dc76256c',\n}\n\n/**\n * We can use the `format` to generate some random values.\n */\nfunction guessFromFormat(schema: Record<string, any>, fallback: string = '') {\n return genericExampleValues[schema.format] ?? fallback\n}\n\n/** Map of all the results */\nconst resultCache = new WeakMap<Record<string, any>, any>()\n\n/** Store result in the cache, and return the result */\nfunction cache(schema: Record<string, any>, result: unknown) {\n // Avoid unnecessary WeakMap operations for primitive values\n if (typeof result !== 'object' || result === null) {\n return result\n }\n\n resultCache.set(schema, result)\n\n return result\n}\n\n/**\n * This function takes an OpenAPI schema and generates an example from it\n */\nexport const getExampleFromSchema = (\n schema: Record<string, any>,\n options?: {\n /**\n * The fallback string for empty string values.\n * @default ''\n */\n emptyString?: string\n /**\n * Whether to use the XML tag names as keys\n * @default false\n */\n xml?: boolean\n /**\n * Whether to show read-only/write-only properties. Otherwise all properties are shown.\n * @default undefined\n */\n mode?: 'read' | 'write'\n /**\n * Dynamic values to add to the example.\n */\n variables?: Record<string, any>\n /**\n * Whether to omit empty and optional properties.\n * @default false\n */\n omitEmptyAndOptionalProperties?: boolean\n },\n level: number = 0,\n parentSchema?: Record<string, any>,\n name?: string,\n): any => {\n // Check if the result is already cached\n if (resultCache.has(schema)) {\n return resultCache.get(schema)\n }\n\n // Check whether it\u2019s a circular reference\n if (level === MAX_LEVELS_DEEP + 1) {\n try {\n // Fails if it contains a circular reference\n JSON.stringify(schema)\n } catch {\n return '[Circular Reference]'\n }\n }\n\n // Sometimes, we just want the structure and no values.\n // But if `emptyString` is set, we do want to see some values.\n const makeUpRandomData = !!options?.emptyString\n\n // If the property is deprecated anyway, we don\u2019t want to show it.\n if (schema.deprecated) {\n return undefined\n }\n\n // Check if the property is read-only/write-only\n if ((options?.mode === 'write' && schema.readOnly) || (options?.mode === 'read' && schema.writeOnly)) {\n return undefined\n }\n\n // Use given variables as values\n if (schema['x-variable']) {\n const value = options?.variables?.[schema['x-variable']]\n\n // Return the value if it\u2019s defined\n if (value !== undefined) {\n // Type-casting\n if (schema.type === 'number' || schema.type === 'integer') {\n return Number.parseInt(value, 10)\n }\n\n return cache(schema, value)\n }\n }\n\n // Use the first example, if there\u2019s an array\n if (Array.isArray(schema.examples) && schema.examples.length > 0) {\n return cache(schema, schema.examples[0])\n }\n\n // Use an example, if there\u2019s one\n if (schema.example !== undefined) {\n return cache(schema, schema.example)\n }\n\n // Use a default value, if there\u2019s one\n if (schema.default !== undefined) {\n return cache(schema, schema.default)\n }\n\n // enum: [ 'available', 'pending', 'sold' ]\n if (Array.isArray(schema.enum) && schema.enum.length > 0) {\n return cache(schema, schema.enum[0])\n }\n\n // Check if the property is required\n const isObjectOrArray =\n schema.type === 'object' ||\n schema.type === 'array' ||\n !!schema.allOf?.at?.(0) ||\n !!schema.anyOf?.at?.(0) ||\n !!schema.oneOf?.at?.(0)\n if (!isObjectOrArray && options?.omitEmptyAndOptionalProperties === true) {\n const isRequired =\n schema.required === true ||\n parentSchema?.required === true ||\n parentSchema?.required?.includes(name ?? schema.name)\n\n if (!isRequired) {\n return undefined\n }\n }\n\n // Object\n if (schema.type === 'object' || schema.properties !== undefined) {\n const response: Record<string, any> = {}\n let propertyCount = 0\n\n // Regular properties\n if (schema.properties !== undefined) {\n for (const propertyName in schema.properties) {\n if (Object.prototype.hasOwnProperty.call(schema.properties, propertyName)) {\n // Only apply property limit for nested levels (level > 0)\n if (level > 3 && propertyCount >= MAX_PROPERTIES) {\n response['...'] = '[Additional Properties Truncated]'\n break\n }\n\n const property = schema.properties[propertyName]\n const propertyXmlTagName = options?.xml ? property.xml?.name : undefined\n\n const value = getExampleFromSchema(property, options, level + 1, schema, propertyName)\n\n if (typeof value !== 'undefined') {\n response[propertyXmlTagName ?? propertyName] = value\n propertyCount++\n }\n }\n }\n }\n\n // Pattern properties (regex)\n if (schema.patternProperties !== undefined) {\n for (const pattern in schema.patternProperties) {\n if (Object.prototype.hasOwnProperty.call(schema.patternProperties, pattern)) {\n const property = schema.patternProperties[pattern]\n\n // Use the regex pattern as an example key\n const exampleKey = pattern\n\n response[exampleKey] = getExampleFromSchema(property, options, level + 1, schema, exampleKey)\n }\n }\n }\n\n // Additional properties\n if (schema.additionalProperties !== undefined) {\n const anyTypeIsValid =\n // true\n schema.additionalProperties === true ||\n // or an empty object {}\n (typeof schema.additionalProperties === 'object' && !Object.keys(schema.additionalProperties).length)\n\n if (anyTypeIsValid) {\n response['ANY_ADDITIONAL_PROPERTY'] = 'anything'\n } else if (schema.additionalProperties !== false) {\n response['ANY_ADDITIONAL_PROPERTY'] = getExampleFromSchema(schema.additionalProperties, options, level + 1)\n }\n }\n\n if (schema.anyOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.anyOf[0], options, level + 1))\n } else if (schema.oneOf !== undefined) {\n Object.assign(response, getExampleFromSchema(schema.oneOf[0], options, level + 1))\n } else if (schema.allOf !== undefined) {\n Object.assign(\n response,\n ...schema.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined),\n )\n }\n\n return cache(schema, response)\n }\n\n // Array\n if (schema.type === 'array' || schema.items !== undefined) {\n const itemsXmlTagName = schema?.items?.xml?.name\n const wrapItems = !!(options?.xml && schema.xml?.wrapped && itemsXmlTagName)\n\n if (schema.example !== undefined) {\n return cache(schema, wrapItems ? { [itemsXmlTagName]: schema.example } : schema.example)\n }\n\n // Check whether the array has a anyOf, oneOf, or allOf rule\n if (schema.items) {\n // First handle allOf separately since it needs special handling\n if (schema.items.allOf) {\n // If the first item is an object type, merge all schemas\n if (schema.items.allOf[0].type === 'object') {\n const mergedExample = getExampleFromSchema(\n { type: 'object', allOf: schema.items.allOf },\n options,\n level + 1,\n schema,\n )\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: mergedExample }] : [mergedExample])\n }\n // For non-objects (like strings), collect all examples\n const examples = schema.items.allOf\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? examples.map((example: any) => ({ [itemsXmlTagName]: example })) : examples)\n }\n\n // Handle other rules (anyOf, oneOf)\n const rules = ['anyOf', 'oneOf']\n for (const rule of rules) {\n if (!schema.items[rule]) {\n continue\n }\n\n const schemas = schema.items[rule].slice(0, 1)\n const exampleFromRule = schemas\n .map((item: Record<string, any>) => getExampleFromSchema(item, options, level + 1, schema))\n .filter((item: any) => item !== undefined)\n\n return cache(schema, wrapItems ? [{ [itemsXmlTagName]: exampleFromRule }] : exampleFromRule)\n }\n }\n\n if (schema.items?.type) {\n const exampleFromSchema = getExampleFromSchema(schema.items, options, level + 1)\n\n return wrapItems ? [{ [itemsXmlTagName]: exampleFromSchema }] : [exampleFromSchema]\n }\n\n return []\n }\n\n const exampleValues: Record<any, any> = {\n string: makeUpRandomData ? guessFromFormat(schema, options?.emptyString) : '',\n boolean: true,\n integer: schema.min ?? 1,\n number: schema.min ?? 1,\n array: [],\n }\n\n if (schema.type !== undefined && exampleValues[schema.type] !== undefined) {\n return cache(schema, exampleValues[schema.type])\n }\n\n const discriminateSchema = schema.oneOf || schema.anyOf\n // Check if property has the `oneOf` | `anyOf` key\n if (Array.isArray(discriminateSchema) && discriminateSchema.length > 0) {\n // Get the first item from the `oneOf` | `anyOf` array\n const firstOneOfItem = discriminateSchema[0]\n\n // Return an example for the first item\n return getExampleFromSchema(firstOneOfItem, options, level + 1)\n }\n\n // Check if schema has the `allOf` key\n if (Array.isArray(schema.allOf)) {\n let example: any = null\n\n // Loop through all `allOf` schemas\n schema.allOf.forEach((allOfItem: Record<string, any>) => {\n // Return an example from the schema\n const newExample = getExampleFromSchema(allOfItem, options, level + 1)\n\n // Merge or overwrite the example\n example =\n typeof newExample === 'object' && typeof example === 'object'\n ? {\n ...(example ?? {}),\n ...newExample,\n }\n : Array.isArray(newExample) && Array.isArray(example)\n ? [...(example ?? {}), ...newExample]\n : newExample\n })\n\n return cache(schema, example)\n }\n\n // Check if schema is a union type\n if (Array.isArray(schema.type)) {\n // Return null if the type is nullable\n if (schema.type.includes('null')) {\n return null\n }\n // Return an example for the first type in the union\n const exampleValue = exampleValues[schema.type[0]]\n if (exampleValue !== undefined) {\n return cache(schema, exampleValue)\n }\n }\n\n // Warn if the type is unknown \u2026\n // console.warn(`[getExampleFromSchema] Unknown property type \"${schema.type}\".`)\n\n // \u2026 and just return null for now.\n return null\n}\n"],
5
+ "mappings": "AACA,MAAM,kBAAkB;AAExB,MAAM,iBAAiB;AAEvB,MAAM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