@scalar/openapi-parser 0.10.16 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (339) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +0 -27
  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 -1
  22. package/dist/plugins/fetch-urls/fetchUrls.d.ts.map +1 -1
  23. package/dist/plugins/fetch-urls/fetchUrls.js +36 -39
  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 -55
  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 +1 -1
  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 +2 -1
  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 +1 -1
  168. package/dist/utils/load/load.d.ts.map +1 -1
  169. package/dist/utils/load/load.js +89 -110
  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 +1 -1
  174. package/dist/utils/makeFilesystem.d.ts.map +1 -1
  175. package/dist/utils/makeFilesystem.js +20 -22
  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 +994 -994
  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 +702 -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 -1
  248. package/dist/utils/resolveReferences.d.ts.map +1 -1
  249. package/dist/utils/resolveReferences.js +91 -139
  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 +3 -3
  298. package/dist/utils/traverse.d.ts.map +1 -1
  299. package/dist/utils/traverse.js +22 -23
  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.bench.d.ts +2 -0
  308. package/dist/utils/upgrade.bench.d.ts.map +1 -0
  309. package/dist/utils/upgrade.bench.js +31 -0
  310. package/dist/utils/upgrade.bench.js.map +7 -0
  311. package/dist/utils/upgrade.d.ts +1 -1
  312. package/dist/utils/upgrade.d.ts.map +1 -1
  313. package/dist/utils/upgrade.js +28 -22
  314. package/dist/utils/upgrade.js.map +7 -0
  315. package/dist/utils/upgrade.test-d.js +16 -0
  316. package/dist/utils/upgrade.test-d.js.map +7 -0
  317. package/dist/utils/upgrade.test.js +57 -0
  318. package/dist/utils/upgrade.test.js.map +7 -0
  319. package/dist/utils/upgradeFromThreeToThreeOne.d.ts +3 -3
  320. package/dist/utils/upgradeFromThreeToThreeOne.d.ts.map +1 -1
  321. package/dist/utils/upgradeFromThreeToThreeOne.js +107 -144
  322. package/dist/utils/upgradeFromThreeToThreeOne.js.map +7 -0
  323. package/dist/utils/upgradeFromThreeToThreeOne.test.js +462 -0
  324. package/dist/utils/upgradeFromThreeToThreeOne.test.js.map +7 -0
  325. package/dist/utils/upgradeFromTwoToThree.d.ts.map +1 -1
  326. package/dist/utils/upgradeFromTwoToThree.js +212 -219
  327. package/dist/utils/upgradeFromTwoToThree.js.map +7 -0
  328. package/dist/utils/upgradeFromTwoToThree.test.js +589 -0
  329. package/dist/utils/upgradeFromTwoToThree.test.js.map +7 -0
  330. package/dist/utils/validate.d.ts +1 -1
  331. package/dist/utils/validate.d.ts.map +1 -1
  332. package/dist/utils/validate.js +14 -16
  333. package/dist/utils/validate.js.map +7 -0
  334. package/dist/utils/validate.test.js +64 -0
  335. package/dist/utils/validate.test.js.map +7 -0
  336. package/package.json +7 -8
  337. package/dist/schemas/v2.0/schema.json.js +0 -1623
  338. package/dist/schemas/v3.0/schema.json.js +0 -1673
  339. package/dist/schemas/v3.1/schema.json.js +0 -1451
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @scalar/openapi-parser
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 483ca93: chore: require Node 20 (or above)
8
+
9
+ ### Patch Changes
10
+
11
+ - bd602d3: chore: mark pipeline syntax as deprecated
12
+ - 1d1470c: feat: speed up the upgrade utility
13
+
14
+ ## 0.10.17
15
+
16
+ ### Patch Changes
17
+
18
+ - 8c7bad8: chore: move build tooling to esbuild
19
+
3
20
  ## 0.10.16
4
21
 
5
22
  ### Patch Changes
package/README.md CHANGED
@@ -7,14 +7,6 @@
7
7
 
8
8
  Modern OpenAPI parser written in TypeScript with support for OpenAPI 3.1, OpenAPI 3.0 and Swagger 2.0.
9
9
 
10
- ## Goals
11
-
12
- - [x] Written in TypeScript
13
- - [x] Runs in Node.js and in the browser (without any polyfills or configuration)
14
- - [x] Tested with hundreds of real world examples
15
- - [ ] Amazing error output
16
- - [ ] Support for OpenAPI 4.0 👀
17
-
18
10
  ## Installation
19
11
 
20
12
  ```bash
@@ -140,25 +132,6 @@ const result = sanitize({
140
132
  console.log(result)
141
133
  ```
142
134
 
143
- ### Pipeline syntax
144
-
145
- ```ts
146
- import { openapi } from '@scalar/openapi-parser'
147
-
148
- const specification = …
149
-
150
- // New pipeline …
151
- const result = openapi()
152
- // loads the specification …
153
- .load(specification)
154
- // upgrades to OpenAPI 3.1 …
155
- .upgrade()
156
- // removes all internal operations …
157
- .filter((schema) => !schema?.['x-internal'])
158
- // done!
159
- .get()
160
- ```
161
-
162
135
  ### Then/Catch syntax
163
136
 
164
137
  If you’re more the then/catch type of guy, that’s fine:
@@ -1,27 +1,24 @@
1
- import Swagger20 from '../schemas/v2.0/schema.json.js';
2
- import OpenApi30 from '../schemas/v3.0/schema.json.js';
3
- import OpenApi31 from '../schemas/v3.1/schema.json.js';
4
-
5
- /**
6
- * A list of the supported OpenAPI specifications
7
- */
1
+ import Swagger20 from "../schemas/v2.0/schema.js";
2
+ import OpenApi30 from "../schemas/v3.0/schema.js";
3
+ import OpenApi31 from "../schemas/v3.1/schema.js";
8
4
  const OpenApiSpecifications = {
9
- '2.0': Swagger20,
10
- '3.0': OpenApi30,
11
- '3.1': OpenApi31,
5
+ "2.0": Swagger20,
6
+ "3.0": OpenApi30,
7
+ "3.1": OpenApi31
12
8
  };
13
9
  const OpenApiVersions = Object.keys(OpenApiSpecifications);
14
- /**
15
- * List of error messages used in the Validator
16
- */
17
10
  const ERRORS = {
18
- EMPTY_OR_INVALID: 'Can’t find JSON, YAML or filename in data',
19
- // URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string',
20
- OPENAPI_VERSION_NOT_SUPPORTED: 'Can’t find supported Swagger/OpenAPI version in specification, version must be a string.',
21
- INVALID_REFERENCE: 'Can’t resolve reference: %s',
22
- EXTERNAL_REFERENCE_NOT_FOUND: 'Can’t resolve external reference: %s',
23
- FILE_DOES_NOT_EXIST: 'File does not exist: %s',
24
- NO_CONTENT: 'No content found',
11
+ EMPTY_OR_INVALID: "Can\u2019t find JSON, YAML or filename in data",
12
+ // URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string',
13
+ OPENAPI_VERSION_NOT_SUPPORTED: "Can\u2019t find supported Swagger/OpenAPI version in specification, version must be a string.",
14
+ INVALID_REFERENCE: "Can\u2019t resolve reference: %s",
15
+ EXTERNAL_REFERENCE_NOT_FOUND: "Can\u2019t resolve external reference: %s",
16
+ FILE_DOES_NOT_EXIST: "File does not exist: %s",
17
+ NO_CONTENT: "No content found"
25
18
  };
26
-
27
- export { ERRORS, OpenApiSpecifications, OpenApiVersions };
19
+ export {
20
+ ERRORS,
21
+ OpenApiSpecifications,
22
+ OpenApiVersions
23
+ };
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/configuration/index.ts"],
4
+ "sourcesContent": ["import Swagger20 from '../schemas/v2.0/schema'\nimport OpenApi30 from '../schemas/v3.0/schema'\nimport OpenApi31 from '../schemas/v3.1/schema'\n\n/**\n * A list of the supported OpenAPI specifications\n */\nexport const OpenApiSpecifications = {\n '2.0': Swagger20,\n '3.0': OpenApi30,\n '3.1': OpenApi31,\n}\n\nexport type OpenApiVersion = keyof typeof OpenApiSpecifications\n\nexport const OpenApiVersions = Object.keys(OpenApiSpecifications) as OpenApiVersion[]\n\n/**\n * List of error messages used in the Validator\n */\nexport const ERRORS = {\n EMPTY_OR_INVALID: 'Can\u2019t find JSON, YAML or filename in data',\n // URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string',\n OPENAPI_VERSION_NOT_SUPPORTED:\n 'Can\u2019t find supported Swagger/OpenAPI version in specification, version must be a string.',\n INVALID_REFERENCE: 'Can\u2019t resolve reference: %s',\n EXTERNAL_REFERENCE_NOT_FOUND: 'Can\u2019t resolve external reference: %s',\n FILE_DOES_NOT_EXIST: 'File does not exist: %s',\n NO_CONTENT: 'No content found',\n} as const\n\nexport type ValidationError = keyof typeof ERRORS\n"],
5
+ "mappings": "AAAA,OAAO,eAAe;AACtB,OAAO,eAAe;AACtB,OAAO,eAAe;AAKf,MAAM,wBAAwB;AAAA,EACnC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACT;AAIO,MAAM,kBAAkB,OAAO,KAAK,qBAAqB;AAKzD,MAAM,SAAS;AAAA,EACpB,kBAAkB;AAAA;AAAA,EAElB,+BACE;AAAA,EACF,mBAAmB;AAAA,EACnB,8BAA8B;AAAA,EAC9B,qBAAqB;AAAA,EACrB,YAAY;AACd;",
6
+ "names": []
7
+ }
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=declarations.d.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './configuration/index.ts';
2
- export * from './lib/Validator/index.ts';
3
- export * from './types/index.ts';
4
- export * from './utils/index.ts';
1
+ export * from './configuration/index.js';
2
+ export * from './lib/Validator/index.js';
3
+ export * from './types/index.js';
4
+ export * from './utils/index.js';
5
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,0BAA0B,CAAA;AACxC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA"}
package/dist/index.js CHANGED
@@ -1,29 +1,5 @@
1
- export { ERRORS, OpenApiSpecifications, OpenApiVersions } from './configuration/index.js';
2
- export { Validator, jsonSchemaVersions } from './lib/Validator/Validator.js';
3
- export { resolveReferences } from './utils/resolveReferences.js';
4
- export { dereference } from './utils/dereference.js';
5
- export { details } from './utils/details.js';
6
- export { escapeJsonPointer } from './utils/escapeJsonPointer.js';
7
- export { filter } from './utils/filter.js';
8
- export { getEntrypoint } from './utils/getEntrypoint.js';
9
- export { getListOfReferences } from './utils/getListOfReferences.js';
10
- export { getSegmentsFromPath } from './utils/getSegmentsFromPath.js';
11
- export { isFilesystem } from './utils/isFilesystem.js';
12
- export { isJson } from './utils/isJson.js';
13
- export { isObject } from './utils/isObject.js';
14
- export { isYaml } from './utils/isYaml.js';
15
- export { load } from './utils/load/load.js';
16
- export { normalize } from './utils/normalize.js';
17
- export { openapi } from './utils/openapi/openapi.js';
18
- export { toJson } from './utils/toJson.js';
19
- export { toYaml } from './utils/toYaml.js';
20
- export { transformErrors } from './utils/transformErrors.js';
21
- export { traverse } from './utils/traverse.js';
22
- export { unescapeJsonPointer } from './utils/unescapeJsonPointer.js';
23
- export { upgrade } from './utils/upgrade.js';
24
- export { isSchemaPath, upgradeFromThreeToThreeOne } from './utils/upgradeFromThreeToThreeOne.js';
25
- export { upgradeFromTwoToThree } from './utils/upgradeFromTwoToThree.js';
26
- export { validate } from './utils/validate.js';
27
- export { DEFAULT_OPENAPI_VERSION } from './utils/transform/utils/addLatestOpenApiVersion.js';
28
- export { DEFAULT_TITLE, DEFAULT_VERSION } from './utils/transform/utils/addInfoObject.js';
29
- export { sanitize } from './utils/transform/sanitize.js';
1
+ export * from "./configuration/index.js";
2
+ export * from "./lib/Validator/index.js";
3
+ export * from "./types/index.js";
4
+ export * from "./utils/index.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["export * from './configuration/index'\nexport * from './lib/Validator/index'\nexport * from './types/index'\nexport * from './utils/index'\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
6
+ "names": []
7
+ }
@@ -1,7 +1,7 @@
1
1
  import Ajv04 from 'ajv-draft-04';
2
2
  import Ajv2020 from 'ajv/dist/2020.js';
3
- import { type OpenApiVersion } from '../../configuration/index.ts';
4
- import type { AnyObject, Filesystem, ThrowOnErrorOption, ValidateResult } from '../../types/index.ts';
3
+ import { type OpenApiVersion } from '../../configuration/index.js';
4
+ import type { AnyObject, Filesystem, ThrowOnErrorOption, ValidateResult } from '../../types/index.js';
5
5
  /**
6
6
  * Configure available JSON Schema versions
7
7
  */
@@ -1 +1 @@
1
- {"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../src/lib/Validator/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,OAAO,MAAM,kBAAkB,CAAA;AAEtC,OAAO,EAAiC,KAAK,cAAc,EAAmB,MAAM,8BAA8B,CAAA;AAClH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAKrG;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;CAG9B,CAAA;AAED,qBAAa,SAAS;IACb,OAAO,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;IAErC,OAAc,iBAAiB,4BAAkB;IAGjD,SAAS,CAAC,aAAa,EAAE,MAAM,CAC7B,MAAM,EACN,CAAC,CAAC,aAAa,EAAE,SAAS,KAAK,OAAO,CAAC,GAAG;QACxC,MAAM,EAAE,MAAM,CAAA;KACf,CACF,CAAK;IAEN,SAAS,CAAC,MAAM,EAAE,MAAM,CAAA;IAExB,SAAS,CAAC,oBAAoB,EAAE,MAAM,CAAA;IAEtC,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAA;IAE5B,aAAa,EAAE,SAAS,CAAA;IAE/B;;OAEG;IACG,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAoF7F;;OAEG;IACG,eAAe,CAAC,OAAO,EAAE,cAAc;CA+B9C"}
1
+ {"version":3,"file":"Validator.d.ts","sourceRoot":"","sources":["../../../src/lib/Validator/Validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,cAAc,CAAA;AAEhC,OAAO,OAAO,MAAM,kBAAkB,CAAA;AAEtC,OAAO,EAAiC,KAAK,cAAc,EAAmB,MAAM,2BAA2B,CAAA;AAC/G,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAKlG;;GAEG;AACH,eAAO,MAAM,kBAAkB;;;CAG9B,CAAA;AAED,qBAAa,SAAS;IACb,OAAO,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;IAErC,OAAc,iBAAiB,4BAAkB;IAGjD,SAAS,CAAC,aAAa,EAAE,MAAM,CAC7B,MAAM,EACN,CAAC,CAAC,aAAa,EAAE,SAAS,KAAK,OAAO,CAAC,GAAG;QACxC,MAAM,EAAE,MAAM,CAAA;KACf,CACF,CAAK;IAEN,SAAS,CAAC,MAAM,EAAE,MAAM,CAAA;IAExB,SAAS,CAAC,oBAAoB,EAAE,MAAM,CAAA;IAEtC,SAAS,CAAC,iBAAiB,EAAE,MAAM,CAAA;IAE5B,aAAa,EAAE,SAAS,CAAA;IAE/B;;OAEG;IACG,QAAQ,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC;IAoF7F;;OAEG;IACG,eAAe,CAAC,OAAO,EAAE,cAAc;CA8B9C"}
@@ -1,128 +1,108 @@
1
- import Ajv04 from 'ajv-draft-04';
2
- import addFormats from 'ajv-formats';
3
- import Ajv2020 from 'ajv/dist/2020.js';
4
- import { OpenApiVersions, ERRORS, OpenApiSpecifications } from '../../configuration/index.js';
5
- import { details } from '../../utils/details.js';
6
- import { resolveReferences } from '../../utils/resolveReferences.js';
7
- import { transformErrors } from '../../utils/transformErrors.js';
8
-
9
- /**
10
- * Configure available JSON Schema versions
11
- */
1
+ import Ajv04 from "ajv-draft-04";
2
+ import addFormats from "ajv-formats";
3
+ import Ajv2020 from "ajv/dist/2020.js";
4
+ import { ERRORS, OpenApiSpecifications, OpenApiVersions } from "../../configuration/index.js";
5
+ import { details as getOpenApiVersion } from "../../utils/details.js";
6
+ import { resolveReferences } from "../../utils/resolveReferences.js";
7
+ import { transformErrors } from "../../utils/transformErrors.js";
12
8
  const jsonSchemaVersions = {
13
- 'http://json-schema.org/draft-04/schema#': Ajv04,
14
- 'https://json-schema.org/draft/2020-12/schema': Ajv2020,
9
+ "http://json-schema.org/draft-04/schema#": Ajv04,
10
+ "https://json-schema.org/draft/2020-12/schema": Ajv2020
15
11
  };
16
12
  class Validator {
17
- version;
18
- static supportedVersions = OpenApiVersions;
19
- // Object with function *or* object { errors: string }
20
- ajvValidators = {};
21
- errors;
22
- specificationVersion;
23
- specificationType;
24
- specification;
25
- /**
26
- * Checks whether a specification is valid and all references can be resolved.
27
- */
28
- async validate(filesystem, options) {
29
- const entrypoint = filesystem.find((file) => file.isEntrypoint);
30
- const specification = entrypoint?.specification;
31
- // TODO: How does this work with a filesystem?
32
- this.specification = specification;
33
- // TODO: defaulting info.version to keep parser compatible with the previous one
34
- // we should bubble this error up and not throw on it
35
- if (this.specification?.info && !this.specification.info.version) {
36
- this.specification.info.version = '0.0.1';
13
+ version;
14
+ static supportedVersions = OpenApiVersions;
15
+ // Object with function *or* object { errors: string }
16
+ ajvValidators = {};
17
+ errors;
18
+ specificationVersion;
19
+ specificationType;
20
+ specification;
21
+ /**
22
+ * Checks whether a specification is valid and all references can be resolved.
23
+ */
24
+ async validate(filesystem, options) {
25
+ const entrypoint = filesystem.find((file) => file.isEntrypoint);
26
+ const specification = entrypoint?.specification;
27
+ this.specification = specification;
28
+ if (this.specification?.info && !this.specification.info.version) {
29
+ this.specification.info.version = "0.0.1";
30
+ }
31
+ try {
32
+ if (specification === void 0 || specification === null) {
33
+ if (options?.throwOnError) {
34
+ throw new Error(ERRORS.EMPTY_OR_INVALID);
37
35
  }
38
- try {
39
- // AnyObject is empty or invalid
40
- if (specification === undefined || specification === null) {
41
- if (options?.throwOnError) {
42
- throw new Error(ERRORS.EMPTY_OR_INVALID);
43
- }
44
- return {
45
- valid: false,
46
- errors: transformErrors(entrypoint, ERRORS.EMPTY_OR_INVALID),
47
- };
48
- }
49
- // Meta data about the specification
50
- const { version, specificationType, specificationVersion } = details(specification);
51
- this.version = version;
52
- this.specificationVersion = specificationVersion;
53
- this.specificationType = specificationType;
54
- // AnyObject is not supported
55
- if (!version) {
56
- if (options?.throwOnError) {
57
- throw new Error(ERRORS.OPENAPI_VERSION_NOT_SUPPORTED);
58
- }
59
- return {
60
- valid: false,
61
- errors: transformErrors(entrypoint, ERRORS.OPENAPI_VERSION_NOT_SUPPORTED),
62
- };
63
- }
64
- // Get the correct OpenAPI validator
65
- const validateSchema = await this.getAjvValidator(version);
66
- const schemaResult = validateSchema(specification);
67
- // Error handling
68
- if (validateSchema.errors) {
69
- if (validateSchema.errors.length > 0) {
70
- if (options?.throwOnError) {
71
- throw new Error(validateSchema.errors[0]);
72
- }
73
- return {
74
- valid: false,
75
- errors: transformErrors(entrypoint, validateSchema.errors),
76
- };
77
- }
78
- }
79
- // Check if the references are valid
80
- const resolvedReferences = resolveReferences(filesystem, options);
81
- return {
82
- valid: schemaResult && resolvedReferences.valid,
83
- errors: [...(schemaResult.errors ?? []), ...resolvedReferences.errors],
84
- schema: resolvedReferences.schema,
85
- };
36
+ return {
37
+ valid: false,
38
+ errors: transformErrors(entrypoint, ERRORS.EMPTY_OR_INVALID)
39
+ };
40
+ }
41
+ const { version, specificationType, specificationVersion } = getOpenApiVersion(specification);
42
+ this.version = version;
43
+ this.specificationVersion = specificationVersion;
44
+ this.specificationType = specificationType;
45
+ if (!version) {
46
+ if (options?.throwOnError) {
47
+ throw new Error(ERRORS.OPENAPI_VERSION_NOT_SUPPORTED);
86
48
  }
87
- catch (error) {
88
- // Something went horribly wrong!
89
- if (options?.throwOnError) {
90
- throw error;
91
- }
92
- return {
93
- valid: false,
94
- errors: transformErrors(entrypoint, error.message ?? error),
95
- };
49
+ return {
50
+ valid: false,
51
+ errors: transformErrors(entrypoint, ERRORS.OPENAPI_VERSION_NOT_SUPPORTED)
52
+ };
53
+ }
54
+ const validateSchema = await this.getAjvValidator(version);
55
+ const schemaResult = validateSchema(specification);
56
+ if (validateSchema.errors) {
57
+ if (validateSchema.errors.length > 0) {
58
+ if (options?.throwOnError) {
59
+ throw new Error(validateSchema.errors[0]);
60
+ }
61
+ return {
62
+ valid: false,
63
+ errors: transformErrors(entrypoint, validateSchema.errors)
64
+ };
96
65
  }
66
+ }
67
+ const resolvedReferences = resolveReferences(filesystem, options);
68
+ return {
69
+ valid: schemaResult && resolvedReferences.valid,
70
+ errors: [...schemaResult.errors ?? [], ...resolvedReferences.errors],
71
+ schema: resolvedReferences.schema
72
+ };
73
+ } catch (error) {
74
+ if (options?.throwOnError) {
75
+ throw error;
76
+ }
77
+ return {
78
+ valid: false,
79
+ errors: transformErrors(entrypoint, error.message ?? error)
80
+ };
97
81
  }
98
- /**
99
- * Ajv JSON schema validator
100
- */
101
- async getAjvValidator(version) {
102
- // Schema loaded already
103
- if (this.ajvValidators[version]) {
104
- return this.ajvValidators[version];
105
- }
106
- // Load OpenAPI Schema
107
- const schema = OpenApiSpecifications[version];
108
- // Load JSON Schema
109
- const AjvClass = jsonSchemaVersions[schema.$schema];
110
- // Get the correct Ajv validator
111
- const ajv = new AjvClass({
112
- // Ajv is a bit too strict in its strict validation of OpenAPI schemas.
113
- // Switch strict mode off.
114
- strict: false,
115
- });
116
- // Register formats
117
- // https://ajv.js.org/packages/ajv-formats.html#formats
118
- // @ts-expect-error ajv-formats is not well typed
119
- addFormats(ajv);
120
- // OpenAPI 3.1 uses media-range format
121
- if (version === '3.1') {
122
- ajv.addFormat('media-range', true);
123
- }
124
- return (this.ajvValidators[version] = ajv.compile(schema));
82
+ }
83
+ /**
84
+ * Ajv JSON schema validator
85
+ */
86
+ async getAjvValidator(version) {
87
+ if (this.ajvValidators[version]) {
88
+ return this.ajvValidators[version];
125
89
  }
90
+ const schema = OpenApiSpecifications[version];
91
+ const AjvClass = jsonSchemaVersions[schema.$schema];
92
+ const ajv = new AjvClass({
93
+ // Ajv is a bit too strict in its strict validation of OpenAPI schemas.
94
+ // Switch strict mode off.
95
+ strict: false
96
+ });
97
+ addFormats(ajv);
98
+ if (version === "3.1") {
99
+ ajv.addFormat("media-range", true);
100
+ }
101
+ return this.ajvValidators[version] = ajv.compile(schema);
102
+ }
126
103
  }
127
-
128
- export { Validator, jsonSchemaVersions };
104
+ export {
105
+ Validator,
106
+ jsonSchemaVersions
107
+ };
108
+ //# sourceMappingURL=Validator.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/Validator/Validator.ts"],
4
+ "sourcesContent": ["import Ajv04 from 'ajv-draft-04'\nimport addFormats from 'ajv-formats'\nimport Ajv2020 from 'ajv/dist/2020.js'\n\nimport { ERRORS, OpenApiSpecifications, type OpenApiVersion, OpenApiVersions } from '../../configuration/index'\nimport type { AnyObject, Filesystem, ThrowOnErrorOption, ValidateResult } from '../../types/index'\nimport { details as getOpenApiVersion } from '../../utils/details'\nimport { resolveReferences } from '../../utils/resolveReferences'\nimport { transformErrors } from '../../utils/transformErrors'\n\n/**\n * Configure available JSON Schema versions\n */\nexport const jsonSchemaVersions = {\n 'http://json-schema.org/draft-04/schema#': Ajv04,\n 'https://json-schema.org/draft/2020-12/schema': Ajv2020,\n}\n\nexport class Validator {\n public version: '2.0' | '3.0' | '3.1'\n\n public static supportedVersions = OpenApiVersions\n\n // Object with function *or* object { errors: string }\n protected ajvValidators: Record<\n string,\n ((specification: AnyObject) => boolean) & {\n errors: string\n }\n > = {}\n\n protected errors: string\n\n protected specificationVersion: string\n\n protected specificationType: string\n\n public specification: AnyObject\n\n /**\n * Checks whether a specification is valid and all references can be resolved.\n */\n async validate(filesystem: Filesystem, options?: ThrowOnErrorOption): Promise<ValidateResult> {\n const entrypoint = filesystem.find((file) => file.isEntrypoint)\n const specification = entrypoint?.specification\n\n // TODO: How does this work with a filesystem?\n this.specification = specification\n\n // TODO: defaulting info.version to keep parser compatible with the previous one\n // we should bubble this error up and not throw on it\n if (this.specification?.info && !this.specification.info.version) {\n this.specification.info.version = '0.0.1'\n }\n\n try {\n // AnyObject is empty or invalid\n if (specification === undefined || specification === null) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.EMPTY_OR_INVALID)\n }\n\n return {\n valid: false,\n errors: transformErrors(entrypoint, ERRORS.EMPTY_OR_INVALID),\n }\n }\n\n // Meta data about the specification\n const { version, specificationType, specificationVersion } = getOpenApiVersion(specification)\n\n this.version = version\n this.specificationVersion = specificationVersion\n this.specificationType = specificationType\n\n // AnyObject is not supported\n if (!version) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.OPENAPI_VERSION_NOT_SUPPORTED)\n }\n\n return {\n valid: false,\n errors: transformErrors(entrypoint, ERRORS.OPENAPI_VERSION_NOT_SUPPORTED),\n }\n }\n\n // Get the correct OpenAPI validator\n const validateSchema = await this.getAjvValidator(version)\n const schemaResult = validateSchema(specification)\n\n // Error handling\n if (validateSchema.errors) {\n if (validateSchema.errors.length > 0) {\n if (options?.throwOnError) {\n throw new Error(validateSchema.errors[0])\n }\n\n return {\n valid: false,\n errors: transformErrors(entrypoint, validateSchema.errors),\n }\n }\n }\n\n // Check if the references are valid\n const resolvedReferences = resolveReferences(filesystem, options)\n\n return {\n valid: schemaResult && resolvedReferences.valid,\n errors: [...(schemaResult.errors ?? []), ...resolvedReferences.errors],\n schema: resolvedReferences.schema,\n }\n } catch (error) {\n // Something went horribly wrong!\n if (options?.throwOnError) {\n throw error\n }\n\n return {\n valid: false,\n errors: transformErrors(entrypoint, error.message ?? error),\n }\n }\n }\n\n /**\n * Ajv JSON schema validator\n */\n async getAjvValidator(version: OpenApiVersion) {\n // Schema loaded already\n if (this.ajvValidators[version]) {\n return this.ajvValidators[version]\n }\n\n // Load OpenAPI Schema\n const schema = OpenApiSpecifications[version]\n\n // Load JSON Schema\n const AjvClass = jsonSchemaVersions[schema.$schema]\n\n // Get the correct Ajv validator\n const ajv = new AjvClass({\n // Ajv is a bit too strict in its strict validation of OpenAPI schemas.\n // Switch strict mode off.\n strict: false,\n })\n\n // Register formats\n // https://ajv.js.org/packages/ajv-formats.html#formats\n addFormats(ajv)\n\n // OpenAPI 3.1 uses media-range format\n if (version === '3.1') {\n ajv.addFormat('media-range', true)\n }\n\n return (this.ajvValidators[version] = ajv.compile(schema))\n }\n}\n"],
5
+ "mappings": "AAAA,OAAO,WAAW;AAClB,OAAO,gBAAgB;AACvB,OAAO,aAAa;AAEpB,SAAS,QAAQ,uBAA4C,uBAAuB;AAEpF,SAAS,WAAW,yBAAyB;AAC7C,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAKzB,MAAM,qBAAqB;AAAA,EAChC,2CAA2C;AAAA,EAC3C,gDAAgD;AAClD;AAEO,MAAM,UAAU;AAAA,EACd;AAAA,EAEP,OAAc,oBAAoB;AAAA;AAAA,EAGxB,gBAKN,CAAC;AAAA,EAEK;AAAA,EAEA;AAAA,EAEA;AAAA,EAEH;AAAA;AAAA;AAAA;AAAA,EAKP,MAAM,SAAS,YAAwB,SAAuD;AAC5F,UAAM,aAAa,WAAW,KAAK,CAAC,SAAS,KAAK,YAAY;AAC9D,UAAM,gBAAgB,YAAY;AAGlC,SAAK,gBAAgB;AAIrB,QAAI,KAAK,eAAe,QAAQ,CAAC,KAAK,cAAc,KAAK,SAAS;AAChE,WAAK,cAAc,KAAK,UAAU;AAAA,IACpC;AAEA,QAAI;AAEF,UAAI,kBAAkB,UAAa,kBAAkB,MAAM;AACzD,YAAI,SAAS,cAAc;AACzB,gBAAM,IAAI,MAAM,OAAO,gBAAgB;AAAA,QACzC;AAEA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,QAAQ,gBAAgB,YAAY,OAAO,gBAAgB;AAAA,QAC7D;AAAA,MACF;AAGA,YAAM,EAAE,SAAS,mBAAmB,qBAAqB,IAAI,kBAAkB,aAAa;AAE5F,WAAK,UAAU;AACf,WAAK,uBAAuB;AAC5B,WAAK,oBAAoB;AAGzB,UAAI,CAAC,SAAS;AACZ,YAAI,SAAS,cAAc;AACzB,gBAAM,IAAI,MAAM,OAAO,6BAA6B;AAAA,QACtD;AAEA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,QAAQ,gBAAgB,YAAY,OAAO,6BAA6B;AAAA,QAC1E;AAAA,MACF;AAGA,YAAM,iBAAiB,MAAM,KAAK,gBAAgB,OAAO;AACzD,YAAM,eAAe,eAAe,aAAa;AAGjD,UAAI,eAAe,QAAQ;AACzB,YAAI,eAAe,OAAO,SAAS,GAAG;AACpC,cAAI,SAAS,cAAc;AACzB,kBAAM,IAAI,MAAM,eAAe,OAAO,CAAC,CAAC;AAAA,UAC1C;AAEA,iBAAO;AAAA,YACL,OAAO;AAAA,YACP,QAAQ,gBAAgB,YAAY,eAAe,MAAM;AAAA,UAC3D;AAAA,QACF;AAAA,MACF;AAGA,YAAM,qBAAqB,kBAAkB,YAAY,OAAO;AAEhE,aAAO;AAAA,QACL,OAAO,gBAAgB,mBAAmB;AAAA,QAC1C,QAAQ,CAAC,GAAI,aAAa,UAAU,CAAC,GAAI,GAAG,mBAAmB,MAAM;AAAA,QACrE,QAAQ,mBAAmB;AAAA,MAC7B;AAAA,IACF,SAAS,OAAO;AAEd,UAAI,SAAS,cAAc;AACzB,cAAM;AAAA,MACR;AAEA,aAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ,gBAAgB,YAAY,MAAM,WAAW,KAAK;AAAA,MAC5D;AAAA,IACF;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,gBAAgB,SAAyB;AAE7C,QAAI,KAAK,cAAc,OAAO,GAAG;AAC/B,aAAO,KAAK,cAAc,OAAO;AAAA,IACnC;AAGA,UAAM,SAAS,sBAAsB,OAAO;AAG5C,UAAM,WAAW,mBAAmB,OAAO,OAAO;AAGlD,UAAM,MAAM,IAAI,SAAS;AAAA;AAAA;AAAA,MAGvB,QAAQ;AAAA,IACV,CAAC;AAID,eAAW,GAAG;AAGd,QAAI,YAAY,OAAO;AACrB,UAAI,UAAU,eAAe,IAAI;AAAA,IACnC;AAEA,WAAQ,KAAK,cAAc,OAAO,IAAI,IAAI,QAAQ,MAAM;AAAA,EAC1D;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,8 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { Validator } from "./Validator.js";
3
+ describe("Validator", () => {
4
+ it("returns all supported versions", () => {
5
+ expect(Validator.supportedVersions).toMatchObject(["2.0", "3.0", "3.1"]);
6
+ });
7
+ });
8
+ //# sourceMappingURL=Validator.test.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/Validator/Validator.test.ts"],
4
+ "sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { Validator } from './Validator'\n\ndescribe('Validator', () => {\n it('returns all supported versions', () => {\n expect(Validator.supportedVersions).toMatchObject(['2.0', '3.0', '3.1'])\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,iBAAiB;AAE1B,SAAS,aAAa,MAAM;AAC1B,KAAG,kCAAkC,MAAM;AACzC,WAAO,UAAU,iBAAiB,EAAE,cAAc,CAAC,OAAO,OAAO,KAAK,CAAC;AAAA,EACzE,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -1,3 +1,3 @@
1
- export * from './Validator.ts';
2
- export * from '../../utils/resolveReferences.ts';
1
+ export * from './Validator.js';
2
+ export * from '../../utils/resolveReferences.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/Validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kCAAkC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/Validator/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,+BAA+B,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from "./Validator.js";
2
+ export * from "../../utils/resolveReferences.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/lib/Validator/index.ts"],
4
+ "sourcesContent": ["export * from './Validator'\nexport * from '../../utils/resolveReferences'\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;",
6
+ "names": []
7
+ }
@@ -1,4 +1,4 @@
1
- import type { LoadPlugin } from '../../utils/load/load.ts';
1
+ import type { LoadPlugin } from '../../utils/load/load.js';
2
2
  export declare const fetchUrlsDefaultConfiguration: {
3
3
  limit: number;
4
4
  };
@@ -1 +1 @@
1
- {"version":3,"file":"fetchUrls.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch-urls/fetchUrls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAE1D,eAAO,MAAM,6BAA6B;;CAEzC,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,CAAC,mBAAmB,CAAC,EAAE;IAC7C;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3C,KAAK,UA2CL,CAAA"}
1
+ {"version":3,"file":"fetchUrls.d.ts","sourceRoot":"","sources":["../../../src/plugins/fetch-urls/fetchUrls.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD,eAAO,MAAM,6BAA6B;;CAEzC,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,CAAC,mBAAmB,CAAC,EAAE;IAC7C;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,GAAG,KAAK,CAAA;IACtB;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3C,KAAK,UA2CL,CAAA"}
@@ -1,43 +1,40 @@
1
1
  const fetchUrlsDefaultConfiguration = {
2
- limit: 20,
2
+ limit: 20
3
3
  };
4
4
  const fetchUrls = (customConfiguration) => {
5
- // State
6
- let numberOfRequests = 0;
7
- // Configuration
8
- const configuration = {
9
- ...fetchUrlsDefaultConfiguration,
10
- ...customConfiguration,
11
- };
12
- return {
13
- check(value) {
14
- // Not a string
15
- if (typeof value !== 'string') {
16
- return false;
17
- }
18
- // Not http/https
19
- if (!value.startsWith('http://') && !value.startsWith('https://')) {
20
- return false;
21
- }
22
- return true;
23
- },
24
- async get(value) {
25
- // Limit ht enumber of requests
26
- if (configuration?.limit !== false && numberOfRequests >= configuration?.limit) {
27
- console.warn(`[fetchUrls] Maximum number of requests reeached (${configuration?.limit}), skipping request`);
28
- return undefined;
29
- }
30
- try {
31
- numberOfRequests++;
32
- const response = await (configuration?.fetch ? configuration.fetch(value) : fetch(value));
33
- return await response.text();
34
- }
35
- catch (error) {
36
- console.error('[fetchUrls]', error.message, `(${value})`);
37
- return undefined;
38
- }
39
- },
40
- };
5
+ let numberOfRequests = 0;
6
+ const configuration = {
7
+ ...fetchUrlsDefaultConfiguration,
8
+ ...customConfiguration
9
+ };
10
+ return {
11
+ check(value) {
12
+ if (typeof value !== "string") {
13
+ return false;
14
+ }
15
+ if (!value.startsWith("http://") && !value.startsWith("https://")) {
16
+ return false;
17
+ }
18
+ return true;
19
+ },
20
+ async get(value) {
21
+ if (configuration?.limit !== false && numberOfRequests >= configuration?.limit) {
22
+ console.warn(`[fetchUrls] Maximum number of requests reeached (${configuration?.limit}), skipping request`);
23
+ return void 0;
24
+ }
25
+ try {
26
+ numberOfRequests++;
27
+ const response = await (configuration?.fetch ? configuration.fetch(value) : fetch(value));
28
+ return await response.text();
29
+ } catch (error) {
30
+ console.error("[fetchUrls]", error.message, `(${value})`);
31
+ return void 0;
32
+ }
33
+ }
34
+ };
41
35
  };
42
-
43
- export { fetchUrls, fetchUrlsDefaultConfiguration };
36
+ export {
37
+ fetchUrls,
38
+ fetchUrlsDefaultConfiguration
39
+ };
40
+ //# sourceMappingURL=fetchUrls.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/plugins/fetch-urls/fetchUrls.ts"],
4
+ "sourcesContent": ["import type { LoadPlugin } from '../../utils/load/load'\n\nexport const fetchUrlsDefaultConfiguration = {\n limit: 20,\n}\n\nexport const fetchUrls: (customConfiguration?: {\n /**\n * Limit the number of requests. Set to `false` to disable the limit.\n */\n limit?: number | false\n /**\n * Fetch function to use instead of the global fetch. Use this to intercept requests.\n */\n fetch?: (url: string) => Promise<Response>\n}) => LoadPlugin = (customConfiguration) => {\n // State\n let numberOfRequests = 0\n\n // Configuration\n const configuration = {\n ...fetchUrlsDefaultConfiguration,\n ...customConfiguration,\n }\n\n return {\n check(value?: any) {\n // Not a string\n if (typeof value !== 'string') {\n return false\n }\n\n // Not http/https\n if (!value.startsWith('http://') && !value.startsWith('https://')) {\n return false\n }\n\n return true\n },\n async get(value?: any) {\n // Limit ht enumber of requests\n if (configuration?.limit !== false && numberOfRequests >= configuration?.limit) {\n console.warn(`[fetchUrls] Maximum number of requests reeached (${configuration?.limit}), skipping request`)\n return undefined\n }\n\n try {\n numberOfRequests++\n\n const response = await (configuration?.fetch ? configuration.fetch(value) : fetch(value))\n\n return await response.text()\n } catch (error) {\n console.error('[fetchUrls]', error.message, `(${value})`)\n return undefined\n }\n },\n }\n}\n"],
5
+ "mappings": "AAEO,MAAM,gCAAgC;AAAA,EAC3C,OAAO;AACT;AAEO,MAAM,YASM,CAAC,wBAAwB;AAE1C,MAAI,mBAAmB;AAGvB,QAAM,gBAAgB;AAAA,IACpB,GAAG;AAAA,IACH,GAAG;AAAA,EACL;AAEA,SAAO;AAAA,IACL,MAAM,OAAa;AAEjB,UAAI,OAAO,UAAU,UAAU;AAC7B,eAAO;AAAA,MACT;AAGA,UAAI,CAAC,MAAM,WAAW,SAAS,KAAK,CAAC,MAAM,WAAW,UAAU,GAAG;AACjE,eAAO;AAAA,MACT;AAEA,aAAO;AAAA,IACT;AAAA,IACA,MAAM,IAAI,OAAa;AAErB,UAAI,eAAe,UAAU,SAAS,oBAAoB,eAAe,OAAO;AAC9E,gBAAQ,KAAK,oDAAoD,eAAe,KAAK,qBAAqB;AAC1G,eAAO;AAAA,MACT;AAEA,UAAI;AACF;AAEA,cAAM,WAAW,OAAO,eAAe,QAAQ,cAAc,MAAM,KAAK,IAAI,MAAM,KAAK;AAEvF,eAAO,MAAM,SAAS,KAAK;AAAA,MAC7B,SAAS,OAAO;AACd,gBAAQ,MAAM,eAAe,MAAM,SAAS,IAAI,KAAK,GAAG;AACxD,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }