@scalar/openapi-parser 0.10.15 → 0.10.17

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 (332) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +0 -22
  3. package/dist/configuration/index.js +19 -22
  4. package/dist/configuration/index.js.map +7 -0
  5. package/dist/declarations.d.js +1 -0
  6. package/dist/declarations.d.js.map +7 -0
  7. package/dist/index.d.ts +4 -4
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +5 -29
  10. package/dist/index.js.map +7 -0
  11. package/dist/lib/Validator/Validator.d.ts +2 -2
  12. package/dist/lib/Validator/Validator.d.ts.map +1 -1
  13. package/dist/lib/Validator/Validator.js +99 -119
  14. package/dist/lib/Validator/Validator.js.map +7 -0
  15. package/dist/lib/Validator/Validator.test.js +8 -0
  16. package/dist/lib/Validator/Validator.test.js.map +7 -0
  17. package/dist/lib/Validator/index.d.ts +2 -2
  18. package/dist/lib/Validator/index.d.ts.map +1 -1
  19. package/dist/lib/Validator/index.js +3 -0
  20. package/dist/lib/Validator/index.js.map +7 -0
  21. package/dist/plugins/fetch-urls/fetchUrls.d.ts +1 -2
  22. package/dist/plugins/fetch-urls/fetchUrls.d.ts.map +1 -1
  23. package/dist/plugins/fetch-urls/fetchUrls.js +36 -111
  24. package/dist/plugins/fetch-urls/fetchUrls.js.map +7 -0
  25. package/dist/plugins/fetch-urls/fetchUrls.test.js +50 -0
  26. package/dist/plugins/fetch-urls/fetchUrls.test.js.map +7 -0
  27. package/dist/plugins/fetch-urls/index.d.ts +1 -1
  28. package/dist/plugins/fetch-urls/index.d.ts.map +1 -1
  29. package/dist/plugins/fetch-urls/index.js +2 -1
  30. package/dist/plugins/fetch-urls/index.js.map +7 -0
  31. package/dist/plugins/read-files/index.d.ts +1 -1
  32. package/dist/plugins/read-files/index.d.ts.map +1 -1
  33. package/dist/plugins/read-files/index.js +2 -1
  34. package/dist/plugins/read-files/index.js.map +7 -0
  35. package/dist/plugins/read-files/readFiles.d.ts +1 -1
  36. package/dist/plugins/read-files/readFiles.d.ts.map +1 -1
  37. package/dist/plugins/read-files/readFiles.js +50 -70
  38. package/dist/plugins/read-files/readFiles.js.map +7 -0
  39. package/dist/plugins/read-files/readFiles.test.js +20 -0
  40. package/dist/plugins/read-files/readFiles.test.js.map +7 -0
  41. package/dist/polyfills/index.d.ts +1 -1
  42. package/dist/polyfills/index.d.ts.map +1 -1
  43. package/dist/polyfills/index.js +5 -0
  44. package/dist/polyfills/index.js.map +7 -0
  45. package/dist/polyfills/path.js +155 -98
  46. package/dist/polyfills/path.js.map +7 -0
  47. package/dist/schemas/v2.0/schema.d.ts +1405 -0
  48. package/dist/schemas/v2.0/schema.d.ts.map +1 -0
  49. package/dist/schemas/v2.0/schema.js +1463 -0
  50. package/dist/schemas/v2.0/schema.js.map +7 -0
  51. package/dist/schemas/v3.0/schema.d.ts +1264 -0
  52. package/dist/schemas/v3.0/schema.d.ts.map +1 -0
  53. package/dist/schemas/v3.0/schema.js +1493 -0
  54. package/dist/schemas/v3.0/schema.js.map +7 -0
  55. package/dist/schemas/v3.1/schema.d.ts +1225 -0
  56. package/dist/schemas/v3.1/schema.d.ts.map +1 -0
  57. package/dist/schemas/v3.1/schema.js +1296 -0
  58. package/dist/schemas/v3.1/schema.js.map +7 -0
  59. package/dist/types/index.d.ts +5 -24
  60. package/dist/types/index.d.ts.map +1 -1
  61. package/dist/types/index.js +1 -0
  62. package/dist/types/index.js.map +7 -0
  63. package/dist/utils/betterAjvErrors/helpers.js +88 -93
  64. package/dist/utils/betterAjvErrors/helpers.js.map +7 -0
  65. package/dist/utils/betterAjvErrors/index.js +14 -13
  66. package/dist/utils/betterAjvErrors/index.js.map +7 -0
  67. package/dist/utils/betterAjvErrors/json/get-meta-from-path.d.ts +2 -0
  68. package/dist/utils/betterAjvErrors/json/get-meta-from-path.d.ts.map +1 -0
  69. package/dist/utils/betterAjvErrors/json/get-meta-from-path.js +27 -0
  70. package/dist/utils/betterAjvErrors/json/get-meta-from-path.js.map +7 -0
  71. package/dist/utils/betterAjvErrors/json/index.d.ts +2 -0
  72. package/dist/utils/betterAjvErrors/json/index.d.ts.map +1 -0
  73. package/dist/utils/betterAjvErrors/json/index.js +5 -0
  74. package/dist/utils/betterAjvErrors/json/index.js.map +7 -0
  75. package/dist/utils/betterAjvErrors/json/utils.d.ts +2 -0
  76. package/dist/utils/betterAjvErrors/json/utils.d.ts.map +1 -0
  77. package/dist/utils/betterAjvErrors/json/utils.js +11 -0
  78. package/dist/utils/betterAjvErrors/json/utils.js.map +7 -0
  79. package/dist/utils/betterAjvErrors/utils.js +21 -14
  80. package/dist/utils/betterAjvErrors/utils.js.map +7 -0
  81. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts +10 -0
  82. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.d.ts.map +1 -0
  83. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js +8 -9
  84. package/dist/utils/betterAjvErrors/validation-errors/additional-prop.js.map +7 -0
  85. package/dist/utils/betterAjvErrors/validation-errors/base.d.ts +23 -0
  86. package/dist/utils/betterAjvErrors/validation-errors/base.d.ts.map +1 -0
  87. package/dist/utils/betterAjvErrors/validation-errors/base.js +6 -10
  88. package/dist/utils/betterAjvErrors/validation-errors/base.js.map +7 -0
  89. package/dist/utils/betterAjvErrors/validation-errors/default.d.ts +10 -0
  90. package/dist/utils/betterAjvErrors/validation-errors/default.d.ts.map +1 -0
  91. package/dist/utils/betterAjvErrors/validation-errors/default.js +8 -9
  92. package/dist/utils/betterAjvErrors/validation-errors/default.js.map +7 -0
  93. package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts +11 -0
  94. package/dist/utils/betterAjvErrors/validation-errors/enum.d.ts.map +1 -0
  95. package/dist/utils/betterAjvErrors/validation-errors/enum.js +19 -29
  96. package/dist/utils/betterAjvErrors/validation-errors/enum.js.map +7 -0
  97. package/dist/utils/betterAjvErrors/validation-errors/index.d.ts +7 -0
  98. package/dist/utils/betterAjvErrors/validation-errors/index.d.ts.map +1 -0
  99. package/dist/utils/betterAjvErrors/validation-errors/index.js +15 -0
  100. package/dist/utils/betterAjvErrors/validation-errors/index.js.map +7 -0
  101. package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts +10 -0
  102. package/dist/utils/betterAjvErrors/validation-errors/pattern.d.ts.map +1 -0
  103. package/dist/utils/betterAjvErrors/validation-errors/pattern.js +8 -9
  104. package/dist/utils/betterAjvErrors/validation-errors/pattern.js.map +7 -0
  105. package/dist/utils/betterAjvErrors/validation-errors/required.d.ts +10 -0
  106. package/dist/utils/betterAjvErrors/validation-errors/required.d.ts.map +1 -0
  107. package/dist/utils/betterAjvErrors/validation-errors/required.js +8 -9
  108. package/dist/utils/betterAjvErrors/validation-errors/required.js.map +7 -0
  109. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts +10 -0
  110. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.d.ts.map +1 -0
  111. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js +8 -9
  112. package/dist/utils/betterAjvErrors/validation-errors/unevaluated-prop.js.map +7 -0
  113. package/dist/utils/dereference.d.ts +2 -2
  114. package/dist/utils/dereference.d.ts.map +1 -1
  115. package/dist/utils/dereference.js +17 -19
  116. package/dist/utils/dereference.js.map +7 -0
  117. package/dist/utils/dereference.test.js +300 -0
  118. package/dist/utils/dereference.test.js.map +7 -0
  119. package/dist/utils/details.d.ts +1 -1
  120. package/dist/utils/details.d.ts.map +1 -1
  121. package/dist/utils/details.js +26 -28
  122. package/dist/utils/details.js.map +7 -0
  123. package/dist/utils/errors.test.js +48 -0
  124. package/dist/utils/errors.test.js.map +7 -0
  125. package/dist/utils/escapeJsonPointer.js +5 -8
  126. package/dist/utils/escapeJsonPointer.js.map +7 -0
  127. package/dist/utils/escapeJsonPointer.test.js +11 -0
  128. package/dist/utils/escapeJsonPointer.test.js.map +7 -0
  129. package/dist/utils/filter.d.ts +1 -1
  130. package/dist/utils/filter.d.ts.map +1 -1
  131. package/dist/utils/filter.js +13 -15
  132. package/dist/utils/filter.js.map +7 -0
  133. package/dist/utils/getEntrypoint.d.ts +1 -1
  134. package/dist/utils/getEntrypoint.d.ts.map +1 -1
  135. package/dist/utils/getEntrypoint.js +5 -6
  136. package/dist/utils/getEntrypoint.js.map +7 -0
  137. package/dist/utils/getEntrypoint.test.js +18 -0
  138. package/dist/utils/getEntrypoint.test.js.map +7 -0
  139. package/dist/utils/getListOfReferences.d.ts +1 -1
  140. package/dist/utils/getListOfReferences.d.ts.map +1 -1
  141. package/dist/utils/getListOfReferences.js +15 -22
  142. package/dist/utils/getListOfReferences.js.map +7 -0
  143. package/dist/utils/getSegmentsFromPath.js +8 -15
  144. package/dist/utils/getSegmentsFromPath.js.map +7 -0
  145. package/dist/utils/getSegmentsFromPath.test.js +13 -0
  146. package/dist/utils/getSegmentsFromPath.test.js.map +7 -0
  147. package/dist/utils/index.d.ts +26 -26
  148. package/dist/utils/index.d.ts.map +1 -1
  149. package/dist/utils/index.js +27 -0
  150. package/dist/utils/index.js.map +7 -0
  151. package/dist/utils/isFilesystem.d.ts +1 -2
  152. package/dist/utils/isFilesystem.d.ts.map +1 -1
  153. package/dist/utils/isFilesystem.js +5 -9
  154. package/dist/utils/isFilesystem.js.map +7 -0
  155. package/dist/utils/isJson.js +10 -9
  156. package/dist/utils/isJson.js.map +7 -0
  157. package/dist/utils/isObject.js +5 -6
  158. package/dist/utils/isObject.js.map +7 -0
  159. package/dist/utils/isObject.test.js +23 -0
  160. package/dist/utils/isObject.test.js.map +7 -0
  161. package/dist/utils/isYaml.js +16 -17
  162. package/dist/utils/isYaml.js.map +7 -0
  163. package/dist/utils/load/index.d.ts +1 -1
  164. package/dist/utils/load/index.d.ts.map +1 -1
  165. package/dist/utils/load/index.js +2 -0
  166. package/dist/utils/load/index.js.map +7 -0
  167. package/dist/utils/load/load.d.ts +3 -12
  168. package/dist/utils/load/load.d.ts.map +1 -1
  169. package/dist/utils/load/load.js +89 -149
  170. package/dist/utils/load/load.js.map +7 -0
  171. package/dist/utils/load/load.test.js +361 -0
  172. package/dist/utils/load/load.test.js.map +7 -0
  173. package/dist/utils/makeFilesystem.d.ts +2 -19
  174. package/dist/utils/makeFilesystem.d.ts.map +1 -1
  175. package/dist/utils/makeFilesystem.js +20 -68
  176. package/dist/utils/makeFilesystem.js.map +7 -0
  177. package/dist/utils/makeFilesystem.test.js +15 -0
  178. package/dist/utils/makeFilesystem.test.js.map +7 -0
  179. package/dist/utils/normalize.d.ts +1 -1
  180. package/dist/utils/normalize.d.ts.map +1 -1
  181. package/dist/utils/normalize.js +22 -27
  182. package/dist/utils/normalize.js.map +7 -0
  183. package/dist/utils/normalize.test.js +88 -0
  184. package/dist/utils/normalize.test.js.map +7 -0
  185. package/dist/utils/openapi/actions/details.d.ts +2 -2
  186. package/dist/utils/openapi/actions/details.d.ts.map +1 -1
  187. package/dist/utils/openapi/actions/details.js +9 -11
  188. package/dist/utils/openapi/actions/details.js.map +7 -0
  189. package/dist/utils/openapi/actions/files.d.ts +1 -1
  190. package/dist/utils/openapi/actions/files.d.ts.map +1 -1
  191. package/dist/utils/openapi/actions/files.js +7 -9
  192. package/dist/utils/openapi/actions/files.js.map +7 -0
  193. package/dist/utils/openapi/actions/get.d.ts +1 -1
  194. package/dist/utils/openapi/actions/get.d.ts.map +1 -1
  195. package/dist/utils/openapi/actions/get.js +9 -11
  196. package/dist/utils/openapi/actions/get.js.map +7 -0
  197. package/dist/utils/openapi/actions/toJson.d.ts +1 -1
  198. package/dist/utils/openapi/actions/toJson.d.ts.map +1 -1
  199. package/dist/utils/openapi/actions/toJson.js +9 -11
  200. package/dist/utils/openapi/actions/toJson.js.map +7 -0
  201. package/dist/utils/openapi/actions/toYaml.d.ts +1 -1
  202. package/dist/utils/openapi/actions/toYaml.d.ts.map +1 -1
  203. package/dist/utils/openapi/actions/toYaml.js +9 -11
  204. package/dist/utils/openapi/actions/toYaml.js.map +7 -0
  205. package/dist/utils/openapi/commands/dereferenceCommand.d.ts +5 -5
  206. package/dist/utils/openapi/commands/dereferenceCommand.d.ts.map +1 -1
  207. package/dist/utils/openapi/commands/dereferenceCommand.js +25 -27
  208. package/dist/utils/openapi/commands/dereferenceCommand.js.map +7 -0
  209. package/dist/utils/openapi/commands/filterCommand.d.ts +9 -9
  210. package/dist/utils/openapi/commands/filterCommand.d.ts.map +1 -1
  211. package/dist/utils/openapi/commands/filterCommand.js +24 -26
  212. package/dist/utils/openapi/commands/filterCommand.js.map +7 -0
  213. package/dist/utils/openapi/commands/loadCommand.d.ts +1174 -1174
  214. package/dist/utils/openapi/commands/loadCommand.d.ts.map +1 -1
  215. package/dist/utils/openapi/commands/loadCommand.js +40 -42
  216. package/dist/utils/openapi/commands/loadCommand.js.map +7 -0
  217. package/dist/utils/openapi/commands/upgradeCommand.d.ts +311 -311
  218. package/dist/utils/openapi/commands/upgradeCommand.d.ts.map +1 -1
  219. package/dist/utils/openapi/commands/upgradeCommand.js +27 -29
  220. package/dist/utils/openapi/commands/upgradeCommand.js.map +7 -0
  221. package/dist/utils/openapi/commands/validateCommand.d.ts +311 -311
  222. package/dist/utils/openapi/commands/validateCommand.d.ts.map +1 -1
  223. package/dist/utils/openapi/commands/validateCommand.js +31 -33
  224. package/dist/utils/openapi/commands/validateCommand.js.map +7 -0
  225. package/dist/utils/openapi/index.d.ts +1 -1
  226. package/dist/utils/openapi/index.d.ts.map +1 -1
  227. package/dist/utils/openapi/index.js +2 -0
  228. package/dist/utils/openapi/index.js.map +7 -0
  229. package/dist/utils/openapi/openapi.d.ts +700 -700
  230. package/dist/utils/openapi/openapi.d.ts.map +1 -1
  231. package/dist/utils/openapi/openapi.js +13 -16
  232. package/dist/utils/openapi/openapi.js.map +7 -0
  233. package/dist/utils/openapi/openapi.test-d.js +14 -0
  234. package/dist/utils/openapi/openapi.test-d.js.map +7 -0
  235. package/dist/utils/openapi/openapi.test.js +309 -0
  236. package/dist/utils/openapi/openapi.test.js.map +7 -0
  237. package/dist/utils/openapi/utils/queueTask.d.ts +1 -1
  238. package/dist/utils/openapi/utils/queueTask.d.ts.map +1 -1
  239. package/dist/utils/openapi/utils/queueTask.js +8 -9
  240. package/dist/utils/openapi/utils/queueTask.js.map +7 -0
  241. package/dist/utils/openapi/utils/workThroughQueue.d.ts +1 -1
  242. package/dist/utils/openapi/utils/workThroughQueue.d.ts.map +1 -1
  243. package/dist/utils/openapi/utils/workThroughQueue.js +49 -64
  244. package/dist/utils/openapi/utils/workThroughQueue.js.map +7 -0
  245. package/dist/utils/openapi/utils/workThroughQueue.test.js +244 -0
  246. package/dist/utils/openapi/utils/workThroughQueue.test.js.map +7 -0
  247. package/dist/utils/resolveReferences.d.ts +1 -7
  248. package/dist/utils/resolveReferences.d.ts.map +1 -1
  249. package/dist/utils/resolveReferences.js +91 -149
  250. package/dist/utils/resolveReferences.js.map +7 -0
  251. package/dist/utils/resolveReferences.test.js +567 -0
  252. package/dist/utils/resolveReferences.test.js.map +7 -0
  253. package/dist/utils/toJson.d.ts +1 -1
  254. package/dist/utils/toJson.d.ts.map +1 -1
  255. package/dist/utils/toJson.js +4 -2
  256. package/dist/utils/toJson.js.map +7 -0
  257. package/dist/utils/toYaml.d.ts +1 -1
  258. package/dist/utils/toYaml.d.ts.map +1 -1
  259. package/dist/utils/toYaml.js +5 -4
  260. package/dist/utils/toYaml.js.map +7 -0
  261. package/dist/utils/transform/index.d.ts +1 -1
  262. package/dist/utils/transform/index.d.ts.map +1 -1
  263. package/dist/utils/transform/index.js +2 -0
  264. package/dist/utils/transform/index.js.map +7 -0
  265. package/dist/utils/transform/sanitize.d.ts +3 -3
  266. package/dist/utils/transform/sanitize.d.ts.map +1 -1
  267. package/dist/utils/transform/sanitize.js +22 -21
  268. package/dist/utils/transform/sanitize.js.map +7 -0
  269. package/dist/utils/transform/sanitize.test.js +148 -0
  270. package/dist/utils/transform/sanitize.test.js.map +7 -0
  271. package/dist/utils/transform/utils/addInfoObject.d.ts +1 -1
  272. package/dist/utils/transform/utils/addInfoObject.d.ts.map +1 -1
  273. package/dist/utils/transform/utils/addInfoObject.js +14 -10
  274. package/dist/utils/transform/utils/addInfoObject.js.map +7 -0
  275. package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts +1 -1
  276. package/dist/utils/transform/utils/addLatestOpenApiVersion.d.ts.map +1 -1
  277. package/dist/utils/transform/utils/addLatestOpenApiVersion.js +8 -5
  278. package/dist/utils/transform/utils/addLatestOpenApiVersion.js.map +7 -0
  279. package/dist/utils/transform/utils/addMissingTags.d.ts +1 -1
  280. package/dist/utils/transform/utils/addMissingTags.d.ts.map +1 -1
  281. package/dist/utils/transform/utils/addMissingTags.js +26 -27
  282. package/dist/utils/transform/utils/addMissingTags.js.map +7 -0
  283. package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts +1 -1
  284. package/dist/utils/transform/utils/normalizeSecuritySchemes.d.ts.map +1 -1
  285. package/dist/utils/transform/utils/normalizeSecuritySchemes.js +36 -40
  286. package/dist/utils/transform/utils/normalizeSecuritySchemes.js.map +7 -0
  287. package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts +1 -1
  288. package/dist/utils/transform/utils/rejectSwaggerDocuments.d.ts.map +1 -1
  289. package/dist/utils/transform/utils/rejectSwaggerDocuments.js +8 -6
  290. package/dist/utils/transform/utils/rejectSwaggerDocuments.js.map +7 -0
  291. package/dist/utils/transformErrors.d.ts +1 -1
  292. package/dist/utils/transformErrors.d.ts.map +1 -1
  293. package/dist/utils/transformErrors.js +18 -21
  294. package/dist/utils/transformErrors.js.map +7 -0
  295. package/dist/utils/transformErrors.test.js +17 -0
  296. package/dist/utils/transformErrors.test.js.map +7 -0
  297. package/dist/utils/traverse.d.ts +1 -1
  298. package/dist/utils/traverse.d.ts.map +1 -1
  299. package/dist/utils/traverse.js +19 -22
  300. package/dist/utils/traverse.js.map +7 -0
  301. package/dist/utils/traverse.test.js +68 -0
  302. package/dist/utils/traverse.test.js.map +7 -0
  303. package/dist/utils/unescapeJsonPointer.js +5 -9
  304. package/dist/utils/unescapeJsonPointer.js.map +7 -0
  305. package/dist/utils/unescapeJsonPointer.test.js +19 -0
  306. package/dist/utils/unescapeJsonPointer.test.js.map +7 -0
  307. package/dist/utils/upgrade.d.ts +1 -1
  308. package/dist/utils/upgrade.d.ts.map +1 -1
  309. package/dist/utils/upgrade.js +22 -22
  310. package/dist/utils/upgrade.js.map +7 -0
  311. package/dist/utils/upgrade.test-d.js +16 -0
  312. package/dist/utils/upgrade.test-d.js.map +7 -0
  313. package/dist/utils/upgrade.test.js +57 -0
  314. package/dist/utils/upgrade.test.js.map +7 -0
  315. package/dist/utils/upgradeFromThreeToThreeOne.js +114 -140
  316. package/dist/utils/upgradeFromThreeToThreeOne.js.map +7 -0
  317. package/dist/utils/upgradeFromThreeToThreeOne.test.js +462 -0
  318. package/dist/utils/upgradeFromThreeToThreeOne.test.js.map +7 -0
  319. package/dist/utils/upgradeFromTwoToThree.js +212 -219
  320. package/dist/utils/upgradeFromTwoToThree.js.map +7 -0
  321. package/dist/utils/upgradeFromTwoToThree.test.js +589 -0
  322. package/dist/utils/upgradeFromTwoToThree.test.js.map +7 -0
  323. package/dist/utils/validate.d.ts +1 -1
  324. package/dist/utils/validate.d.ts.map +1 -1
  325. package/dist/utils/validate.js +14 -16
  326. package/dist/utils/validate.js.map +7 -0
  327. package/dist/utils/validate.test.js +64 -0
  328. package/dist/utils/validate.test.js.map +7 -0
  329. package/package.json +6 -8
  330. package/dist/schemas/v2.0/schema.json.js +0 -1623
  331. package/dist/schemas/v3.0/schema.json.js +0 -1673
  332. package/dist/schemas/v3.1/schema.json.js +0 -1451
@@ -0,0 +1,244 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { workThroughQueue } from "./workThroughQueue.js";
3
+ describe("workThroughQueue", () => {
4
+ it("loads a specification", async () => {
5
+ const result = workThroughQueue({
6
+ input: {
7
+ openapi: "3.1.0",
8
+ info: {
9
+ title: "Hello World",
10
+ version: "1.0.0"
11
+ },
12
+ paths: {}
13
+ },
14
+ specification: {
15
+ openapi: "3.1.1",
16
+ info: {
17
+ title: "Hello World",
18
+ version: "1.0.0"
19
+ },
20
+ paths: {}
21
+ },
22
+ tasks: [
23
+ {
24
+ name: "load"
25
+ }
26
+ ]
27
+ });
28
+ expect(await result).toStrictEqual({
29
+ errors: [],
30
+ specification: {
31
+ info: {
32
+ title: "Hello World",
33
+ version: "1.0.0"
34
+ },
35
+ openapi: "3.1.0",
36
+ paths: {}
37
+ },
38
+ filesystem: [
39
+ {
40
+ dir: "./",
41
+ filename: null,
42
+ isEntrypoint: true,
43
+ references: [],
44
+ specification: {
45
+ info: {
46
+ title: "Hello World",
47
+ version: "1.0.0"
48
+ },
49
+ openapi: "3.1.0",
50
+ paths: {}
51
+ }
52
+ }
53
+ ]
54
+ });
55
+ });
56
+ it("validates a specification", async () => {
57
+ const result = workThroughQueue({
58
+ input: {
59
+ openapi: "3.1.0",
60
+ info: {
61
+ title: "Hello World",
62
+ version: "1.0.0"
63
+ },
64
+ paths: {}
65
+ },
66
+ specification: {
67
+ openapi: "3.1.0",
68
+ info: {
69
+ title: "Hello World",
70
+ version: "1.0.0"
71
+ },
72
+ paths: {}
73
+ },
74
+ tasks: [
75
+ {
76
+ name: "load"
77
+ },
78
+ {
79
+ name: "validate"
80
+ }
81
+ ]
82
+ });
83
+ expect(await result).toStrictEqual({
84
+ errors: [],
85
+ valid: true,
86
+ version: "3.1",
87
+ filesystem: [
88
+ {
89
+ dir: "./",
90
+ filename: null,
91
+ isEntrypoint: true,
92
+ references: [],
93
+ specification: {
94
+ info: {
95
+ title: "Hello World",
96
+ version: "1.0.0"
97
+ },
98
+ openapi: "3.1.0",
99
+ paths: {}
100
+ }
101
+ }
102
+ ],
103
+ specification: {
104
+ openapi: "3.1.0",
105
+ info: {
106
+ title: "Hello World",
107
+ version: "1.0.0"
108
+ },
109
+ paths: {}
110
+ },
111
+ schema: {
112
+ info: {
113
+ title: "Hello World",
114
+ version: "1.0.0"
115
+ },
116
+ openapi: "3.1.0",
117
+ paths: {}
118
+ }
119
+ });
120
+ });
121
+ it("dereferences a specification", async () => {
122
+ const result = workThroughQueue({
123
+ input: {
124
+ openapi: "3.1.0",
125
+ info: {
126
+ title: "Hello World",
127
+ version: "1.0.0"
128
+ },
129
+ paths: {}
130
+ },
131
+ specification: {
132
+ openapi: "3.1.0",
133
+ info: {
134
+ title: "Hello World",
135
+ version: "1.0.0"
136
+ },
137
+ paths: {}
138
+ },
139
+ tasks: [
140
+ {
141
+ name: "load"
142
+ },
143
+ {
144
+ name: "dereference"
145
+ }
146
+ ]
147
+ });
148
+ expect(await result).toStrictEqual({
149
+ errors: [],
150
+ specificationType: "openapi",
151
+ specificationVersion: "3.1.0",
152
+ version: "3.1",
153
+ filesystem: [
154
+ {
155
+ dir: "./",
156
+ filename: null,
157
+ isEntrypoint: true,
158
+ references: [],
159
+ specification: {
160
+ info: {
161
+ title: "Hello World",
162
+ version: "1.0.0"
163
+ },
164
+ openapi: "3.1.0",
165
+ paths: {}
166
+ }
167
+ }
168
+ ],
169
+ specification: {
170
+ openapi: "3.1.0",
171
+ info: {
172
+ title: "Hello World",
173
+ version: "1.0.0"
174
+ },
175
+ paths: {}
176
+ },
177
+ schema: {
178
+ info: {
179
+ title: "Hello World",
180
+ version: "1.0.0"
181
+ },
182
+ openapi: "3.1.0",
183
+ paths: {}
184
+ }
185
+ });
186
+ });
187
+ it("upgrades a specification", async () => {
188
+ const result = workThroughQueue({
189
+ input: {
190
+ openapi: "3.0.0",
191
+ info: {
192
+ title: "Hello World",
193
+ version: "1.0.0"
194
+ },
195
+ paths: {}
196
+ },
197
+ specification: {
198
+ openapi: "3.0.0",
199
+ info: {
200
+ title: "Hello World",
201
+ version: "1.0.0"
202
+ },
203
+ paths: {}
204
+ },
205
+ tasks: [
206
+ {
207
+ name: "load"
208
+ },
209
+ {
210
+ name: "upgrade"
211
+ }
212
+ ]
213
+ });
214
+ expect(await result).toStrictEqual({
215
+ errors: [],
216
+ version: "3.1",
217
+ specification: {
218
+ openapi: "3.1.1",
219
+ info: {
220
+ title: "Hello World",
221
+ version: "1.0.0"
222
+ },
223
+ paths: {}
224
+ },
225
+ filesystem: [
226
+ {
227
+ dir: "./",
228
+ filename: null,
229
+ isEntrypoint: true,
230
+ references: [],
231
+ specification: {
232
+ info: {
233
+ title: "Hello World",
234
+ version: "1.0.0"
235
+ },
236
+ openapi: "3.1.1",
237
+ paths: {}
238
+ }
239
+ }
240
+ ]
241
+ });
242
+ });
243
+ });
244
+ //# sourceMappingURL=workThroughQueue.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/utils/openapi/utils/workThroughQueue.test.ts"],
4
+ "sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { workThroughQueue } from './workThroughQueue'\n\ndescribe('workThroughQueue', () => {\n it('loads a specification', async () => {\n const result = workThroughQueue({\n input: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n specification: {\n openapi: '3.1.1',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n tasks: [\n {\n name: 'load',\n },\n ],\n })\n\n expect(await result).toStrictEqual({\n errors: [],\n specification: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n filesystem: [\n {\n dir: './',\n filename: null,\n isEntrypoint: true,\n references: [],\n specification: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n },\n ],\n })\n })\n\n it('validates a specification', async () => {\n const result = workThroughQueue({\n input: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n specification: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n tasks: [\n {\n name: 'load',\n },\n {\n name: 'validate',\n },\n ],\n })\n\n expect(await result).toStrictEqual({\n errors: [],\n valid: true,\n version: '3.1',\n filesystem: [\n {\n dir: './',\n filename: null,\n isEntrypoint: true,\n references: [],\n specification: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n },\n ],\n specification: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n schema: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n })\n })\n\n it('dereferences a specification', async () => {\n const result = workThroughQueue({\n input: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n specification: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n tasks: [\n {\n name: 'load',\n },\n {\n name: 'dereference',\n },\n ],\n })\n\n expect(await result).toStrictEqual({\n errors: [],\n specificationType: 'openapi',\n specificationVersion: '3.1.0',\n version: '3.1',\n filesystem: [\n {\n dir: './',\n filename: null,\n isEntrypoint: true,\n references: [],\n specification: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n },\n ],\n specification: {\n openapi: '3.1.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n schema: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.0',\n paths: {},\n },\n })\n })\n\n it('upgrades a specification', async () => {\n const result = workThroughQueue({\n input: {\n openapi: '3.0.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n specification: {\n openapi: '3.0.0',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n tasks: [\n {\n name: 'load',\n },\n {\n name: 'upgrade',\n },\n ],\n })\n\n expect(await result).toStrictEqual({\n errors: [],\n version: '3.1',\n specification: {\n openapi: '3.1.1',\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n paths: {},\n },\n filesystem: [\n {\n dir: './',\n filename: null,\n isEntrypoint: true,\n references: [],\n specification: {\n info: {\n title: 'Hello World',\n version: '1.0.0',\n },\n openapi: '3.1.1',\n paths: {},\n },\n },\n ],\n })\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB,MAAM;AACjC,KAAG,yBAAyB,YAAY;AACtC,UAAM,SAAS,iBAAiB;AAAA,MAC9B,OAAO;AAAA,QACL,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,QACA,OAAO,CAAC;AAAA,MACV;AAAA,MACA,eAAe;AAAA,QACb,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,QACA,OAAO,CAAC;AAAA,MACV;AAAA,MACA,OAAO;AAAA,QACL;AAAA,UACE,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO,MAAM,MAAM,EAAE,cAAc;AAAA,MACjC,QAAQ,CAAC;AAAA,MACT,eAAe;AAAA,QACb,MAAM;AAAA,UACJ,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,QACA,SAAS;AAAA,QACT,OAAO,CAAC;AAAA,MACV;AAAA,MACA,YAAY;AAAA,QACV;AAAA,UACE,KAAK;AAAA,UACL,UAAU;AAAA,UACV,cAAc;AAAA,UACd,YAAY,CAAC;AAAA,UACb,eAAe;AAAA,YACb,MAAM;AAAA,cACJ,OAAO;AAAA,cACP,SAAS;AAAA,YACX;AAAA,YACA,SAAS;AAAA,YACT,OAAO,CAAC;AAAA,UACV;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAED,KAAG,6BAA6B,YAAY;AAC1C,UAAM,SAAS,iBAAiB;AAAA,MAC9B,OAAO;AAAA,QACL,SAAS;A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,QACA;AAAA,UACE,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF,CAAC;AAED,WAAO,MAAM,MAAM,EAAE,cAAc;AAAA,MACjC,QAAQ,CAAC;AAAA,MACT,SAAS;AAAA,MACT,eAAe;AAAA,QACb,SAAS;AAAA,QACT,MAAM;AAAA,UACJ,OAAO;AAAA,UACP,SAAS;AAAA,QACX;AAAA,QACA,OAAO,CAAC;AAAA,MACV;AAAA,MACA,YAAY;AAAA,QACV;AAAA,UACE,KAAK;AAAA,UACL,UAAU;AAAA,UACV,cAAc;AAAA,UACd,YAAY,CAAC;AAAA,UACb,eAAe;AAAA,YACb,MAAM;AAAA,cACJ,OAAO;AAAA,cACP,SAAS;AAAA,YACX;AAAA,YACA,SAAS;AAAA,YACT,OAAO,CAAC;AAAA,UACV;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -1,5 +1,5 @@
1
1
  import type { OpenAPI } from '@scalar/openapi-types';
2
- import type { AnyObject, ErrorObject, Filesystem, FilesystemEntry, ThrowOnErrorOption } from '../types/index.ts';
2
+ import type { AnyObject, ErrorObject, Filesystem, FilesystemEntry, ThrowOnErrorOption } from '../types/index.js';
3
3
  export type ResolveReferencesResult = {
4
4
  valid: boolean;
5
5
  errors: ErrorObject[];
@@ -15,12 +15,6 @@ export type ResolveReferencesOptions = ThrowOnErrorOption & {
15
15
  schema: AnyObject;
16
16
  ref: string;
17
17
  }) => void;
18
- /**
19
- * Whether to resolve internal references.
20
- *
21
- * @default true
22
- */
23
- resolveInternalRefs?: boolean;
24
18
  };
25
19
  /**
26
20
  * Takes a specification and resolves all references.
@@ -1 +1 @@
1
- {"version":3,"file":"resolveReferences.d.ts","sourceRoot":"","sources":["../../src/utils/resolveReferences.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAGpD,OAAO,KAAK,EAAE,SAAS,E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CAAA;KAAE,KAAK,IAAI,CAAA;CACnE,CAAA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAE/B,KAAK,EAAE,SAAS,GAAG,UAAU,EAE7B,OAAO,CAAC,EAAE,wBAAwB,EAElC,IAAI,CAAC,EAAE,eAAe,EAEtB,MAAM,GAAE,WAAW,EAAO,GACzB,uBAAuB,CA0BzB"}
@@ -1,160 +1,102 @@
1
- import { ERRORS } from '../configuration/index.js';
2
- import { getEntrypoint } from './getEntrypoint.js';
3
- import { getSegmentsFromPath } from './getSegmentsFromPath.js';
4
- import { makeFilesystem } from './makeFilesystem.js';
5
-
6
- /**
7
- * Takes a specification and resolves all references.
8
- */
9
- function resolveReferences(
10
- // Just a specification, or a set of files.
11
- input,
12
- // Additional options to control the behaviour
13
- options,
14
- // Fallback to the entrypoint
15
- file,
16
- // Errors that occurred during the process
17
- errors = []) {
18
- // Detach from input
19
- const clonedInput = structuredClone(input);
20
- // Make it a filesystem, even if it’s just one file
21
- const filesystem = makeFilesystem(clonedInput);
22
- // Get the main file
23
- const entrypoint = getEntrypoint(filesystem);
24
- const finalInput = file?.content ?? entrypoint.content;
25
- // Recursively resolve all references
26
- dereference(finalInput, filesystem, file ?? entrypoint, new WeakSet(), errors, options);
27
- // Remove duplicats (according to message) from errors
28
- errors = errors.filter((error, index, self) => index === self.findIndex((t) => t.message === error.message && t.code === error.code));
29
- // Return the resolved specification
30
- return {
31
- valid: errors.length === 0,
32
- errors,
33
- schema: finalInput,
34
- };
1
+ import { ERRORS } from "../configuration/index.js";
2
+ import { getEntrypoint } from "./getEntrypoint.js";
3
+ import { getSegmentsFromPath } from "./getSegmentsFromPath.js";
4
+ import { makeFilesystem } from "./makeFilesystem.js";
5
+ function resolveReferences(input, options, file, errors = []) {
6
+ const clonedInput = structuredClone(input);
7
+ const filesystem = makeFilesystem(clonedInput);
8
+ const entrypoint = getEntrypoint(filesystem);
9
+ const finalInput = file?.specification ?? entrypoint.specification;
10
+ dereference(finalInput, filesystem, file ?? entrypoint, /* @__PURE__ */ new WeakSet(), errors, options);
11
+ errors = errors.filter(
12
+ (error, index, self) => index === self.findIndex((t) => t.message === error.message && t.code === error.code)
13
+ );
14
+ return {
15
+ valid: errors.length === 0,
16
+ errors,
17
+ schema: finalInput
18
+ };
35
19
  }
36
- /**
37
- * Resolves the circular reference to an object and deletes the $ref properties (in-place).
38
- */
39
- function dereference(schema, filesystem, entrypoint,
40
- // references to resolved object
41
- resolvedSchemas,
42
- // error output
43
- errors, options) {
44
- if (schema === null || resolvedSchemas.has(schema)) {
45
- return;
20
+ function dereference(schema, filesystem, entrypoint, resolvedSchemas, errors, options) {
21
+ if (schema === null || resolvedSchemas.has(schema)) {
22
+ return;
23
+ }
24
+ resolvedSchemas.add(schema);
25
+ function resolveExternal(externalFile) {
26
+ dereference(externalFile.specification, filesystem, externalFile, resolvedSchemas, errors, options);
27
+ return externalFile;
28
+ }
29
+ while (schema.$ref !== void 0) {
30
+ const resolved = resolveUri(schema.$ref, options, entrypoint, filesystem, resolveExternal, errors);
31
+ if (typeof resolved !== "object" || resolved === null) {
32
+ break;
46
33
  }
47
- resolvedSchemas.add(schema);
48
- function resolveExternal(externalFile) {
49
- dereference(externalFile.content, filesystem, externalFile, resolvedSchemas, errors, options);
50
- return externalFile;
34
+ const dereferencedRef = schema.$ref;
35
+ delete schema.$ref;
36
+ for (const key of Object.keys(resolved)) {
37
+ if (schema[key] === void 0) {
38
+ schema[key] = resolved[key];
39
+ }
51
40
  }
52
- // Skip internal reference resolution if resolveInternalRefs is false
53
- const skipReference =
54
- // Only if the option is set …
55
- options?.resolveInternalRefs === false &&
56
- // and it’s obviously internal
57
- schema.$ref?.startsWith('#');
58
- if (skipReference) {
59
- return;
41
+ if (dereferencedRef) {
42
+ options?.onDereference?.({ schema, ref: dereferencedRef });
60
43
  }
61
- while (schema.$ref !== undefined) {
62
- // Find the referenced content
63
- const resolved = resolveUri(schema.$ref, options, entrypoint, filesystem, resolveExternal, errors);
64
- // invalid
65
- if (typeof resolved !== 'object' || resolved === null) {
66
- break;
67
- }
68
- const dereferencedRef = schema.$ref;
69
- // Get rid of the reference
70
- delete schema.$ref;
71
- for (const key of Object.keys(resolved)) {
72
- if (schema[key] === undefined) {
73
- schema[key] = resolved[key];
74
- }
75
- }
76
- if (dereferencedRef) {
77
- options?.onDereference?.({ schema, ref: dereferencedRef });
78
- }
79
- }
80
- // Iterate over the whole object
81
- for (const value of Object.values(schema)) {
82
- if (typeof value === 'object' && value !== null) {
83
- dereference(value, filesystem, entrypoint, resolvedSchemas, errors, options);
84
- }
44
+ }
45
+ for (const value of Object.values(schema)) {
46
+ if (typeof value === "object" && value !== null) {
47
+ dereference(value, filesystem, entrypoint, resolvedSchemas, errors, options);
85
48
  }
49
+ }
86
50
  }
87
- /**
88
- * Resolves a URI to a part of the specification
89
- *
90
- * The output is not necessarily dereferenced
91
- */
92
- function resolveUri(
93
- // 'foobar.json#/foo/bar'
94
- uri, options,
95
- // { uri: './foobar.json '}
96
- file,
97
- // [ { uri: './foobar.json '} ]
98
- filesystem,
99
- // a function to resolve references in external file
100
- resolve, errors) {
101
- // Ignore invalid URIs
102
- if (typeof uri !== 'string') {
103
- if (options?.throwOnError) {
104
- throw new Error(ERRORS.INVALID_REFERENCE.replace('%s', uri));
105
- }
106
- errors.push({
107
- code: 'INVALID_REFERENCE',
108
- message: ERRORS.INVALID_REFERENCE.replace('%s', uri),
109
- });
110
- return undefined;
51
+ function resolveUri(uri, options, file, filesystem, resolve, errors) {
52
+ if (typeof uri !== "string") {
53
+ if (options?.throwOnError) {
54
+ throw new Error(ERRORS.INVALID_REFERENCE.replace("%s", uri));
111
55
  }
112
- // Understand the URI
113
- const [prefix, path] = uri.split('#', 2);
114
- /** Check whether the file is pointing to itself */
115
- const isDifferentFile = prefix !== file.uri;
116
- // External references
117
- if (prefix && isDifferentFile) {
118
- const absoluteUri = file.references[prefix] ?? prefix;
119
- const externalReference = filesystem.find((entry) => {
120
- return entry.uri && entry.uri === absoluteUri;
121
- });
122
- if (!externalReference) {
123
- if (options?.throwOnError) {
124
- throw new Error(ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', prefix));
125
- }
126
- errors.push({
127
- code: 'EXTERNAL_REFERENCE_NOT_FOUND',
128
- message: ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', prefix),
129
- });
130
- return undefined;
131
- }
132
- // $ref: 'other-file.yaml'
133
- if (path === undefined) {
134
- return externalReference.content;
135
- }
136
- // $ref: 'other-file.yaml#/foo/bar'
137
- // resolve refs first before accessing properties directly
138
- return resolveUri(`#${path}`, options, resolve(externalReference), filesystem, resolve, errors);
56
+ errors.push({
57
+ code: "INVALID_REFERENCE",
58
+ message: ERRORS.INVALID_REFERENCE.replace("%s", uri)
59
+ });
60
+ return void 0;
61
+ }
62
+ const [prefix, path] = uri.split("#", 2);
63
+ const isDifferentFile = prefix !== file.filename;
64
+ if (prefix && isDifferentFile) {
65
+ const externalReference = filesystem.find((entry) => {
66
+ return entry.filename === prefix;
67
+ });
68
+ if (!externalReference) {
69
+ if (options?.throwOnError) {
70
+ throw new Error(ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace("%s", prefix));
71
+ }
72
+ errors.push({
73
+ code: "EXTERNAL_REFERENCE_NOT_FOUND",
74
+ message: ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace("%s", prefix)
75
+ });
76
+ return void 0;
139
77
  }
140
- // Pointers
141
- const segments = getSegmentsFromPath(path);
142
- // Internal references
143
- try {
144
- return segments.reduce((acc, key) => {
145
- return acc[key];
146
- }, file.content);
78
+ if (path === void 0) {
79
+ return externalReference.specification;
147
80
  }
148
- catch (_error) {
149
- if (options?.throwOnError) {
150
- throw new Error(ERRORS.INVALID_REFERENCE.replace('%s', uri));
151
- }
152
- errors.push({
153
- code: 'INVALID_REFERENCE',
154
- message: ERRORS.INVALID_REFERENCE.replace('%s', uri),
155
- });
81
+ return resolveUri(`#${path}`, options, resolve(externalReference), filesystem, resolve, errors);
82
+ }
83
+ const segments = getSegmentsFromPath(path);
84
+ try {
85
+ return segments.reduce((acc, key) => {
86
+ return acc[key];
87
+ }, file.specification);
88
+ } catch (_error) {
89
+ if (options?.throwOnError) {
90
+ throw new Error(ERRORS.INVALID_REFERENCE.replace("%s", uri));
156
91
  }
157
- return undefined;
92
+ errors.push({
93
+ code: "INVALID_REFERENCE",
94
+ message: ERRORS.INVALID_REFERENCE.replace("%s", uri)
95
+ });
96
+ }
97
+ return void 0;
158
98
  }
159
-
160
- export { resolveReferences };
99
+ export {
100
+ resolveReferences
101
+ };
102
+ //# sourceMappingURL=resolveReferences.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/resolveReferences.ts"],
4
+ "sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\n\nimport { ERRORS } from '../configuration/index'\nimport type { AnyObject, ErrorObject, Filesystem, FilesystemEntry, ThrowOnErrorOption } from '../types/index'\nimport { getEntrypoint } from './getEntrypoint'\nimport { getSegmentsFromPath } from './getSegmentsFromPath'\nimport { makeFilesystem } from './makeFilesystem'\n\n// TODO: Add support for all pointer words\n// export const pointerWords = new Set([\n// '$ref',\n// '$id',\n// '$anchor',\n// '$dynamicRef',\n// '$dynamicAnchor',\n// '$schema',\n// ])\n\nexport type ResolveReferencesResult = {\n valid: boolean\n errors: ErrorObject[]\n schema: OpenAPI.Document\n}\n\nexport type ResolveReferencesOptions = ThrowOnErrorOption & {\n /**\n * Fired when dereferenced a schema.\n *\n * Note that for object schemas, its properties may not be dereferenced when the hook is called.\n */\n onDereference?: (data: { schema: AnyObject; ref: string }) => void\n}\n\n/**\n * Takes a specification and resolves all references.\n */\nexport function resolveReferences(\n // Just a specification, or a set of files.\n input: AnyObject | Filesystem,\n // Additional options to control the behaviour\n options?: ResolveReferencesOptions,\n // Fallback to the entrypoint\n file?: FilesystemEntry,\n // Errors that occurred during the process\n errors: ErrorObject[] = [],\n): ResolveReferencesResult {\n // Detach from input\n const clonedInput = structuredClone(input)\n\n // Make it a filesystem, even if it\u2019s just one file\n const filesystem = makeFilesystem(clonedInput)\n\n // Get the main file\n const entrypoint = getEntrypoint(filesystem)\n\n const finalInput = file?.specification ?? entrypoint.specification\n\n // Recursively resolve all references\n dereference(finalInput, filesystem, file ?? entrypoint, new WeakSet(), errors, options)\n\n // Remove duplicats (according to message) from errors\n errors = errors.filter(\n (error, index, self) => index === self.findIndex((t) => t.message === error.message && t.code === error.code),\n )\n\n // Return the resolved specification\n return {\n valid: errors.length === 0,\n errors,\n schema: finalInput as OpenAPI.Document,\n }\n}\n\n/**\n * Resolves the circular reference to an object and deletes the $ref properties (in-place).\n */\nfunction dereference(\n schema: AnyObject,\n filesystem: Filesystem,\n entrypoint: FilesystemEntry,\n // references to resolved object\n resolvedSchemas: WeakSet<object>,\n // error output\n errors: ErrorObject[],\n\n options?: ResolveReferencesOptions,\n): void {\n if (schema === null || resolvedSchemas.has(schema)) {\n return\n }\n resolvedSchemas.add(schema)\n\n function resolveExternal(externalFile: FilesystemEntry) {\n dereference(externalFile.specification, filesystem, externalFile, resolvedSchemas, errors, options)\n\n return externalFile\n }\n\n while (schema.$ref !== undefined) {\n // Find the referenced content\n const resolved = resolveUri(schema.$ref, options, entrypoint, filesystem, resolveExternal, errors)\n\n // invalid\n if (typeof resolved !== 'object' || resolved === null) {\n break\n }\n const dereferencedRef = schema.$ref\n\n // Get rid of the reference\n delete schema.$ref\n\n for (const key of Object.keys(resolved)) {\n if (schema[key] === undefined) {\n schema[key] = resolved[key]\n }\n }\n\n if (dereferencedRef) {\n options?.onDereference?.({ schema, ref: dereferencedRef })\n }\n }\n\n // Iterate over the whole object\n for (const value of Object.values(schema)) {\n if (typeof value === 'object' && value !== null) {\n dereference(value, filesystem, entrypoint, resolvedSchemas, errors, options)\n }\n }\n}\n\n/**\n * Resolves a URI to a part of the specification\n *\n * The output is not necessarily dereferenced\n */\nfunction resolveUri(\n // 'foobar.json#/foo/bar'\n uri: string,\n options: ResolveReferencesOptions,\n // { filename: './foobar.json '}\n file: FilesystemEntry,\n // [ { filename: './foobar.json '} ]\n filesystem: Filesystem,\n\n // a function to resolve references in external file\n resolve: (file: FilesystemEntry) => FilesystemEntry,\n\n errors: ErrorObject[],\n): AnyObject | undefined {\n // Ignore invalid URIs\n if (typeof uri !== 'string') {\n if (options?.throwOnError) {\n throw new Error(ERRORS.INVALID_REFERENCE.replace('%s', uri))\n }\n\n errors.push({\n code: 'INVALID_REFERENCE',\n message: ERRORS.INVALID_REFERENCE.replace('%s', uri),\n })\n\n return undefined\n }\n\n // Understand the URI\n const [prefix, path] = uri.split('#', 2)\n\n /** Check whether the file is pointing to itself */\n const isDifferentFile = prefix !== file.filename\n\n // External references\n if (prefix && isDifferentFile) {\n const externalReference = filesystem.find((entry) => {\n return entry.filename === prefix\n })\n\n if (!externalReference) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', prefix))\n }\n\n errors.push({\n code: 'EXTERNAL_REFERENCE_NOT_FOUND',\n message: ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', prefix),\n })\n\n return undefined\n }\n // $ref: 'other-file.yaml'\n if (path === undefined) {\n return externalReference.specification\n }\n\n // $ref: 'other-file.yaml#/foo/bar'\n // resolve refs first before accessing properties directly\n return resolveUri(`#${path}`, options, resolve(externalReference), filesystem, resolve, errors)\n }\n\n // Pointers\n const segments = getSegmentsFromPath(path)\n\n // Try to find the URI\n try {\n return segments.reduce((acc, key) => {\n return acc[key]\n }, file.specification)\n } catch (_error) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.INVALID_REFERENCE.replace('%s', uri))\n }\n\n errors.push({\n code: 'INVALID_REFERENCE',\n message: ERRORS.INVALID_REFERENCE.replace('%s', uri),\n })\n }\n\n return undefined\n}\n"],
5
+ "mappings": "AAEA,SAAS,cAAc;AAEvB,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,sBA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