openapi-typesafe 1.0.0-rc.1 → 1.0.0-rc.3

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 (286) hide show
  1. package/README.md +12 -5
  2. package/dist/adapters/node-deprecations/node-deprecations.cjs +14 -0
  3. package/dist/adapters/node-deprecations/node-deprecations.cjs.map +1 -0
  4. package/dist/adapters/node-deprecations/node-deprecations.mjs +12 -0
  5. package/dist/adapters/node-deprecations/node-deprecations.mjs.map +1 -0
  6. package/dist/adapters/redocly-loader/configured-headers.cjs +32 -0
  7. package/dist/adapters/redocly-loader/configured-headers.cjs.map +1 -0
  8. package/dist/adapters/redocly-loader/configured-headers.mjs +30 -0
  9. package/dist/adapters/redocly-loader/configured-headers.mjs.map +1 -0
  10. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +19 -6
  11. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  12. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +18 -5
  13. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  14. package/dist/adapters/redocly-loader/ref-access.cjs +37 -4
  15. package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
  16. package/dist/adapters/redocly-loader/ref-access.mjs +37 -4
  17. package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
  18. package/dist/adapters/redocly-loader/ref-resolution-check.cjs +191 -0
  19. package/dist/adapters/redocly-loader/ref-resolution-check.cjs.map +1 -0
  20. package/dist/adapters/redocly-loader/ref-resolution-check.mjs +189 -0
  21. package/dist/adapters/redocly-loader/ref-resolution-check.mjs.map +1 -0
  22. package/dist/adapters/redocly-loader/ref-resolution-steps.cjs +73 -0
  23. package/dist/adapters/redocly-loader/ref-resolution-steps.cjs.map +1 -0
  24. package/dist/adapters/redocly-loader/ref-resolution-steps.mjs +60 -0
  25. package/dist/adapters/redocly-loader/ref-resolution-steps.mjs.map +1 -0
  26. package/dist/adapters/redocly-loader/remote-fetch.cjs +41 -14
  27. package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
  28. package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -14
  29. package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
  30. package/dist/adapters/redocly-loader/schema-load-errors.cjs +23 -5
  31. package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
  32. package/dist/adapters/redocly-loader/schema-load-errors.mjs +23 -5
  33. package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
  34. package/dist/adapters/redocly-loader/unsupported-keys.cjs +9 -1
  35. package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
  36. package/dist/adapters/redocly-loader/unsupported-keys.mjs +9 -1
  37. package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
  38. package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
  39. package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
  40. package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
  41. package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
  42. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs +2 -1
  43. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -1
  44. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +2 -1
  45. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs.map +1 -1
  46. package/dist/adapters/type-ast-bridge/print-typescript.cjs.map +1 -1
  47. package/dist/adapters/type-ast-bridge/print-typescript.mjs.map +1 -1
  48. package/dist/api/default-ports.cjs +14 -0
  49. package/dist/api/default-ports.cjs.map +1 -1
  50. package/dist/api/default-ports.mjs +12 -1
  51. package/dist/api/default-ports.mjs.map +1 -1
  52. package/dist/api/discriminator-conflict-warnings.cjs +1 -1
  53. package/dist/api/discriminator-conflict-warnings.cjs.map +1 -1
  54. package/dist/api/discriminator-conflict-warnings.mjs +2 -2
  55. package/dist/api/discriminator-conflict-warnings.mjs.map +1 -1
  56. package/dist/api/discriminator-patch.cjs +8 -4
  57. package/dist/api/discriminator-patch.cjs.map +1 -1
  58. package/dist/api/discriminator-patch.mjs +9 -5
  59. package/dist/api/discriminator-patch.mjs.map +1 -1
  60. package/dist/api/discriminator-scan.cjs +2 -2
  61. package/dist/api/discriminator-scan.cjs.map +1 -1
  62. package/dist/api/discriminator-scan.mjs +3 -3
  63. package/dist/api/discriminator-scan.mjs.map +1 -1
  64. package/dist/api/document-refs.cjs +15 -12
  65. package/dist/api/document-refs.cjs.map +1 -1
  66. package/dist/api/document-refs.mjs +15 -12
  67. package/dist/api/document-refs.mjs.map +1 -1
  68. package/dist/api/document-run.cjs +6 -3
  69. package/dist/api/document-run.cjs.map +1 -1
  70. package/dist/api/document-run.mjs +6 -3
  71. package/dist/api/document-run.mjs.map +1 -1
  72. package/dist/api/footer-sink.cjs +25 -2
  73. package/dist/api/footer-sink.cjs.map +1 -1
  74. package/dist/api/footer-sink.mjs +25 -2
  75. package/dist/api/footer-sink.mjs.map +1 -1
  76. package/dist/api/legacy-callback-warning.cjs +7 -1
  77. package/dist/api/legacy-callback-warning.cjs.map +1 -1
  78. package/dist/api/legacy-callback-warning.mjs +8 -2
  79. package/dist/api/legacy-callback-warning.mjs.map +1 -1
  80. package/dist/api/legacy-ts-helpers.cjs.map +1 -1
  81. package/dist/api/legacy-ts-helpers.mjs.map +1 -1
  82. package/dist/api/legacy-utils.cjs.map +1 -1
  83. package/dist/api/legacy-utils.mjs.map +1 -1
  84. package/dist/api/openapi-ts.cjs +3 -2
  85. package/dist/api/openapi-ts.cjs.map +1 -1
  86. package/dist/api/openapi-ts.mjs +4 -3
  87. package/dist/api/openapi-ts.mjs.map +1 -1
  88. package/dist/api/string-to-ast.cjs +7 -9
  89. package/dist/api/string-to-ast.cjs.map +1 -1
  90. package/dist/api/string-to-ast.mjs +8 -9
  91. package/dist/api/string-to-ast.mjs.map +1 -1
  92. package/dist/api/transform-context.cjs +1 -1
  93. package/dist/api/transform-context.cjs.map +1 -1
  94. package/dist/api/transform-context.mjs +1 -1
  95. package/dist/api/transform-context.mjs.map +1 -1
  96. package/dist/api/transform-schema.cjs +2 -2
  97. package/dist/api/transform-schema.cjs.map +1 -1
  98. package/dist/api/transform-schema.mjs +3 -3
  99. package/dist/api/transform-schema.mjs.map +1 -1
  100. package/dist/application/print/type-printer.cjs +2 -1
  101. package/dist/application/print/type-printer.cjs.map +1 -1
  102. package/dist/application/print/type-printer.mjs +2 -1
  103. package/dist/application/print/type-printer.mjs.map +1 -1
  104. package/dist/application/transform/document/components.cjs +1 -1
  105. package/dist/application/transform/document/components.cjs.map +1 -1
  106. package/dist/application/transform/document/components.mjs +2 -2
  107. package/dist/application/transform/document/components.mjs.map +1 -1
  108. package/dist/application/transform/document/parameters.cjs +2 -2
  109. package/dist/application/transform/document/parameters.cjs.map +1 -1
  110. package/dist/application/transform/document/parameters.mjs +3 -3
  111. package/dist/application/transform/document/parameters.mjs.map +1 -1
  112. package/dist/application/transform/document/paths.cjs +2 -2
  113. package/dist/application/transform/document/paths.cjs.map +1 -1
  114. package/dist/application/transform/document/paths.mjs +3 -3
  115. package/dist/application/transform/document/paths.mjs.map +1 -1
  116. package/dist/application/transform/footer/evaluation.cjs +9 -0
  117. package/dist/application/transform/footer/evaluation.cjs.map +1 -1
  118. package/dist/application/transform/footer/evaluation.mjs +8 -1
  119. package/dist/application/transform/footer/evaluation.mjs.map +1 -1
  120. package/dist/application/transform/footer/type-evaluation.cjs +4 -112
  121. package/dist/application/transform/footer/type-evaluation.cjs.map +1 -1
  122. package/dist/application/transform/footer/type-evaluation.mjs +4 -112
  123. package/dist/application/transform/footer/type-evaluation.mjs.map +1 -1
  124. package/dist/application/transform/footer/type-indexing.cjs +107 -0
  125. package/dist/application/transform/footer/type-indexing.cjs.map +1 -0
  126. package/dist/application/transform/footer/type-indexing.mjs +105 -0
  127. package/dist/application/transform/footer/type-indexing.mjs.map +1 -0
  128. package/dist/application/transform/ref-pointer/pointer-type.cjs +1 -1
  129. package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
  130. package/dist/application/transform/ref-pointer/pointer-type.mjs +2 -2
  131. package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
  132. package/dist/application/transform/schema/access-flags.cjs +1 -1
  133. package/dist/application/transform/schema/access-flags.cjs.map +1 -1
  134. package/dist/application/transform/schema/access-flags.mjs +2 -2
  135. package/dist/application/transform/schema/access-flags.mjs.map +1 -1
  136. package/dist/application/transform/schema/array-type.cjs +2 -2
  137. package/dist/application/transform/schema/array-type.cjs.map +1 -1
  138. package/dist/application/transform/schema/array-type.mjs +3 -3
  139. package/dist/application/transform/schema/array-type.mjs.map +1 -1
  140. package/dist/application/transform/schema/composition-type.cjs +3 -3
  141. package/dist/application/transform/schema/composition-type.cjs.map +1 -1
  142. package/dist/application/transform/schema/composition-type.mjs +4 -4
  143. package/dist/application/transform/schema/composition-type.mjs.map +1 -1
  144. package/dist/application/transform/schema/enum-rule.cjs +3 -5
  145. package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
  146. package/dist/application/transform/schema/enum-rule.mjs +4 -6
  147. package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
  148. package/dist/application/transform/schema/presence-members.cjs +1 -1
  149. package/dist/application/transform/schema/presence-members.cjs.map +1 -1
  150. package/dist/application/transform/schema/presence-members.mjs +2 -2
  151. package/dist/application/transform/schema/presence-members.mjs.map +1 -1
  152. package/dist/application/transform/schema/required-variants.cjs +2 -2
  153. package/dist/application/transform/schema/required-variants.cjs.map +1 -1
  154. package/dist/application/transform/schema/required-variants.mjs +3 -3
  155. package/dist/application/transform/schema/required-variants.mjs.map +1 -1
  156. package/dist/application/transform/schema/unevaluated-properties.cjs +1 -1
  157. package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
  158. package/dist/application/transform/schema/unevaluated-properties.mjs +2 -2
  159. package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
  160. package/dist/application/transform/schema-comment.cjs +1 -1
  161. package/dist/application/transform/schema-comment.cjs.map +1 -1
  162. package/dist/application/transform/schema-comment.mjs +2 -2
  163. package/dist/application/transform/schema-comment.mjs.map +1 -1
  164. package/dist/cli/api-settings.cjs +78 -0
  165. package/dist/cli/api-settings.cjs.map +1 -0
  166. package/dist/cli/api-settings.mjs +73 -0
  167. package/dist/cli/api-settings.mjs.map +1 -0
  168. package/dist/cli/cli-arguments.cjs +1 -0
  169. package/dist/cli/cli-arguments.cjs.map +1 -1
  170. package/dist/cli/cli-arguments.mjs +1 -1
  171. package/dist/cli/cli-arguments.mjs.map +1 -1
  172. package/dist/cli/help-text.cjs +3 -3
  173. package/dist/cli/help-text.cjs.map +1 -1
  174. package/dist/cli/help-text.mjs +3 -3
  175. package/dist/cli/help-text.mjs.map +1 -1
  176. package/dist/cli/redocly-apis.cjs +8 -4
  177. package/dist/cli/redocly-apis.cjs.map +1 -1
  178. package/dist/cli/redocly-apis.mjs +7 -3
  179. package/dist/cli/redocly-apis.mjs.map +1 -1
  180. package/dist/cli/run-cli.cjs +5 -1
  181. package/dist/cli/run-cli.cjs.map +1 -1
  182. package/dist/cli/run-cli.mjs +5 -1
  183. package/dist/cli/run-cli.mjs.map +1 -1
  184. package/dist/domain/deprecations.cjs +11 -0
  185. package/dist/domain/deprecations.cjs.map +1 -0
  186. package/dist/domain/deprecations.mjs +9 -0
  187. package/dist/domain/deprecations.mjs.map +1 -0
  188. package/dist/domain/errors.cjs +4 -1
  189. package/dist/domain/errors.cjs.map +1 -1
  190. package/dist/domain/errors.mjs +4 -1
  191. package/dist/domain/errors.mjs.map +1 -1
  192. package/dist/domain/ir/constructors.cjs +2 -0
  193. package/dist/domain/ir/constructors.cjs.map +1 -1
  194. package/dist/domain/ir/constructors.mjs +2 -1
  195. package/dist/domain/ir/constructors.mjs.map +1 -1
  196. package/dist/domain/openapi/path-templates.cjs +1 -1
  197. package/dist/domain/openapi/path-templates.cjs.map +1 -1
  198. package/dist/domain/openapi/path-templates.mjs +1 -1
  199. package/dist/domain/openapi/path-templates.mjs.map +1 -1
  200. package/dist/domain/output-fixes.cjs +11 -14
  201. package/dist/domain/output-fixes.cjs.map +1 -1
  202. package/dist/domain/output-fixes.mjs +11 -13
  203. package/dist/domain/output-fixes.mjs.map +1 -1
  204. package/dist/domain/url-credentials.cjs +10 -0
  205. package/dist/domain/url-credentials.cjs.map +1 -0
  206. package/dist/domain/url-credentials.mjs +8 -0
  207. package/dist/domain/url-credentials.mjs.map +1 -0
  208. package/dist/domain/warnings.cjs +8 -1
  209. package/dist/domain/warnings.cjs.map +1 -1
  210. package/dist/domain/warnings.mjs +8 -1
  211. package/dist/domain/warnings.mjs.map +1 -1
  212. package/dist/index.cjs +4 -3
  213. package/dist/index.cjs.map +1 -1
  214. package/dist/index.d.cts +1185 -59
  215. package/dist/index.d.mts +1185 -59
  216. package/dist/index.d.ts +1185 -59
  217. package/dist/index.mjs +4 -2
  218. package/dist/index.mjs.map +1 -1
  219. package/dist/transform/path-item-object.cjs.map +1 -1
  220. package/dist/transform/path-item-object.mjs.map +1 -1
  221. package/package.json +5 -4
  222. package/src/adapters/node-deprecations/node-deprecations.ts +14 -0
  223. package/src/adapters/redocly-loader/configured-headers.ts +65 -0
  224. package/src/adapters/redocly-loader/redocly-schema-loader.ts +22 -7
  225. package/src/adapters/redocly-loader/ref-access.ts +60 -5
  226. package/src/adapters/redocly-loader/ref-resolution-check.ts +257 -0
  227. package/src/adapters/redocly-loader/ref-resolution-steps.ts +113 -0
  228. package/src/adapters/redocly-loader/remote-fetch.ts +77 -21
  229. package/src/adapters/redocly-loader/schema-load-errors.ts +33 -11
  230. package/src/adapters/redocly-loader/unsupported-keys.ts +17 -2
  231. package/src/adapters/terminal-logger/terminal-logger.ts +9 -5
  232. package/src/adapters/type-ast-bridge/ir-to-typescript.ts +2 -1
  233. package/src/adapters/type-ast-bridge/print-typescript.ts +3 -1
  234. package/src/adapters/type-ast-bridge/typescript-types.ts +57 -5
  235. package/src/api/default-ports.ts +23 -0
  236. package/src/api/discriminator-conflict-warnings.ts +2 -2
  237. package/src/api/discriminator-patch.ts +11 -7
  238. package/src/api/discriminator-scan.ts +3 -3
  239. package/src/api/document-refs.ts +19 -15
  240. package/src/api/document-run.ts +14 -6
  241. package/src/api/footer-sink.ts +34 -2
  242. package/src/api/legacy-callback-warning.ts +16 -5
  243. package/src/api/legacy-ts-helpers.ts +7 -5
  244. package/src/api/legacy-utils.ts +1 -1
  245. package/src/api/openapi-ts.ts +8 -2
  246. package/src/api/run-context.ts +37 -0
  247. package/src/api/string-to-ast.ts +11 -15
  248. package/src/api/transform-context.ts +10 -8
  249. package/src/api/transform-schema.ts +9 -8
  250. package/src/application/ports/deprecation-reporter.ts +9 -0
  251. package/src/application/print/type-printer.ts +2 -1
  252. package/src/application/transform/document/components.ts +2 -2
  253. package/src/application/transform/document/parameters.ts +4 -3
  254. package/src/application/transform/document/paths.ts +4 -3
  255. package/src/application/transform/footer/evaluation.ts +10 -0
  256. package/src/application/transform/footer/type-evaluation.ts +6 -133
  257. package/src/application/transform/footer/type-indexing.ts +152 -0
  258. package/src/application/transform/ref-pointer/pointer-type.ts +2 -4
  259. package/src/application/transform/schema/access-flags.ts +2 -2
  260. package/src/application/transform/schema/array-type.ts +3 -5
  261. package/src/application/transform/schema/composition-type.ts +4 -4
  262. package/src/application/transform/schema/enum-rule.ts +4 -6
  263. package/src/application/transform/schema/presence-members.ts +2 -2
  264. package/src/application/transform/schema/required-variants.ts +3 -3
  265. package/src/application/transform/schema/unevaluated-properties.ts +2 -2
  266. package/src/application/transform/schema-comment.ts +2 -2
  267. package/src/cli/api-settings.ts +109 -0
  268. package/src/cli/cli-arguments.ts +5 -2
  269. package/src/cli/help-text.ts +4 -4
  270. package/src/cli/redocly-apis.ts +13 -7
  271. package/src/cli/run-cli.ts +5 -1
  272. package/src/domain/deprecations.ts +15 -0
  273. package/src/domain/errors.ts +16 -4
  274. package/src/domain/ir/constructors.ts +3 -0
  275. package/src/domain/ir/nodes.ts +9 -6
  276. package/src/domain/openapi/path-templates.ts +2 -1
  277. package/src/domain/output-fixes.ts +16 -16
  278. package/src/domain/url-credentials.ts +18 -0
  279. package/src/domain/warnings.ts +7 -0
  280. package/src/index.ts +3 -6
  281. package/src/transform/path-item-object.ts +6 -2
  282. package/src/types/generator-options.ts +12 -32
  283. package/src/types/openapi-common.ts +1 -0
  284. package/src/types/openapi-request.ts +3 -0
  285. package/src/types/openapi-schema.ts +2 -0
  286. package/src/types/openapi-security.ts +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref-resolution-steps.cjs","sources":["../../../src/adapters/redocly-loader/ref-resolution-steps.ts"],"sourcesContent":["import type { Document, normalizeTypes } from \"@redocly/openapi-core\";\nimport { parseRefPointer } from \"../../domain/openapi/json-pointer.js\";\n\n/**\n * The pieces of Redocly 1.34's `$ref` resolution (`lib/resolve.js`, `lib/ref-utils.js`, MIT) that\n * the resolution check (`ref-resolution-check.ts`, ADR-031) walks with, kept as Redocly has them.\n */\n\ntype RedoclyTypes = ReturnType<typeof normalizeTypes>;\nexport type WalkType = RedoclyTypes[string];\ntype PropTypeOrFunction = WalkType[\"properties\"][string] | WalkType[\"additionalProperties\"];\n/** The type of a property or array item, after Redocly called a type function. */\nexport type PropType = Exclude<PropTypeOrFunction, (...args: never[]) => unknown>;\n\n/** Redocly's own placeholders: a node of no known type, and a scalar that is a `$ref`. */\nexport const UNKNOWN_TYPE: WalkType = { name: \"unknown\", properties: {} };\nexport const RESOLVABLE_SCALAR_TYPE: WalkType = { name: \"scalar\", properties: {} };\n\n/** Redocly's test for an anchor reference (`#name`), which waits for the whole document walk. */\nexport const ANCHOR_REF = /^#[A-Za-z][A-Za-z0-9\\-_:.]*$/;\n\n/** Redocly throws a plain Error with this message for a `$ref` chain that points back to itself. */\nexport const REF_CYCLE_MESSAGE = \"Self-referencing circular pointer\";\n\nexport interface RefStack {\n readonly prev: RefStack | null;\n readonly node: unknown;\n}\n\nexport interface ResolvedRef {\n readonly resolved: boolean;\n readonly node?: unknown;\n readonly document?: Document;\n readonly nodePointer?: string;\n}\n\nexport type Ref = { readonly $ref: string };\n\nexport function isNamedType(type: PropType): type is WalkType {\n return typeof (type as { name?: unknown } | null | undefined)?.name === \"string\";\n}\n\nexport function joinPointer(base: string, key: string | number): string {\n const start = base === \"\" ? \"#/\" : base;\n return start.endsWith(\"/\") ? `${start}${key}` : `${start}/${key}`;\n}\n\nexport function escapePointer(fragment: string): string {\n return fragment.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\n/** Redocly's `parseRef`: the document part (null for a local ref) and the unescaped segments. */\nexport function parseRef(ref: string): { uri: string | null; pointer: string[] } {\n const [uri = \"\"] = ref.split(\"#/\");\n return {\n uri: (uri.endsWith(\"#\") ? uri.slice(0, -1) : uri) || null,\n pointer: parseRefPointer(ref),\n };\n}\n\nexport function hasRef(head: RefStack | null, node: unknown): boolean {\n for (let entry = head; entry !== null; entry = entry.prev) {\n if (entry.node === node) {\n return true;\n }\n }\n return false;\n}\n\nexport function isExternalValue(node: object): node is { externalValue: string } {\n return typeof (node as { externalValue?: unknown }).externalValue === \"string\";\n}\n\n/** Wait one macrotask, as Redocly does before it reads the anchors of a document. */\nexport function nextTick(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve));\n}\n\n/**\n * The type Redocly gives one property value, and the value to walk (a `directResolveAs` string\n * becomes a `$ref`). A value whose type has no name is not walked.\n */\nexport function propertyType(\n type: WalkType,\n name: string,\n value: unknown,\n specExtension: WalkType,\n): [PropType, unknown] {\n // `properties[name]` also finds `Object.prototype` members, as in Redocly; for `valueOf` and the\n // like the call below throws the TypeError that the loader turns into SCHEMA_KEY_UNSUPPORTED.\n let declared: PropTypeOrFunction = type.properties[name];\n if (declared === undefined) {\n declared = type.additionalProperties;\n }\n let propType: PropType = typeof declared === \"function\" ? declared(value, name) : declared;\n if (propType === undefined) {\n propType = UNKNOWN_TYPE;\n }\n if (\n type.extensionsPrefix &&\n name.startsWith(type.extensionsPrefix) &&\n propType === UNKNOWN_TYPE\n ) {\n return [specExtension, value];\n }\n if (!isNamedType(propType) && propType?.directResolveAs) {\n return [propType.directResolveAs, { $ref: value }];\n }\n if (propType && !isNamedType(propType) && propType.resolvable !== false) {\n return [RESOLVABLE_SCALAR_TYPE, value];\n }\n return [propType, value];\n}\n"],"names":["parseRefPointer"],"mappings":";;;;AAeO,MAAM,eAAyB,EAAE,IAAA,EAAM,SAAA,EAAW,UAAA,EAAY,EAAC;AAC/D,MAAM,yBAAmC,EAAE,IAAA,EAAM,QAAA,EAAU,UAAA,EAAY,EAAC;AAGxE,MAAM,UAAA,GAAa;AAGnB,MAAM,iBAAA,GAAoB;AAgB1B,SAAS,YAAY,IAAA,EAAkC;AAC5D,EAAA,OAAO,OAAQ,MAAgD,IAAA,KAAS,QAAA;AAC1E;AAEO,SAAS,WAAA,CAAY,MAAc,GAAA,EAA8B;AACtE,EAAA,MAAM,KAAA,GAAQ,IAAA,KAAS,EAAA,GAAK,IAAA,GAAO,IAAA;AACnC,EAAA,OAAO,KAAA,CAAM,QAAA,CAAS,GAAG,CAAA,GAAI,CAAA,EAAG,KAAK,CAAA,EAAG,GAAG,CAAA,CAAA,GAAK,CAAA,EAAG,KAAK,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA;AACjE;AAEO,SAAS,cAAc,QAAA,EAA0B;AACtD,EAAA,OAAO,SAAS,UAAA,CAAW,GAAA,EAAK,IAAI,CAAA,CAAE,UAAA,CAAW,KAAK,IAAI,CAAA;AAC5D;AAGO,SAAS,SAAS,GAAA,EAAwD;AAC/E,EAAA,MAAM,CAAC,GAAA,GAAM,EAAE,CAAA,GAAI,GAAA,CAAI,MAAM,IAAI,CAAA;AACjC,EAAA,OAAO;AAAA,IACL,GAAA,EAAA,CAAM,GAAA,CAAI,QAAA,CAAS,GAAG,CAAA,GAAI,IAAI,KAAA,CAAM,CAAA,EAAG,EAAE,CAAA,GAAI,GAAA,KAAQ,IAAA;AAAA,IACrD,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AA,EACnD;AACA,EAAA,IAAI,YAAY,CAAC,WAAA,CAAY,QAAQ,CAAA,IAAK,QAAA,CAAS,eAAe,KAAA,EAAO;AACvE,IAAA,OAAO,CAAC,wBAAwB,KAAK,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,CAAC,UAAU,KAAK,CAAA;AACzB;;;;;;;;;;;;;"}
@@ -0,0 +1,60 @@
1
+ import { parseRefPointer } from '../../domain/openapi/json-pointer.mjs';
2
+
3
+ const UNKNOWN_TYPE = { name: "unknown", properties: {} };
4
+ const RESOLVABLE_SCALAR_TYPE = { name: "scalar", properties: {} };
5
+ const ANCHOR_REF = /^#[A-Za-z][A-Za-z0-9\-_:.]*$/;
6
+ const REF_CYCLE_MESSAGE = "Self-referencing circular pointer";
7
+ function isNamedType(type) {
8
+ return typeof type?.name === "string";
9
+ }
10
+ function joinPointer(base, key) {
11
+ const start = base === "" ? "#/" : base;
12
+ return start.endsWith("/") ? `${start}${key}` : `${start}/${key}`;
13
+ }
14
+ function escapePointer(fragment) {
15
+ return fragment.replaceAll("~", "~0").replaceAll("/", "~1");
16
+ }
17
+ function parseRef(ref) {
18
+ const [uri = ""] = ref.split("#/");
19
+ return {
20
+ uri: (uri.endsWith("#") ? uri.slice(0, -1) : uri) || null,
21
+ pointer: parseRefPointer(ref)
22
+ };
23
+ }
24
+ function hasRef(head, node) {
25
+ for (let entry = head; entry !== null; entry = entry.prev) {
26
+ if (entry.node === node) {
27
+ return true;
28
+ }
29
+ }
30
+ return false;
31
+ }
32
+ function isExternalValue(node) {
33
+ return typeof node.externalValue === "string";
34
+ }
35
+ function nextTick() {
36
+ return new Promise((resolve) => setTimeout(resolve));
37
+ }
38
+ function propertyType(type, name, value, specExtension) {
39
+ let declared = type.properties[name];
40
+ if (declared === void 0) {
41
+ declared = type.additionalProperties;
42
+ }
43
+ let propType = typeof declared === "function" ? declared(value, name) : declared;
44
+ if (propType === void 0) {
45
+ propType = UNKNOWN_TYPE;
46
+ }
47
+ if (type.extensionsPrefix && name.startsWith(type.extensionsPrefix) && propType === UNKNOWN_TYPE) {
48
+ return [specExtension, value];
49
+ }
50
+ if (!isNamedType(propType) && propType?.directResolveAs) {
51
+ return [propType.directResolveAs, { $ref: value }];
52
+ }
53
+ if (propType && !isNamedType(propType) && propType.resolvable !== false) {
54
+ return [RESOLVABLE_SCALAR_TYPE, value];
55
+ }
56
+ return [propType, value];
57
+ }
58
+
59
+ export { ANCHOR_REF, REF_CYCLE_MESSAGE, RESOLVABLE_SCALAR_TYPE, UNKNOWN_TYPE, escapePointer, hasRef, isExternalValue, isNamedType, joinPointer, nextTick, parseRef, propertyType };
60
+ //# sourceMappingURL=ref-resolution-steps.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ref-resolution-steps.mjs","sources":["../../../src/adapters/redocly-loader/ref-resolution-steps.ts"],"sourcesContent":["import type { Document, normalizeTypes } from \"@redocly/openapi-core\";\nimport { parseRefPointer } from \"../../domain/openapi/json-pointer.js\";\n\n/**\n * The pieces of Redocly 1.34's `$ref` resolution (`lib/resolve.js`, `lib/ref-utils.js`, MIT) that\n * the resolution check (`ref-resolution-check.ts`, ADR-031) walks with, kept as Redocly has them.\n */\n\ntype RedoclyTypes = ReturnType<typeof normalizeTypes>;\nexport type WalkType = RedoclyTypes[string];\ntype PropTypeOrFunction = WalkType[\"properties\"][string] | WalkType[\"additionalProperties\"];\n/** The type of a property or array item, after Redocly called a type function. */\nexport type PropType = Exclude<PropTypeOrFunction, (...args: never[]) => unknown>;\n\n/** Redocly's own placeholders: a node of no known type, and a scalar that is a `$ref`. */\nexport const UNKNOWN_TYPE: WalkType = { name: \"unknown\", properties: {} };\nexport const RESOLVABLE_SCALAR_TYPE: WalkType = { name: \"scalar\", properties: {} };\n\n/** Redocly's test for an anchor reference (`#name`), which waits for the whole document walk. */\nexport const ANCHOR_REF = /^#[A-Za-z][A-Za-z0-9\\-_:.]*$/;\n\n/** Redocly throws a plain Error with this message for a `$ref` chain that points back to itself. */\nexport const REF_CYCLE_MESSAGE = \"Self-referencing circular pointer\";\n\nexport interface RefStack {\n readonly prev: RefStack | null;\n readonly node: unknown;\n}\n\nexport interface ResolvedRef {\n readonly resolved: boolean;\n readonly node?: unknown;\n readonly document?: Document;\n readonly nodePointer?: string;\n}\n\nexport type Ref = { readonly $ref: string };\n\nexport function isNamedType(type: PropType): type is WalkType {\n return typeof (type as { name?: unknown } | null | undefined)?.name === \"string\";\n}\n\nexport function joinPointer(base: string, key: string | number): string {\n const start = base === \"\" ? \"#/\" : base;\n return start.endsWith(\"/\") ? `${start}${key}` : `${start}/${key}`;\n}\n\nexport function escapePointer(fragment: string): string {\n return fragment.replaceAll(\"~\", \"~0\").replaceAll(\"/\", \"~1\");\n}\n\n/** Redocly's `parseRef`: the document part (null for a local ref) and the unescaped segments. */\nexport function parseRef(ref: string): { uri: string | null; pointer: string[] } {\n const [uri = \"\"] = ref.split(\"#/\");\n return {\n uri: (uri.endsWith(\"#\") ? uri.slice(0, -1) : uri) || null,\n pointer: parseRefPointer(ref),\n };\n}\n\nexport function hasRef(head: RefStack | null, node: unknown): boolean {\n for (let entry = head; entry !== null; entry = entry.prev) {\n if (entry.node === node) {\n return true;\n }\n }\n return false;\n}\n\nexport function isExternalValue(node: object): node is { externalValue: string } {\n return typeof (node as { externalValue?: unknown }).externalValue === \"string\";\n}\n\n/** Wait one macrotask, as Redocly does before it reads the anchors of a document. */\nexport function nextTick(): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve));\n}\n\n/**\n * The type Redocly gives one property value, and the value to walk (a `directResolveAs` string\n * becomes a `$ref`). A value whose type has no name is not walked.\n */\nexport function propertyType(\n type: WalkType,\n name: string,\n value: unknown,\n specExtension: WalkType,\n): [PropType, unknown] {\n // `properties[name]` also finds `Object.prototype` members, as in Redocly; for `valueOf` and the\n // like the call below throws the TypeError that the loader turns into SCHEMA_KEY_UNSUPPORTED.\n let declared: PropTypeOrFunction = type.properties[name];\n if (declared === undefined) {\n declared = type.additionalProperties;\n }\n let propType: PropType = typeof declared === \"function\" ? declared(value, name) : declared;\n if (propType === undefined) {\n propType = UNKNOWN_TYPE;\n }\n if (\n type.extensionsPrefix &&\n name.startsWith(type.extensionsPrefix) &&\n propType === UNKNOWN_TYPE\n ) {\n return [specExtension, value];\n }\n if (!isNamedType(propType) && propType?.directResolveAs) {\n return [propType.directResolveAs, { $ref: value }];\n }\n if (propType && !isNamedType(propType) && propType.resolvable !== false) {\n return [RESOLVABLE_SCALAR_TYPE, value];\n }\n return [propType, value];\n}\n"],"names":[],"mappings":";;AAeO,MAAM,eAAyB,EAAE,IAAA,EAAM,SAAA,EAAW,UAAA,EAAY,EAAC;AAC/D,MAAM,yBAAmC,EAAE,IAAA,EAAM,QAAA,EAAU,UAAA,EAAY,EAAC;AAGxE,MAAM,UAAA,GAAa;AAGnB,MAAM,iBAAA,GAAoB;AAgB1B,SAAS,YAAY,IAAA,EAAkC;AAC5D,EAAA,OAAO,OAAQ,MAAgD,IAAA,KAAS,QAAA;AAC1E;AAEO,SAAS,WAAA,CAAY,MAAc,GAAA,EAA8B;AACtE,EAAA,MAAM,KAAA,GAAQ,IAAA,KAAS,EAAA,GAAK,IAAA,GAAO,IAAA;AACnC,EAAA,OAAO,KAAA,CAAM,QAAA,CAAS,GAAG,CAAA,GAAI,CAAA,EAAG,KAAK,CAAA,EAAG,GAAG,CAAA,CAAA,GAAK,CAAA,EAAG,KAAK,CAAA,CAAA,EAAI,GAAG,CAAA,CAAA;AACjE;AAEO,SAAS,cAAc,QAAA,EAA0B;AACtD,EAAA,OAAO,SAAS,UAAA,CAAW,GAAA,EAAK,IAAI,CAAA,CAAE,UAAA,CAAW,KAAK,IAAI,CAAA;AAC5D;AAGO,SAAS,SAAS,GAAA,EAAwD;AAC/E,EAAA,MAAM,CAAC,GAAA,GAAM,EAAE,CAAA,GAAI,GAAA,CAAI,MAAM,IAAI,CAAA;AACjC,EAAA,OAAO;AAAA,IACL,GAAA,EAAA,CAAM,GAAA,CAAI,QAAA,CA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UAAU,eAAA,EAAiB;AACvD,IAAA,OAAO,CAAC,QAAA,CAAS,eAAA,EAAiB,EAAE,IAAA,EAAM,OAAO,CAAA;AAAA,EACnD;AACA,EAAA,IAAI,YAAY,CAAC,WAAA,CAAY,QAAQ,CAAA,IAAK,QAAA,CAAS,eAAe,KAAA,EAAO;AACvE,IAAA,OAAO,CAAC,wBAAwB,KAAK,CAAA;AAAA,EACvC;AACA,EAAA,OAAO,CAAC,UAAU,KAAK,CAAA;AACzB;;"}
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  const allowedHosts = require('./allowed-hosts.cjs');
4
+ const configuredHeaders = require('./configured-headers.cjs');
4
5
  const schemaLoadErrors = require('./schema-load-errors.cjs');
5
6
 
6
- const MAX_CHECKED_REDIRECTS = 5;
7
+ const MAX_REDIRECTS = 20;
7
8
  const REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
8
9
  const NULL_BODY_STATUSES = /* @__PURE__ */ new Set([101, 103, 204, 205, 304]);
9
10
  async function bufferedResponse(response) {
@@ -26,35 +27,61 @@ function fetchWithTimeout(timeoutMs) {
26
27
  }
27
28
  };
28
29
  }
29
- function fetchWithCheckedRedirects(fetchImpl, hosts) {
30
+ function fetchWithCheckedRedirects(fetchImpl, policy) {
30
31
  return async (input, init = {}) => {
31
- const firstOrigin = new URL(input).origin;
32
32
  let url = new URL(input);
33
- for (let hop = 0; hop <= MAX_CHECKED_REDIRECTS; hop += 1) {
34
- if (hop > 0 && !allowedHosts.isHostAllowed(url, hosts)) {
35
- throw schemaLoadErrors.refForbiddenError(url.href, { reason: "host-not-allowed", allowedHosts: [...hosts] });
33
+ for (let hop = 0; hop <= MAX_REDIRECTS; hop += 1) {
34
+ if (hop > 0 && policy.hosts !== void 0 && !allowedHosts.isHostAllowed(url, policy.hosts)) {
35
+ throw schemaLoadErrors.refForbiddenError(url.href, {
36
+ reason: "host-not-allowed",
37
+ allowedHosts: [...policy.hosts]
38
+ });
36
39
  }
37
- const { headers, ...rest } = init;
38
- const hopInit = url.origin === firstOrigin && headers !== void 0 ? { ...rest, headers } : rest;
39
- const response = await fetchImpl(url.href, { ...hopInit, redirect: "manual" });
40
+ const headers = await configuredHeaders.headersFor(url, policy.headers);
41
+ const response = await fetchImpl(url.href, { ...init, headers, redirect: "manual" });
40
42
  const location = response.headers.get("location");
41
43
  if (!REDIRECT_STATUSES.has(response.status) || location === null) {
42
44
  return response;
43
45
  }
44
46
  url = new URL(location, url);
45
47
  }
46
- throw new Error(`More than ${MAX_CHECKED_REDIRECTS} redirects loading ${input}`);
48
+ throw new Error(`More than ${MAX_REDIRECTS} redirects loading ${input}`);
49
+ };
50
+ }
51
+ function fetchWithConcurrencyLimit(fetchImpl, limit) {
52
+ let running = 0;
53
+ const waiting = [];
54
+ return async (input, init) => {
55
+ if (running < limit) {
56
+ running += 1;
57
+ } else {
58
+ await new Promise((resolve) => waiting.push(resolve));
59
+ }
60
+ try {
61
+ return await fetchImpl(input, init);
62
+ } finally {
63
+ const next = waiting.shift();
64
+ if (next === void 0) {
65
+ running -= 1;
66
+ } else {
67
+ next();
68
+ }
69
+ }
47
70
  };
48
71
  }
49
72
  function resolveConfigWithAccess(resolve, options) {
50
73
  const configured = resolve.http.customFetch;
51
74
  const base = configured ?? fetchWithTimeout(options.timeoutMs);
52
- const hosts = options.access.remoteHosts;
53
- const customFetch = hosts === void 0 ? base : fetchWithCheckedRedirects(base, hosts);
54
- return { ...resolve, http: { ...resolve.http, customFetch } };
75
+ const checked = fetchWithCheckedRedirects(base, {
76
+ headers: resolve.http.headers,
77
+ hosts: options.access.remoteHosts
78
+ });
79
+ const customFetch = fetchWithConcurrencyLimit(checked, options.maxParallelFetches);
80
+ return { ...resolve, http: { ...resolve.http, headers: [], customFetch } };
55
81
  }
56
82
 
57
- exports.MAX_CHECKED_REDIRECTS = MAX_CHECKED_REDIRECTS;
83
+ exports.MAX_REDIRECTS = MAX_REDIRECTS;
58
84
  exports.fetchWithCheckedRedirects = fetchWithCheckedRedirects;
85
+ exports.fetchWithConcurrencyLimit = fetchWithConcurrencyLimit;
59
86
  exports.resolveConfigWithAccess = resolveConfigWithAccess;
60
87
  //# sourceMappingURL=remote-fetch.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"remote-fetch.cjs","sources":["../../../src/adapters/redocly-loader/remote-fetch.ts"],"sourcesContent":["import type { Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport type { RefAccess } from \"../../application/ports/schema-loader.js\";\nimport { isHostAllowed } from \"./allowed-hosts.js\";\nimport { refForbiddenError } from \"./schema-load-errors.js\";\n\n/** How the loader fetches remote documents: a time limit, and the host limit on redirects. */\n\ntype ResolveConfig = RedoclyConfig[\"resolve\"];\n\n/** The fetch Redocly calls for a remote document (`resolve.http.customFetch`). */\nexport type RemoteFetch = (input: string, init?: RequestInit) => Promise<Response>;\n\n/**\n * Redirects followed for a remote `$ref` when hosts are limited. Each hop is checked, so fetch\n * cannot follow them on its own; 5 covers http → https plus a moved file, and a loop stops early.\n */\nexport const MAX_CHECKED_REDIRECTS = 5;\n\nconst REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\n\n/** Statuses whose responses have no body; `new Response()` refuses a body for them. */\nconst NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);\n\n/** A response whose body is already read, so that reading it again cannot wait or fail. */\nasync function bufferedResponse(response: Response): Promise<Response> {\n const body = await response.arrayBuffer();\n const { status, statusText, headers } = response;\n return new Response(NULL_BODY_STATUSES.has(status) ? null : body, {\n status,\n statusText,\n headers,\n });\n}\n\n/**\n * Fetch with a time limit for the whole response, body included: Node's own fetch waits five\n * minutes for a server that never answers, and a server that sends its body one byte at a time\n * never finishes. The body is read here, inside the limit; when Redocly read it, the abort\n * surfaced as a `DOMException` whose read-only `message` Redocly tried to change, which gave\n * \"Cannot set property message of which has only a getter\" instead of the time limit.\n */\nfunction fetchWithTimeout(timeoutMs: number): RemoteFetch {\n return async (input, init = {}) => {\n try {\n const response = await fetch(input, { ...init, signal: AbortSignal.timeout(timeoutMs) });\n return await bufferedResponse(response);\n } catch (cause) {\n const isTimeout = cause instanceof Error && cause.name === \"TimeoutError\";\n throw isTimeout ? new Error(`Timed out after ${timeoutMs} ms loading ${input}`) : cause;\n }\n };\n}\n\n/**\n * Follow redirects one by one, and refuse a redirect to a host that is not listed. The first URL\n * was checked by the resolver (or is the root document). As fetch does, the configured headers\n * (often credentials) are not sent on to another origin.\n */\nexport function fetchWithCheckedRedirects(\n fetchImpl: RemoteFetch,\n hosts: readonly string[],\n): RemoteFetch {\n return async (input, init = {}) => {\n const firstOrigin = new URL(input).origin;\n let url = new URL(input);\n for (let hop = 0; hop <= MAX_CHECKED_REDIRECTS; hop += 1) {\n if (hop > 0 && !isHostAllowed(url, hosts)) {\n throw refForbiddenError(url.href, { reason: \"host-not-allowed\", allowedHosts: [...hosts] });\n }\n const { headers, ...rest } = init;\n const hopInit: RequestInit =\n url.origin === firstOrigin && headers !== undefined ? { ...rest, headers } : rest;\n const response = await fetchImpl(url.href, { ...hopInit, redirect: \"manual\" });\n const location = response.headers.get(\"location\");\n if (!REDIRECT_STATUSES.has(response.status) || location === null) {\n return response;\n }\n url = new URL(location, url);\n }\n throw new Error(`More than ${MAX_CHECKED_REDIRECTS} redirects loading ${input}`);\n };\n}\n\nexport interface RemoteFetchOptions {\n /** Time limit of one fetch and its body, unless the Redocly config has its own `customFetch`. */\n readonly timeoutMs: number;\n readonly access: RefAccess;\n}\n\n/**\n * The resolve config with the fetch the loader uses. A `customFetch` of the Redocly config is\n * kept; with a host limit, it is wrapped so that each redirect is checked.\n */\nexport function resolveConfigWithAccess(\n resolve: ResolveConfig,\n options: RemoteFetchOptions,\n): ResolveConfig {\n // Redocly types `customFetch` as `Function`; it is called as fetch is.\n const configured = resolve.http.customFetch as RemoteFetch | undefined;\n const base = configured ?? fetchWithTimeout(options.timeoutMs);\n const hosts = options.access.remoteHosts;\n const customFetch = hosts === undefined ? base : fetchWithCheckedRed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AAqB,CAAA,mBAAA,EAAsB,KAAK,CAAA,CAAE,CAAA;AAAA,EACjF,CAAA;AACF;AAYO,SAAS,uBAAA,CACd,SACA,OAAA,EACe;AAEf,EAAA,MAAM,UAAA,GAAa,QAAQ,IAAA,CAAK,WAAA;AAChC,EAAA,MAAM,IAAA,GAAO,UAAA,IAAc,gBAAA,CAAiB,OAAA,CAAQ,SAAS,CAAA;AAC7D,EAAA,MAAM,KAAA,GAAQ,QAAQ,MAAA,CAAO,WAAA;AAC7B,EAAA,MAAM,cAAc,KAAA,KAAU,MAAA,GAAY,IAAA,GAAO,yBAAA,CAA0B,MAAM,KAAK,CAAA;AACtF,EAAA,OAAO,EAAE,GAAG,OAAA,EAAS,IAAA,EAAM,EAAE,GAAG,OAAA,CAAQ,IAAA,EAAM,WAAA,EAAY,EAAE;AAC9D;;;;"}
1
+ {"version":3,"file":"remote-fetch.cjs","sources":["../../../src/adapters/redocly-loader/remote-fetch.ts"],"sourcesContent":["import type { Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport type { RefAccess } from \"../../application/ports/schema-loader.js\";\nimport { isHostAllowed } from \"./allowed-hosts.js\";\nimport { type ConfiguredHeader, headersFor } from \"./configured-headers.js\";\nimport { refForbiddenError } from \"./schema-load-errors.js\";\n\n/**\n * How the loader fetches remote documents: a time limit, the host limit and the configured headers\n * checked on every redirect.\n */\n\ntype ResolveConfig = RedoclyConfig[\"resolve\"];\n\n/** The fetch Redocly calls for a remote document (`resolve.http.customFetch`). */\nexport type RemoteFetch = (input: string, init?: RequestInit) => Promise<Response>;\n\n/**\n * Redirects followed for one remote document. The loader follows them itself, so that each hop is\n * checked; 20 is the limit of the Fetch standard, which fetch applied before.\n */\nexport const MAX_REDIRECTS = 20;\n\nconst REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\n\n/** Statuses whose responses have no body; `new Response()` refuses a body for them. */\nconst NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);\n\n/** A response whose body is already read, so that reading it again cannot wait or fail. */\nasync function bufferedResponse(response: Response): Promise<Response> {\n const body = await response.arrayBuffer();\n const { status, statusText, headers } = response;\n return new Response(NULL_BODY_STATUSES.has(status) ? null : body, {\n status,\n statusText,\n headers,\n });\n}\n\n/**\n * Fetch with a time limit for the whole response, body included: Node's own fetch waits five\n * minutes for a server that never answers, and a server that sends its body one byte at a time\n * never finishes. The body is read here, inside the limit; when Redocly read it, the abort\n * surfaced as a `DOMException` whose read-only `message` Redocly tried to change, which gave\n * \"Cannot set property message of which has only a getter\" instead of the time limit.\n */\nfunction fetchWithTimeout(timeoutMs: number): RemoteFetch {\n return async (input, init = {}) => {\n try {\n const response = await fetch(input, { ...init, signal: AbortSignal.timeout(timeoutMs) });\n return await bufferedResponse(response);\n } catch (cause) {\n const isTimeout = cause instanceof Error && cause.name === \"TimeoutError\";\n throw isTimeout ? new Error(`Timed out after ${timeoutMs} ms loading ${input}`) : cause;\n }\n };\n}\n\n/** What every hop of a remote fetch is checked against. */\nexport interface RedirectPolicy {\n /** `resolve.http.headers` of the Redocly config; chosen again for the URL of every hop. */\n readonly headers: readonly ConfiguredHeader[];\n /** `--remote-ref-hosts`; undefined allows every host. */\n readonly hosts: readonly string[] | undefined;\n}\n\n/**\n * Follow redirects one by one. Fetch drops only `Authorization`, `Cookie` and\n * `Proxy-Authorization` on a redirect to another origin and keeps every other header (an\n * `X-Api-Key`), so the configured headers are chosen for each hop's own URL instead, and a hop to\n * a host that is not listed is refused before it is fetched. The first URL was checked by the\n * resolver (or is the root document). Redocly passes only the configured headers in `init`, and\n * it gets an empty list of them (`resolveConfigWithAccess`), so `init.headers` is replaced.\n */\nexport function fetchWithCheckedRedirects(\n fetchImpl: RemoteFetch,\n policy: RedirectPolicy,\n): RemoteFetch {\n return async (input, init = {}) => {\n let url = new URL(input);\n for (let hop = 0; hop <= MAX_REDIRECTS; hop += 1) {\n if (hop > 0 && policy.hosts !== undefined && !isHostAllowed(url, policy.hosts)) {\n throw refForbiddenError(url.href, {\n reason: \"host-not-allowed\",\n allowedHosts: [...policy.hosts],\n });\n }\n const headers = await headersFor(url, policy.headers);\n const response = await fetchImpl(url.href, { ...init, headers, redirect: \"manual\" });\n const location = response.headers.get(\"location\");\n if (!REDIRECT_STATUSES.has(response.status) || location === null) {\n return response;\n }\n url = new URL(location, url);\n }\n throw new Error(`More than ${MAX_REDIRECTS} redirects loading ${input}`);\n };\n}\n\n/** Bounds on the remote documents of one load (threat model T2, ADR-033). */\nexport interface RemoteDocumentLimits {\n /** Remote documents one load may fetch, the root included; one more is refused. */\n readonly maxDocuments: number;\n /** Remote documents fetched at the same time; the others wait for a free slot. */\n readonly maxParallelFetches: number;\n}\n\n/**\n * At most `limit` calls of the fetch run at once; the others wait in order. A finished call hands\n * its slot to the next waiting one.\n */\nexport function fetchWithConcurrencyLimit(fetchImpl: RemoteFetch, limit: number): RemoteFetch {\n let running = 0;\n const waiting: (() => void)[] = [];\n return async (input, init) => {\n if (running < limit) {\n running += 1;\n } else {\n await new Promise<void>((resolve) => waiting.push(resolve));\n }\n try {\n return await fetchImpl(input, init);\n } finally {\n const next = waiting.shift();\n if (next === undefined) {\n running -= 1;\n } else {\n next();\n }\n }\n };\n}\n\nexport interface RemoteFetchOptions {\n /** Time limit of one fetch and its body, unless the Redocly config has its own `customFetch`. */\n readonly timeoutMs: number;\n readonly access: RefAccess;\n readonly maxParallelFetches: number;\n}\n\n/**\n * The resolve config with the fetch the loader uses. A `customFetch` of the Redocly config is\n * kept and wrapped, so that each redirect is checked and only a few documents load at once. The\n * configured headers move into that wrapper: Redocly would match them against the raw URL and\n * send them on through redirects.\n */\nexport function resolveConfigWithAccess(\n resolve: ResolveConfig,\n options: RemoteFetchOptions,\n): ResolveConfig {\n // Redocly types `customFetch` as `Function`; it is called as fetch is.\n const configured = resolve.http.customFetch as RemoteFetch | undefined;\n const base = configured ?? fetchWithTimeout(options.timeoutMs);\n const checked = fetchWithCheckedRedirects(base, {\n headers: resolve.http.headers,\n hosts: options.access.remoteHosts,\n });\n // The limit is outside the redirects, so all hops of one document share one slot.\n const customFetch = fetchWithConcurrencyLimit(checked, options.maxParallelFetches);\n return { ...resolve, http: { ...resolve.http, headers: [], customFetch } };\n}\n"],"names":["isHostAllowed","refForbiddenError","headersFor"],"mappings":";;;;;;AAoBO,MAAM,aAAA,GAAgB;AAE7B,MAAM,iBAAA,uBAAwB,GAAA,CAAI,CAAC,KAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAG,CAAC,CAAA;AAG3D,MAAM,kBAAA,uBAAyB,GAAA,CAAI,CAAC,KAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAG,CAAC,CAAA;AAG5D,eAAe,iBAAiB,QAAA,EAAuC;AACrE,EAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,WAAA,EAAY;AACxC,EAAA,MAAM,EAAE,MAAA,EAAQ,UAAA,EAAY,OAAA,EAAQ,GAAI,QAAA;AACxC,EAAA,OAAO,IAAI,QAAA,CAAS,kBAAA,CAAmB,IAAI,MAAM,CAAA,GAAI,OAAO,IAAA,EAAM;AAAA,IAChE,MAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACD,CAAA;AACH;AASA,SAAS,iBAAiB,SAAA,EAAgC;AACxD,EAAA,OAAO,OAAO,KAAA,EAAO,IAAA,GAAO,EAAC,KAAM;AACjC,IAAA,IAAI;AACF,MAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,KAAA,EAAO,EAAE,GAAG,IAAA,EAAM,MAAA,EAAQ,WAAA,CAAY,OAAA,CAAQ,SAAS,CAAA,EAAG,CAAA;AACvF,MAAA,OAAO,MAAM,iBAAiB,QAAQ,CAAA;AAAA,IACxC,SAAS,KAAA,EAAO;AACd,MAAA,MAAM,SAAA,GAAY,KAAA,YAAiB,KAAA,IAAS,KAAA,CAAM,IAAA,KAAS,cAAA;AAC3D,MAAA,MAAM,SAAA,GAAY,IAAI,KAAA,CAAM,CAAA,gBAAA,EAAmB,SAA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,WAAA,EAAY,EAAE;AAC3E;;;;;"}
@@ -1,7 +1,8 @@
1
1
  import { isHostAllowed } from './allowed-hosts.mjs';
2
+ import { headersFor } from './configured-headers.mjs';
2
3
  import { refForbiddenError } from './schema-load-errors.mjs';
3
4
 
4
- const MAX_CHECKED_REDIRECTS = 5;
5
+ const MAX_REDIRECTS = 20;
5
6
  const REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
6
7
  const NULL_BODY_STATUSES = /* @__PURE__ */ new Set([101, 103, 204, 205, 304]);
7
8
  async function bufferedResponse(response) {
@@ -24,33 +25,58 @@ function fetchWithTimeout(timeoutMs) {
24
25
  }
25
26
  };
26
27
  }
27
- function fetchWithCheckedRedirects(fetchImpl, hosts) {
28
+ function fetchWithCheckedRedirects(fetchImpl, policy) {
28
29
  return async (input, init = {}) => {
29
- const firstOrigin = new URL(input).origin;
30
30
  let url = new URL(input);
31
- for (let hop = 0; hop <= MAX_CHECKED_REDIRECTS; hop += 1) {
32
- if (hop > 0 && !isHostAllowed(url, hosts)) {
33
- throw refForbiddenError(url.href, { reason: "host-not-allowed", allowedHosts: [...hosts] });
31
+ for (let hop = 0; hop <= MAX_REDIRECTS; hop += 1) {
32
+ if (hop > 0 && policy.hosts !== void 0 && !isHostAllowed(url, policy.hosts)) {
33
+ throw refForbiddenError(url.href, {
34
+ reason: "host-not-allowed",
35
+ allowedHosts: [...policy.hosts]
36
+ });
34
37
  }
35
- const { headers, ...rest } = init;
36
- const hopInit = url.origin === firstOrigin && headers !== void 0 ? { ...rest, headers } : rest;
37
- const response = await fetchImpl(url.href, { ...hopInit, redirect: "manual" });
38
+ const headers = await headersFor(url, policy.headers);
39
+ const response = await fetchImpl(url.href, { ...init, headers, redirect: "manual" });
38
40
  const location = response.headers.get("location");
39
41
  if (!REDIRECT_STATUSES.has(response.status) || location === null) {
40
42
  return response;
41
43
  }
42
44
  url = new URL(location, url);
43
45
  }
44
- throw new Error(`More than ${MAX_CHECKED_REDIRECTS} redirects loading ${input}`);
46
+ throw new Error(`More than ${MAX_REDIRECTS} redirects loading ${input}`);
47
+ };
48
+ }
49
+ function fetchWithConcurrencyLimit(fetchImpl, limit) {
50
+ let running = 0;
51
+ const waiting = [];
52
+ return async (input, init) => {
53
+ if (running < limit) {
54
+ running += 1;
55
+ } else {
56
+ await new Promise((resolve) => waiting.push(resolve));
57
+ }
58
+ try {
59
+ return await fetchImpl(input, init);
60
+ } finally {
61
+ const next = waiting.shift();
62
+ if (next === void 0) {
63
+ running -= 1;
64
+ } else {
65
+ next();
66
+ }
67
+ }
45
68
  };
46
69
  }
47
70
  function resolveConfigWithAccess(resolve, options) {
48
71
  const configured = resolve.http.customFetch;
49
72
  const base = configured ?? fetchWithTimeout(options.timeoutMs);
50
- const hosts = options.access.remoteHosts;
51
- const customFetch = hosts === void 0 ? base : fetchWithCheckedRedirects(base, hosts);
52
- return { ...resolve, http: { ...resolve.http, customFetch } };
73
+ const checked = fetchWithCheckedRedirects(base, {
74
+ headers: resolve.http.headers,
75
+ hosts: options.access.remoteHosts
76
+ });
77
+ const customFetch = fetchWithConcurrencyLimit(checked, options.maxParallelFetches);
78
+ return { ...resolve, http: { ...resolve.http, headers: [], customFetch } };
53
79
  }
54
80
 
55
- export { MAX_CHECKED_REDIRECTS, fetchWithCheckedRedirects, resolveConfigWithAccess };
81
+ export { MAX_REDIRECTS, fetchWithCheckedRedirects, fetchWithConcurrencyLimit, resolveConfigWithAccess };
56
82
  //# sourceMappingURL=remote-fetch.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"remote-fetch.mjs","sources":["../../../src/adapters/redocly-loader/remote-fetch.ts"],"sourcesContent":["import type { Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport type { RefAccess } from \"../../application/ports/schema-loader.js\";\nimport { isHostAllowed } from \"./allowed-hosts.js\";\nimport { refForbiddenError } from \"./schema-load-errors.js\";\n\n/** How the loader fetches remote documents: a time limit, and the host limit on redirects. */\n\ntype ResolveConfig = RedoclyConfig[\"resolve\"];\n\n/** The fetch Redocly calls for a remote document (`resolve.http.customFetch`). */\nexport type RemoteFetch = (input: string, init?: RequestInit) => Promise<Response>;\n\n/**\n * Redirects followed for a remote `$ref` when hosts are limited. Each hop is checked, so fetch\n * cannot follow them on its own; 5 covers http → https plus a moved file, and a loop stops early.\n */\nexport const MAX_CHECKED_REDIRECTS = 5;\n\nconst REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\n\n/** Statuses whose responses have no body; `new Response()` refuses a body for them. */\nconst NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);\n\n/** A response whose body is already read, so that reading it again cannot wait or fail. */\nasync function bufferedResponse(response: Response): Promise<Response> {\n const body = await response.arrayBuffer();\n const { status, statusText, headers } = response;\n return new Response(NULL_BODY_STATUSES.has(status) ? null : body, {\n status,\n statusText,\n headers,\n });\n}\n\n/**\n * Fetch with a time limit for the whole response, body included: Node's own fetch waits five\n * minutes for a server that never answers, and a server that sends its body one byte at a time\n * never finishes. The body is read here, inside the limit; when Redocly read it, the abort\n * surfaced as a `DOMException` whose read-only `message` Redocly tried to change, which gave\n * \"Cannot set property message of which has only a getter\" instead of the time limit.\n */\nfunction fetchWithTimeout(timeoutMs: number): RemoteFetch {\n return async (input, init = {}) => {\n try {\n const response = await fetch(input, { ...init, signal: AbortSignal.timeout(timeoutMs) });\n return await bufferedResponse(response);\n } catch (cause) {\n const isTimeout = cause instanceof Error && cause.name === \"TimeoutError\";\n throw isTimeout ? new Error(`Timed out after ${timeoutMs} ms loading ${input}`) : cause;\n }\n };\n}\n\n/**\n * Follow redirects one by one, and refuse a redirect to a host that is not listed. The first URL\n * was checked by the resolver (or is the root document). As fetch does, the configured headers\n * (often credentials) are not sent on to another origin.\n */\nexport function fetchWithCheckedRedirects(\n fetchImpl: RemoteFetch,\n hosts: readonly string[],\n): RemoteFetch {\n return async (input, init = {}) => {\n const firstOrigin = new URL(input).origin;\n let url = new URL(input);\n for (let hop = 0; hop <= MAX_CHECKED_REDIRECTS; hop += 1) {\n if (hop > 0 && !isHostAllowed(url, hosts)) {\n throw refForbiddenError(url.href, { reason: \"host-not-allowed\", allowedHosts: [...hosts] });\n }\n const { headers, ...rest } = init;\n const hopInit: RequestInit =\n url.origin === firstOrigin && headers !== undefined ? { ...rest, headers } : rest;\n const response = await fetchImpl(url.href, { ...hopInit, redirect: \"manual\" });\n const location = response.headers.get(\"location\");\n if (!REDIRECT_STATUSES.has(response.status) || location === null) {\n return response;\n }\n url = new URL(location, url);\n }\n throw new Error(`More than ${MAX_CHECKED_REDIRECTS} redirects loading ${input}`);\n };\n}\n\nexport interface RemoteFetchOptions {\n /** Time limit of one fetch and its body, unless the Redocly config has its own `customFetch`. */\n readonly timeoutMs: number;\n readonly access: RefAccess;\n}\n\n/**\n * The resolve config with the fetch the loader uses. A `customFetch` of the Redocly config is\n * kept; with a host limit, it is wrapped so that each redirect is checked.\n */\nexport function resolveConfigWithAccess(\n resolve: ResolveConfig,\n options: RemoteFetchOptions,\n): ResolveConfig {\n // Redocly types `customFetch` as `Function`; it is called as fetch is.\n const configured = resolve.http.customFetch as RemoteFetch | undefined;\n const base = configured ?? fetchWithTimeout(options.timeoutMs);\n const hosts = options.access.remoteHosts;\n const customFetch = hosts === undefined ? base : fetchWithCheckedRedirects(base, hosts);\n return { ...resolve, http: { ...resolve.http, customFetch } };\n}\n"],"names":[],"mappings":";;;AAgBO,MAAM,qBAAA,GAAwB;AAErC,MAAM,iBAAA,uBAAwB,GAAA,CAAI,CAAC,KAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAG,CAAC,CAAA;AAG3D,MAAM,kBAAA,uBAAyB,GAAA,CAAI,CAAC,KAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAG,CAAC,CAAA;AAG5D,eAAe,iBAAiB,QAAA,EAAuC;AACrE,EAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,WAAA,EAAY;AACxC,EAAA,MAAM,EAAE,MAAA,EAAQ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GAAG,OAAA,CAAQ,IAAA,EAAM,WAAA,EAAY,EAAE;AAC9D;;"}
1
+ {"version":3,"file":"remote-fetch.mjs","sources":["../../../src/adapters/redocly-loader/remote-fetch.ts"],"sourcesContent":["import type { Config as RedoclyConfig } from \"@redocly/openapi-core\";\nimport type { RefAccess } from \"../../application/ports/schema-loader.js\";\nimport { isHostAllowed } from \"./allowed-hosts.js\";\nimport { type ConfiguredHeader, headersFor } from \"./configured-headers.js\";\nimport { refForbiddenError } from \"./schema-load-errors.js\";\n\n/**\n * How the loader fetches remote documents: a time limit, the host limit and the configured headers\n * checked on every redirect.\n */\n\ntype ResolveConfig = RedoclyConfig[\"resolve\"];\n\n/** The fetch Redocly calls for a remote document (`resolve.http.customFetch`). */\nexport type RemoteFetch = (input: string, init?: RequestInit) => Promise<Response>;\n\n/**\n * Redirects followed for one remote document. The loader follows them itself, so that each hop is\n * checked; 20 is the limit of the Fetch standard, which fetch applied before.\n */\nexport const MAX_REDIRECTS = 20;\n\nconst REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\n\n/** Statuses whose responses have no body; `new Response()` refuses a body for them. */\nconst NULL_BODY_STATUSES = new Set([101, 103, 204, 205, 304]);\n\n/** A response whose body is already read, so that reading it again cannot wait or fail. */\nasync function bufferedResponse(response: Response): Promise<Response> {\n const body = await response.arrayBuffer();\n const { status, statusText, headers } = response;\n return new Response(NULL_BODY_STATUSES.has(status) ? null : body, {\n status,\n statusText,\n headers,\n });\n}\n\n/**\n * Fetch with a time limit for the whole response, body included: Node's own fetch waits five\n * minutes for a server that never answers, and a server that sends its body one byte at a time\n * never finishes. The body is read here, inside the limit; when Redocly read it, the abort\n * surfaced as a `DOMException` whose read-only `message` Redocly tried to change, which gave\n * \"Cannot set property message of which has only a getter\" instead of the time limit.\n */\nfunction fetchWithTimeout(timeoutMs: number): RemoteFetch {\n return async (input, init = {}) => {\n try {\n const response = await fetch(input, { ...init, signal: AbortSignal.timeout(timeoutMs) });\n return await bufferedResponse(response);\n } catch (cause) {\n const isTimeout = cause instanceof Error && cause.name === \"TimeoutError\";\n throw isTimeout ? new Error(`Timed out after ${timeoutMs} ms loading ${input}`) : cause;\n }\n };\n}\n\n/** What every hop of a remote fetch is checked against. */\nexport interface RedirectPolicy {\n /** `resolve.http.headers` of the Redocly config; chosen again for the URL of every hop. */\n readonly headers: readonly ConfiguredHeader[];\n /** `--remote-ref-hosts`; undefined allows every host. */\n readonly hosts: readonly string[] | undefined;\n}\n\n/**\n * Follow redirects one by one. Fetch drops only `Authorization`, `Cookie` and\n * `Proxy-Authorization` on a redirect to another origin and keeps every other header (an\n * `X-Api-Key`), so the configured headers are chosen for each hop's own URL instead, and a hop to\n * a host that is not listed is refused before it is fetched. The first URL was checked by the\n * resolver (or is the root document). Redocly passes only the configured headers in `init`, and\n * it gets an empty list of them (`resolveConfigWithAccess`), so `init.headers` is replaced.\n */\nexport function fetchWithCheckedRedirects(\n fetchImpl: RemoteFetch,\n policy: RedirectPolicy,\n): RemoteFetch {\n return async (input, init = {}) => {\n let url = new URL(input);\n for (let hop = 0; hop <= MAX_REDIRECTS; hop += 1) {\n if (hop > 0 && policy.hosts !== undefined && !isHostAllowed(url, policy.hosts)) {\n throw refForbiddenError(url.href, {\n reason: \"host-not-allowed\",\n allowedHosts: [...policy.hosts],\n });\n }\n const headers = await headersFor(url, policy.headers);\n const response = await fetchImpl(url.href, { ...init, headers, redirect: \"manual\" });\n const location = response.headers.get(\"location\");\n if (!REDIRECT_STATUSES.has(response.status) || location === null) {\n return response;\n }\n url = new URL(location, url);\n }\n throw new Error(`More than ${MAX_REDIRECTS} redirects loading ${input}`);\n };\n}\n\n/** Bounds on the remote documents of one load (threat model T2, ADR-033). */\nexport interface RemoteDocumentLimits {\n /** Remote documents one load may fetch, the root included; one more is refused. */\n readonly maxDocuments: number;\n /** Remote documents fetched at the same time; the others wait for a free slot. */\n readonly maxParallelFetches: number;\n}\n\n/**\n * At most `limit` calls of the fetch run at once; the others wait in order. A finished call hands\n * its slot to the next waiting one.\n */\nexport function fetchWithConcurrencyLimit(fetchImpl: RemoteFetch, limit: number): RemoteFetch {\n let running = 0;\n const waiting: (() => void)[] = [];\n return async (input, init) => {\n if (running < limit) {\n running += 1;\n } else {\n await new Promise<void>((resolve) => waiting.push(resolve));\n }\n try {\n return await fetchImpl(input, init);\n } finally {\n const next = waiting.shift();\n if (next === undefined) {\n running -= 1;\n } else {\n next();\n }\n }\n };\n}\n\nexport interface RemoteFetchOptions {\n /** Time limit of one fetch and its body, unless the Redocly config has its own `customFetch`. */\n readonly timeoutMs: number;\n readonly access: RefAccess;\n readonly maxParallelFetches: number;\n}\n\n/**\n * The resolve config with the fetch the loader uses. A `customFetch` of the Redocly config is\n * kept and wrapped, so that each redirect is checked and only a few documents load at once. The\n * configured headers move into that wrapper: Redocly would match them against the raw URL and\n * send them on through redirects.\n */\nexport function resolveConfigWithAccess(\n resolve: ResolveConfig,\n options: RemoteFetchOptions,\n): ResolveConfig {\n // Redocly types `customFetch` as `Function`; it is called as fetch is.\n const configured = resolve.http.customFetch as RemoteFetch | undefined;\n const base = configured ?? fetchWithTimeout(options.timeoutMs);\n const checked = fetchWithCheckedRedirects(base, {\n headers: resolve.http.headers,\n hosts: options.access.remoteHosts,\n });\n // The limit is outside the redirects, so all hops of one document share one slot.\n const customFetch = fetchWithConcurrencyLimit(checked, options.maxParallelFetches);\n return { ...resolve, http: { ...resolve.http, headers: [], customFetch } };\n}\n"],"names":[],"mappings":";;;;AAoBO,MAAM,aAAA,GAAgB;AAE7B,MAAM,iBAAA,uBAAwB,GAAA,CAAI,CAAC,KAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAG,CAAC,CAAA;AAG3D,MAAM,kBAAA,uBAAyB,GAAA,CAAI,CAAC,KAAK,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAG,CAAC,CAAA;AAG5D,eAAe,iBAAiB,QAAA,EAAuC;AACrE,EAAA,MAAM,IAAA,GAAO,MAAM,QAAA,CA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AA,MAAM,IAAA,GAAO,QAAQ,KAAA,EAAM;AAC3B,MAAA,IAAI,SAAS,MAAA,EAAW;AACtB,QAAA,OAAA,IAAW,CAAA;AAAA,MACb,CAAA,MAAO;AACL,QAAA,IAAA,EAAK;AAAA,MACP;AAAA,IACF;AAAA,EACF,CAAA;AACF;AAeO,SAAS,uBAAA,CACd,SACA,OAAA,EACe;AAEf,EAAA,MAAM,UAAA,GAAa,QAAQ,IAAA,CAAK,WAAA;AAChC,EAAA,MAAM,IAAA,GAAO,UAAA,IAAc,gBAAA,CAAiB,OAAA,CAAQ,SAAS,CAAA;AAC7D,EAAA,MAAM,OAAA,GAAU,0BAA0B,IAAA,EAAM;AAAA,IAC9C,OAAA,EAAS,QAAQ,IAAA,CAAK,OAAA;AAAA,IACtB,KAAA,EAAO,QAAQ,MAAA,CAAO;AAAA,GACvB,CAAA;AAED,EAAA,MAAM,WAAA,GAAc,yBAAA,CAA0B,OAAA,EAAS,OAAA,CAAQ,kBAAkB,CAAA;AACjF,EAAA,OAAO,EAAE,GAAG,OAAA,EAAS,IAAA,EAAM,EAAE,GAAG,OAAA,CAAQ,IAAA,EAAM,OAAA,EAAS,EAAC,EAAG,WAAA,EAAY,EAAE;AAC3E;;"}
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ const assertNever = require('../../domain/assert-never.cjs');
3
4
  const errors = require('../../domain/errors.cjs');
5
+ const urlCredentials = require('../../domain/url-credentials.cjs');
4
6
 
5
7
  function sourceEmptyError(message) {
6
8
  return new errors.OpenAPITypesafeError({ code: errors.ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });
@@ -29,7 +31,7 @@ function loadFailedError(absoluteRef, cause) {
29
31
  return new errors.OpenAPITypesafeError({
30
32
  code: errors.ERROR_CODES.SCHEMA_LOAD_FAILED,
31
33
  message: causeMessage(cause),
32
- details: { source: absoluteRef },
34
+ details: { source: urlCredentials.redactUrlCredentials(absoluteRef) },
33
35
  cause
34
36
  });
35
37
  }
@@ -37,7 +39,7 @@ function parseFailedError(format, absoluteRef, cause) {
37
39
  return new errors.OpenAPITypesafeError({
38
40
  code: errors.ERROR_CODES.SCHEMA_PARSE_FAILED,
39
41
  message: causeMessage(cause),
40
- details: { format, source: absoluteRef },
42
+ details: { format, source: urlCredentials.redactUrlCredentials(absoluteRef) },
41
43
  cause
42
44
  });
43
45
  }
@@ -52,7 +54,7 @@ function schemaInvalidError(problems) {
52
54
  return new errors.OpenAPITypesafeError({
53
55
  code: errors.ERROR_CODES.SCHEMA_INVALID,
54
56
  message: problems.at(-1) ?? "",
55
- details: { problems: [...problems] }
57
+ details: { problems: problems.map(urlCredentials.redactUrlCredentials) }
56
58
  });
57
59
  }
58
60
  function refCycleError(cause) {
@@ -66,12 +68,28 @@ function refCycleError(cause) {
66
68
  function hostListText(hosts) {
67
69
  return hosts.length === 0 ? "none" : hosts.join(", ");
68
70
  }
71
+ function limitText(details) {
72
+ switch (details.reason) {
73
+ case "outside-local-root":
74
+ return `it is outside the local $ref root ${details.localRoot}`;
75
+ case "host-not-allowed": {
76
+ const hosts = hostListText(details.allowedHosts);
77
+ return `its host is not in the allowed remote $ref hosts (${hosts})`;
78
+ }
79
+ case "local-ref-from-remote":
80
+ return `it is not an http(s) URL, and the $ref is in the remote document ${details.base}`;
81
+ case "too-many-remote-documents":
82
+ return `the document refers to more than ${details.maxDocuments} remote documents`;
83
+ default:
84
+ return assertNever.assertNever(details);
85
+ }
86
+ }
69
87
  function refForbiddenError(ref, details) {
70
- const limit = details.reason === "outside-local-root" ? `it is outside the local $ref root ${details.localRoot}` : `its host is not in the allowed remote $ref hosts (${hostListText(details.allowedHosts)})`;
88
+ const limit = limitText(details);
71
89
  return new errors.OpenAPITypesafeError({
72
90
  code: errors.ERROR_CODES.SCHEMA_REF_FORBIDDEN,
73
91
  message: `Refused to load ${ref}: ${limit}`,
74
- details: { ref, ...details }
92
+ details: { ref: urlCredentials.redactUrlCredentials(ref), ...details }
75
93
  });
76
94
  }
77
95
 
@@ -1 +1 @@
1
- {"version":3,"file":"schema-load-errors.cjs","sources":["../../../src/adapters/redocly-loader/schema-load-errors.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\n\n/**\n * The typed errors of loading, validating and bundling a document (ADR-011). Messages are the\n * original messages, so Node API users who match on them keep working.\n */\n\n/** No source was given, or the source is empty. */\nexport function sourceEmptyError(message: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });\n}\n\n/** The source is neither a URL, text, buffer, stream nor plain object. */\nexport function sourceInvalidError(source: unknown): OpenAPITypesafeError {\n const received = Array.isArray(source) ? \"Array\" : typeof source;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message: `Expected string, object, or Buffer. Got ${received}`,\n details: { received },\n });\n}\n\nfunction causeMessage(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n\n/** Enough of a source string to recognise it in the message. */\nconst SOURCE_TEXT_IN_MESSAGE = 200;\n\n/**\n * A string source is document text, so a file path parses as a YAML string scalar, not as a\n * document (docs/node.md). The message says how to load the file instead.\n */\nexport function pathStringError(text: string): OpenAPITypesafeError {\n const shown =\n text.length > SOURCE_TEXT_IN_MESSAGE ? `${text.slice(0, SOURCE_TEXT_IN_MESSAGE)}…` : text;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message:\n `The string \"${shown}\" was parsed as YAML text, not loaded as a file. ` +\n \"To load a file, pass a URL: openapiTS(pathToFileURL(path)) from node:url.\",\n details: { reason: \"path\", received: \"string\" },\n });\n}\n\n/** Reading the document from a file or URL failed; the message is the reader's message. */\nexport function loadFailedError(absoluteRef: string, cause: unknown): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_LOAD_FAILED,\n message: causeMessage(cause),\n details: { source: absoluteRef },\n cause,\n });\n}\n\n/** The document text is not valid JSON or YAML; the message is the parser's message. */\nexport function parseFailedError(\n format: \"json\" | \"yaml\",\n absoluteRef: string,\n cause: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_PARSE_FAILED,\n message: causeMessage(cause),\n details: { format, source: absoluteRef },\n cause,\n });\n}\n\n/** The document is not OpenAPI 3.x. */\nexport function versionUnsupportedError(\n message: string,\n parsed: Readonly<Record<string, unknown>>,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_VERSION_UNSUPPORTED,\n message,\n details: { openapi: parsed.openapi, swagger: parsed.swagger },\n });\n}\n\n/**\n * Linting or bundling found errors. The message is the last error, as in the original; all error\n * messages are in `details.problems`.\n */\nexport function schemaInvalidError(problems: readonly string[]): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_INVALID,\n message: problems.at(-1) ?? \"\",\n details: { problems: [...problems] },\n });\n}\n\n/** A `$ref` chain points back to itself with no schema in between (`A: $ref B`, `B: $ref A`). */\nexport function refCycleError(cause: Error): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: cause.message,\n details: { reason: \"cycle\" },\n cause,\n });\n}\n\nfunction hostListText(hosts: readonly string[]): string {\n return hosts.length === 0 ? \"none\" : hosts.join(\", \");\n}\n\n/** Why a `$ref` document was refused, with the limit it broke (ADR-017). */\nexport type RefRefusalDetails =\n | { readonly reason: \"outside-local-root\"; readonly localRoot: string }\n | { readonly reason: \"host-not-allowed\"; readonly allowedHosts: readonly string[] };\n\n/** A `$ref` is outside the local root, or its host is not allowed (threat model R1, R2). */\nexport function refForbiddenError(ref: string, details: RefRefusalDetails): OpenAPITypesafeError {\n const limit =\n details.reason === \"outside-local-root\"\n ? `it is outside the local $ref root ${details.localRoot}`\n : `its host is not in the allowed remote $ref hosts (${hostListText(details.allowedHosts)})`;\n return new OpenAPITypesafeError({\n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,EAAkC;AACtD,EAAA,OAAO,MAAM,MAAA,KAAW,CAAA,GAAI,MAAA,GAAS,KAAA,CAAM,KAAK,IAAI,CAAA;AACtD;AAQO,SAAS,iBAAA,CAAkB,KAAa,OAAA,EAAkD;AAC/F,EAAA,MAAM,KAAA,GACJ,OAAA,CAAQ,MAAA,KAAW,oBAAA,GACf,CAAA,kCAAA,EAAqC,OAAA,CAAQ,SAAS,CAAA,CAAA,GACtD,CAAA,kDAAA,EAAqD,YAAA,CAAa,OAAA,CAAQ,YAAY,CAAC,CAAA,CAAA,CAAA;AAC7F,EAAA,OAAO,IAAID,2BAAA,CAAqB;AAAA,IAC9B,MAAMC,kBAAA,CAAY,oBAAA;AAAA,IAClB,OAAA,EAAS,CAAA,gBAAA,EAAmB,GAAG,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AAAA,IACzC,OAAA,EAAS,EAAE,GAAA,EAAK,GAAG,OAAA;AAAQ,GAC5B,CAAA;AACH;;;;;;;;;;"}
1
+ {"version":3,"file":"schema-load-errors.cjs","sources":["../../../src/adapters/redocly-loader/schema-load-errors.ts"],"sourcesContent":["import { assertNever } from \"../../domain/assert-never.js\";\nimport { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport { redactUrlCredentials } from \"../../domain/url-credentials.js\";\n\n/**\n * The typed errors of loading, validating and bundling a document (ADR-011). Messages are the\n * original messages, so Node API users who match on them keep working; URLs in them and in the\n * details never show user info.\n */\n\n/** No source was given, or the source is empty. */\nexport function sourceEmptyError(message: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });\n}\n\n/** The source is neither a URL, text, buffer, stream nor plain object. */\nexport function sourceInvalidError(source: unknown): OpenAPITypesafeError {\n const received = Array.isArray(source) ? \"Array\" : typeof source;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message: `Expected string, object, or Buffer. Got ${received}`,\n details: { received },\n });\n}\n\nfunction causeMessage(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n\n/** Enough of a source string to recognise it in the message. */\nconst SOURCE_TEXT_IN_MESSAGE = 200;\n\n/**\n * A string source is document text, so a file path parses as a YAML string scalar, not as a\n * document (docs/node.md). The message says how to load the file instead.\n */\nexport function pathStringError(text: string): OpenAPITypesafeError {\n const shown =\n text.length > SOURCE_TEXT_IN_MESSAGE ? `${text.slice(0, SOURCE_TEXT_IN_MESSAGE)}…` : text;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message:\n `The string \"${shown}\" was parsed as YAML text, not loaded as a file. ` +\n \"To load a file, pass a URL: openapiTS(pathToFileURL(path)) from node:url.\",\n details: { reason: \"path\", received: \"string\" },\n });\n}\n\n/** Reading the document from a file or URL failed; the message is the reader's message. */\nexport function loadFailedError(absoluteRef: string, cause: unknown): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_LOAD_FAILED,\n message: causeMessage(cause),\n details: { source: redactUrlCredentials(absoluteRef) },\n cause,\n });\n}\n\n/** The document text is not valid JSON or YAML; the message is the parser's message. */\nexport function parseFailedError(\n format: \"json\" | \"yaml\",\n absoluteRef: string,\n cause: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_PARSE_FAILED,\n message: causeMessage(cause),\n details: { format, source: redactUrlCredentials(absoluteRef) },\n cause,\n });\n}\n\n/** The document is not OpenAPI 3.x. */\nexport function versionUnsupportedError(\n message: string,\n parsed: Readonly<Record<string, unknown>>,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_VERSION_UNSUPPORTED,\n message,\n details: { openapi: parsed.openapi, swagger: parsed.swagger },\n });\n}\n\n/**\n * Linting or bundling found errors. The message is the last error, as in the original; all error\n * messages are in `details.problems`.\n */\nexport function schemaInvalidError(problems: readonly string[]): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_INVALID,\n message: problems.at(-1) ?? \"\",\n details: { problems: problems.map(redactUrlCredentials) },\n });\n}\n\n/** A `$ref` chain points back to itself with no schema in between (`A: $ref B`, `B: $ref A`). */\nexport function refCycleError(cause: Error): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: cause.message,\n details: { reason: \"cycle\" },\n cause,\n });\n}\n\nfunction hostListText(hosts: readonly string[]): string {\n return hosts.length === 0 ? \"none\" : hosts.join(\", \");\n}\n\n/** Why a `$ref` document was refused, with the limit it broke (ADR-017). */\nexport type RefRefusalDetails =\n | { readonly reason: \"outside-local-root\"; readonly localRoot: string }\n | { readonly reason: \"host-not-allowed\"; readonly allowedHosts: readonly string[] }\n | { readonly reason: \"local-ref-from-remote\"; readonly base: string }\n | { readonly reason: \"too-many-remote-documents\"; readonly maxDocuments: number };\n\nfunction limitText(details: RefRefusalDetails): string {\n switch (details.reason) {\n case \"outside-local-root\":\n return `it is outside the local $ref root ${details.localRoot}`;\n case \"host-not-allowed\": {\n const hosts = hostListText(details.allowedHosts);\n return `its host is not in the allowed remote $ref hosts (${hosts})`;\n }\n case \"local-ref-from-remote\":\n return `it is not an http(s) URL, and the $ref is in the remote document ${details.base}`;\n case \"too-many-remote-documents\":\n return `the document refers to more than ${details.maxDocuments} remote documents`;\n default:\n return assertNever(details);\n }\n}\n\n/**\n * A `$ref` is outside the local root, its host is not allowed (threat model R1, R2), a remote\n * document refers to a local file (T3), or there are too many remote documents (T2).\n */\nexport function refForbiddenError(ref: string, details: RefRefusalDetails): OpenAPITypesafeError {\n const limit = limitText(details);\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_FORBIDDEN,\n message: `Refused to load ${ref}: ${limit}`,\n details: { ref: redactUrlCredentials(ref), ...details },\n });\n}\n"],"names":["OpenAPITypesafeError","ERROR_CODES","redactUrlCredentials","assertNever"],"mappings":";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,CAAM,KAAK,IAAI,CAAA;AACtD;AASA,SAAS,UAAU,OAAA,EAAoC;AACrD,EAAA,QAAQ,QAAQ,MAAA;AAAQ,IACtB,KAAK,oBAAA;AACH,MAAA,OAAO,CAAA,kCAAA,EAAqC,QAAQ,SAAS,CAAA,CAAA;AAAA,IAC/D,KAAK,kBAAA,EAAoB;AACvB,MAAA,MAAM,KAAA,GAAQ,YAAA,CAAa,OAAA,CAAQ,YAAY,CAAA;AAC/C,MAAA,OAAO,qDAAqD,KAAK,CAAA,CAAA,CAAA;AAAA,IACnE;AAAA,IACA,KAAK,uBAAA;AACH,MAAA,OAAO,CAAA,iEAAA,EAAoE,QAAQ,IAAI,CAAA,CAAA;AAAA,IACzF,KAAK,2BAAA;AACH,MAAA,OAAO,CAAA,iCAAA,EAAoC,QAAQ,YAAY,CAAA,iBAAA,CAAA;AAAA,IACjE;AACE,MAAA,OAAOE,wBAAY,OAAO,CAAA;AAAA;AAEhC;AAMO,SAAS,iBAAA,CAAkB,KAAa,OAAA,EAAkD;AAC/F,EAAA,MAAM,KAAA,GAAQ,UAAU,OAAO,CAAA;AAC/B,EAAA,OAAO,IAAIH,2BAAA,CAAqB;AAAA,IAC9B,MAAMC,kBAAA,CAAY,oBAAA;AAAA,IAClB,OAAA,EAAS,CAAA,gBAAA,EAAmB,GAAG,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AAAA,IACzC,SAAS,EAAE,GAAA,EAAKC,oCAAqB,GAAG,CAAA,EAAG,GAAG,OAAA;AAAQ,GACvD,CAAA;AACH;;;;;;;;;;"}
@@ -1,4 +1,6 @@
1
+ import { assertNever } from '../../domain/assert-never.mjs';
1
2
  import { OpenAPITypesafeError, ERROR_CODES } from '../../domain/errors.mjs';
3
+ import { redactUrlCredentials } from '../../domain/url-credentials.mjs';
2
4
 
3
5
  function sourceEmptyError(message) {
4
6
  return new OpenAPITypesafeError({ code: ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });
@@ -27,7 +29,7 @@ function loadFailedError(absoluteRef, cause) {
27
29
  return new OpenAPITypesafeError({
28
30
  code: ERROR_CODES.SCHEMA_LOAD_FAILED,
29
31
  message: causeMessage(cause),
30
- details: { source: absoluteRef },
32
+ details: { source: redactUrlCredentials(absoluteRef) },
31
33
  cause
32
34
  });
33
35
  }
@@ -35,7 +37,7 @@ function parseFailedError(format, absoluteRef, cause) {
35
37
  return new OpenAPITypesafeError({
36
38
  code: ERROR_CODES.SCHEMA_PARSE_FAILED,
37
39
  message: causeMessage(cause),
38
- details: { format, source: absoluteRef },
40
+ details: { format, source: redactUrlCredentials(absoluteRef) },
39
41
  cause
40
42
  });
41
43
  }
@@ -50,7 +52,7 @@ function schemaInvalidError(problems) {
50
52
  return new OpenAPITypesafeError({
51
53
  code: ERROR_CODES.SCHEMA_INVALID,
52
54
  message: problems.at(-1) ?? "",
53
- details: { problems: [...problems] }
55
+ details: { problems: problems.map(redactUrlCredentials) }
54
56
  });
55
57
  }
56
58
  function refCycleError(cause) {
@@ -64,12 +66,28 @@ function refCycleError(cause) {
64
66
  function hostListText(hosts) {
65
67
  return hosts.length === 0 ? "none" : hosts.join(", ");
66
68
  }
69
+ function limitText(details) {
70
+ switch (details.reason) {
71
+ case "outside-local-root":
72
+ return `it is outside the local $ref root ${details.localRoot}`;
73
+ case "host-not-allowed": {
74
+ const hosts = hostListText(details.allowedHosts);
75
+ return `its host is not in the allowed remote $ref hosts (${hosts})`;
76
+ }
77
+ case "local-ref-from-remote":
78
+ return `it is not an http(s) URL, and the $ref is in the remote document ${details.base}`;
79
+ case "too-many-remote-documents":
80
+ return `the document refers to more than ${details.maxDocuments} remote documents`;
81
+ default:
82
+ return assertNever(details);
83
+ }
84
+ }
67
85
  function refForbiddenError(ref, details) {
68
- const limit = details.reason === "outside-local-root" ? `it is outside the local $ref root ${details.localRoot}` : `its host is not in the allowed remote $ref hosts (${hostListText(details.allowedHosts)})`;
86
+ const limit = limitText(details);
69
87
  return new OpenAPITypesafeError({
70
88
  code: ERROR_CODES.SCHEMA_REF_FORBIDDEN,
71
89
  message: `Refused to load ${ref}: ${limit}`,
72
- details: { ref, ...details }
90
+ details: { ref: redactUrlCredentials(ref), ...details }
73
91
  });
74
92
  }
75
93
 
@@ -1 +1 @@
1
- {"version":3,"file":"schema-load-errors.mjs","sources":["../../../src/adapters/redocly-loader/schema-load-errors.ts"],"sourcesContent":["import { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\n\n/**\n * The typed errors of loading, validating and bundling a document (ADR-011). Messages are the\n * original messages, so Node API users who match on them keep working.\n */\n\n/** No source was given, or the source is empty. */\nexport function sourceEmptyError(message: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });\n}\n\n/** The source is neither a URL, text, buffer, stream nor plain object. */\nexport function sourceInvalidError(source: unknown): OpenAPITypesafeError {\n const received = Array.isArray(source) ? \"Array\" : typeof source;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message: `Expected string, object, or Buffer. Got ${received}`,\n details: { received },\n });\n}\n\nfunction causeMessage(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n\n/** Enough of a source string to recognise it in the message. */\nconst SOURCE_TEXT_IN_MESSAGE = 200;\n\n/**\n * A string source is document text, so a file path parses as a YAML string scalar, not as a\n * document (docs/node.md). The message says how to load the file instead.\n */\nexport function pathStringError(text: string): OpenAPITypesafeError {\n const shown =\n text.length > SOURCE_TEXT_IN_MESSAGE ? `${text.slice(0, SOURCE_TEXT_IN_MESSAGE)}…` : text;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message:\n `The string \"${shown}\" was parsed as YAML text, not loaded as a file. ` +\n \"To load a file, pass a URL: openapiTS(pathToFileURL(path)) from node:url.\",\n details: { reason: \"path\", received: \"string\" },\n });\n}\n\n/** Reading the document from a file or URL failed; the message is the reader's message. */\nexport function loadFailedError(absoluteRef: string, cause: unknown): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_LOAD_FAILED,\n message: causeMessage(cause),\n details: { source: absoluteRef },\n cause,\n });\n}\n\n/** The document text is not valid JSON or YAML; the message is the parser's message. */\nexport function parseFailedError(\n format: \"json\" | \"yaml\",\n absoluteRef: string,\n cause: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_PARSE_FAILED,\n message: causeMessage(cause),\n details: { format, source: absoluteRef },\n cause,\n });\n}\n\n/** The document is not OpenAPI 3.x. */\nexport function versionUnsupportedError(\n message: string,\n parsed: Readonly<Record<string, unknown>>,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_VERSION_UNSUPPORTED,\n message,\n details: { openapi: parsed.openapi, swagger: parsed.swagger },\n });\n}\n\n/**\n * Linting or bundling found errors. The message is the last error, as in the original; all error\n * messages are in `details.problems`.\n */\nexport function schemaInvalidError(problems: readonly string[]): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_INVALID,\n message: problems.at(-1) ?? \"\",\n details: { problems: [...problems] },\n });\n}\n\n/** A `$ref` chain points back to itself with no schema in between (`A: $ref B`, `B: $ref A`). */\nexport function refCycleError(cause: Error): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: cause.message,\n details: { reason: \"cycle\" },\n cause,\n });\n}\n\nfunction hostListText(hosts: readonly string[]): string {\n return hosts.length === 0 ? \"none\" : hosts.join(\", \");\n}\n\n/** Why a `$ref` document was refused, with the limit it broke (ADR-017). */\nexport type RefRefusalDetails =\n | { readonly reason: \"outside-local-root\"; readonly localRoot: string }\n | { readonly reason: \"host-not-allowed\"; readonly allowedHosts: readonly string[] };\n\n/** A `$ref` is outside the local root, or its host is not allowed (threat model R1, R2). */\nexport function refForbiddenError(ref: string, details: RefRefusalDetails): OpenAPITypesafeError {\n const limit =\n details.reason === \"outside-local-root\"\n ? `it is outside the local $ref root ${details.localRoot}`\n : `its host is not in the allowed remote $ref hosts (${hostListText(details.allowedHosts)})`;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_FORBIDDEN,\n message: `Refused to load ${ref}: ${limit}`,\n details: { ref, ...details },\n });\n}\n"],"names":[],"mappings":";;AAQO,SAAS,iBAAiB,OAAA,EAAuC;AACtE,EAAA,OAAO,IAAI,oBAAA,CAAqB,EAAE,MAAM,WAAA,CAAY,mBAAA,EAAqB,SAAS,CAAA;AACpF;AAGO,SAAS,mBAAmB,MAAA,EAAuC;AACxE,EAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,MAAM,CAAA,GAAI,UAAU,OAAO,MAAA;AAC1D,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,qBAAA;AAAA,IAClB,OAAA,EAAS,2CAA2C,QAAQ,CAAA,CAAA;AAAA,IAC5D,OAAA,EAAS,EAAE,QAAA;AAAS,GACrB,CAAA;AACH;AAEA,SAAS,aAAa,KAAA,EAAwB;AAC5C,EAAA,OAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAC9D;AAGA,MAAM,sBAAA,GAAyB,GAAA;AAMxB,SAAS,gBAAgB,IAAA,EAAoC;AAClE,EAAA,MAAM,KAAA,GACJ,IAAA,CAAK,MAAA,GAAS,sBAAA,GAAyB,CAAA,EAAG,KAAK,KAAA,CAAM,CAAA,EAAG,sBAAsB,CAAC,CAAA,MAAA,CAAA,GAAM,IAAA;AACvF,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,qBAAA;AAAA,IAClB,OAAA,EACE,eAAe,KAAK,CAAA,0HAAA,CAAA;AAAA,IAEtB,OAAA,EAAS,EAAE,MAAA,EAAQ,MAAA,EAAQ,UAAU,QAAA;A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EAAE,MAAA,EAAQ,OAAA,EAAQ;AAAA,IAC3B;AAAA,GACD,CAAA;AACH;AAEA,SAAS,aAAa,KAAA,EAAkC;AACtD,EAAA,OAAO,MAAM,MAAA,KAAW,CAAA,GAAI,MAAA,GAAS,KAAA,CAAM,KAAK,IAAI,CAAA;AACtD;AAQO,SAAS,iBAAA,CAAkB,KAAa,OAAA,EAAkD;AAC/F,EAAA,MAAM,KAAA,GACJ,OAAA,CAAQ,MAAA,KAAW,oBAAA,GACf,CAAA,kCAAA,EAAqC,OAAA,CAAQ,SAAS,CAAA,CAAA,GACtD,CAAA,kDAAA,EAAqD,YAAA,CAAa,OAAA,CAAQ,YAAY,CAAC,CAAA,CAAA,CAAA;AAC7F,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,oBAAA;AAAA,IAClB,OAAA,EAAS,CAAA,gBAAA,EAAmB,GAAG,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AAAA,IACzC,OAAA,EAAS,EAAE,GAAA,EAAK,GAAG,OAAA;AAAQ,GAC5B,CAAA;AACH;;"}
1
+ {"version":3,"file":"schema-load-errors.mjs","sources":["../../../src/adapters/redocly-loader/schema-load-errors.ts"],"sourcesContent":["import { assertNever } from \"../../domain/assert-never.js\";\nimport { ERROR_CODES, OpenAPITypesafeError } from \"../../domain/errors.js\";\nimport { redactUrlCredentials } from \"../../domain/url-credentials.js\";\n\n/**\n * The typed errors of loading, validating and bundling a document (ADR-011). Messages are the\n * original messages, so Node API users who match on them keep working; URLs in them and in the\n * details never show user info.\n */\n\n/** No source was given, or the source is empty. */\nexport function sourceEmptyError(message: string): OpenAPITypesafeError {\n return new OpenAPITypesafeError({ code: ERROR_CODES.SCHEMA_SOURCE_EMPTY, message });\n}\n\n/** The source is neither a URL, text, buffer, stream nor plain object. */\nexport function sourceInvalidError(source: unknown): OpenAPITypesafeError {\n const received = Array.isArray(source) ? \"Array\" : typeof source;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message: `Expected string, object, or Buffer. Got ${received}`,\n details: { received },\n });\n}\n\nfunction causeMessage(cause: unknown): string {\n return cause instanceof Error ? cause.message : String(cause);\n}\n\n/** Enough of a source string to recognise it in the message. */\nconst SOURCE_TEXT_IN_MESSAGE = 200;\n\n/**\n * A string source is document text, so a file path parses as a YAML string scalar, not as a\n * document (docs/node.md). The message says how to load the file instead.\n */\nexport function pathStringError(text: string): OpenAPITypesafeError {\n const shown =\n text.length > SOURCE_TEXT_IN_MESSAGE ? `${text.slice(0, SOURCE_TEXT_IN_MESSAGE)}…` : text;\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_SOURCE_INVALID,\n message:\n `The string \"${shown}\" was parsed as YAML text, not loaded as a file. ` +\n \"To load a file, pass a URL: openapiTS(pathToFileURL(path)) from node:url.\",\n details: { reason: \"path\", received: \"string\" },\n });\n}\n\n/** Reading the document from a file or URL failed; the message is the reader's message. */\nexport function loadFailedError(absoluteRef: string, cause: unknown): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_LOAD_FAILED,\n message: causeMessage(cause),\n details: { source: redactUrlCredentials(absoluteRef) },\n cause,\n });\n}\n\n/** The document text is not valid JSON or YAML; the message is the parser's message. */\nexport function parseFailedError(\n format: \"json\" | \"yaml\",\n absoluteRef: string,\n cause: unknown,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_PARSE_FAILED,\n message: causeMessage(cause),\n details: { format, source: redactUrlCredentials(absoluteRef) },\n cause,\n });\n}\n\n/** The document is not OpenAPI 3.x. */\nexport function versionUnsupportedError(\n message: string,\n parsed: Readonly<Record<string, unknown>>,\n): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_VERSION_UNSUPPORTED,\n message,\n details: { openapi: parsed.openapi, swagger: parsed.swagger },\n });\n}\n\n/**\n * Linting or bundling found errors. The message is the last error, as in the original; all error\n * messages are in `details.problems`.\n */\nexport function schemaInvalidError(problems: readonly string[]): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_INVALID,\n message: problems.at(-1) ?? \"\",\n details: { problems: problems.map(redactUrlCredentials) },\n });\n}\n\n/** A `$ref` chain points back to itself with no schema in between (`A: $ref B`, `B: $ref A`). */\nexport function refCycleError(cause: Error): OpenAPITypesafeError {\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_INVALID,\n message: cause.message,\n details: { reason: \"cycle\" },\n cause,\n });\n}\n\nfunction hostListText(hosts: readonly string[]): string {\n return hosts.length === 0 ? \"none\" : hosts.join(\", \");\n}\n\n/** Why a `$ref` document was refused, with the limit it broke (ADR-017). */\nexport type RefRefusalDetails =\n | { readonly reason: \"outside-local-root\"; readonly localRoot: string }\n | { readonly reason: \"host-not-allowed\"; readonly allowedHosts: readonly string[] }\n | { readonly reason: \"local-ref-from-remote\"; readonly base: string }\n | { readonly reason: \"too-many-remote-documents\"; readonly maxDocuments: number };\n\nfunction limitText(details: RefRefusalDetails): string {\n switch (details.reason) {\n case \"outside-local-root\":\n return `it is outside the local $ref root ${details.localRoot}`;\n case \"host-not-allowed\": {\n const hosts = hostListText(details.allowedHosts);\n return `its host is not in the allowed remote $ref hosts (${hosts})`;\n }\n case \"local-ref-from-remote\":\n return `it is not an http(s) URL, and the $ref is in the remote document ${details.base}`;\n case \"too-many-remote-documents\":\n return `the document refers to more than ${details.maxDocuments} remote documents`;\n default:\n return assertNever(details);\n }\n}\n\n/**\n * A `$ref` is outside the local root, its host is not allowed (threat model R1, R2), a remote\n * document refers to a local file (T3), or there are too many remote documents (T2).\n */\nexport function refForbiddenError(ref: string, details: RefRefusalDetails): OpenAPITypesafeError {\n const limit = limitText(details);\n return new OpenAPITypesafeError({\n code: ERROR_CODES.SCHEMA_REF_FORBIDDEN,\n message: `Refused to load ${ref}: ${limit}`,\n details: { ref: redactUrlCredentials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S,KAAA,CAAM,KAAK,IAAI,CAAA;AACtD;AASA,SAAS,UAAU,OAAA,EAAoC;AACrD,EAAA,QAAQ,QAAQ,MAAA;AAAQ,IACtB,KAAK,oBAAA;AACH,MAAA,OAAO,CAAA,kCAAA,EAAqC,QAAQ,SAAS,CAAA,CAAA;AAAA,IAC/D,KAAK,kBAAA,EAAoB;AACvB,MAAA,MAAM,KAAA,GAAQ,YAAA,CAAa,OAAA,CAAQ,YAAY,CAAA;AAC/C,MAAA,OAAO,qDAAqD,KAAK,CAAA,CAAA,CAAA;AAAA,IACnE;AAAA,IACA,KAAK,uBAAA;AACH,MAAA,OAAO,CAAA,iEAAA,EAAoE,QAAQ,IAAI,CAAA,CAAA;AAAA,IACzF,KAAK,2BAAA;AACH,MAAA,OAAO,CAAA,iCAAA,EAAoC,QAAQ,YAAY,CAAA,iBAAA,CAAA;AAAA,IACjE;AACE,MAAA,OAAO,YAAY,OAAO,CAAA;AAAA;AAEhC;AAMO,SAAS,iBAAA,CAAkB,KAAa,OAAA,EAAkD;AAC/F,EAAA,MAAM,KAAA,GAAQ,UAAU,OAAO,CAAA;AAC/B,EAAA,OAAO,IAAI,oBAAA,CAAqB;AAAA,IAC9B,MAAM,WAAA,CAAY,oBAAA;AAAA,IAClB,OAAA,EAAS,CAAA,gBAAA,EAAmB,GAAG,CAAA,EAAA,EAAK,KAAK,CAAA,CAAA;AAAA,IACzC,SAAS,EAAE,GAAA,EAAK,qBAAqB,GAAG,CAAA,EAAG,GAAG,OAAA;AAAQ,GACvD,CAAA;AACH;;"}
@@ -13,6 +13,14 @@ const UNSUPPORTED_KEYS = /* @__PURE__ */ new Set([
13
13
  "__lookupGetter__",
14
14
  "__lookupSetter__"
15
15
  ]);
16
+ const CONSTRUCTOR_KEY = "constructor";
17
+ function isUnsupportedEntry(key, value) {
18
+ if (UNSUPPORTED_KEYS.has(key)) {
19
+ return true;
20
+ }
21
+ const name = value?.name;
22
+ return key === CONSTRUCTOR_KEY && typeof value === "object" && typeof name === "string";
23
+ }
16
24
  const KEYS_IN_MESSAGE = 5;
17
25
  function escapePointerSegment(segment) {
18
26
  return segment.replaceAll("~", "~0").replaceAll("/", "~1");
@@ -31,7 +39,7 @@ function unsupportedKeysOf(document) {
31
39
  for (let node = pending.pop(); node !== void 0; node = pending.pop()) {
32
40
  for (const [key, child] of Object.entries(node.value)) {
33
41
  const pointer = `${node.pointer}/${escapePointerSegment(key)}`;
34
- if (UNSUPPORTED_KEYS.has(key)) {
42
+ if (isUnsupportedEntry(key, child)) {
35
43
  found.push({ key, pointer, source: document.source });
36
44
  }
37
45
  enqueue(child, pointer);