openapi-typesafe 1.0.0-rc.4 → 1.0.0-rc.6

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 (366) hide show
  1. package/CHANGELOG.md +214 -0
  2. package/dist/adapters/node-file-system/node-file-system.cjs +7 -0
  3. package/dist/adapters/node-file-system/node-file-system.cjs.map +1 -1
  4. package/dist/adapters/node-file-system/node-file-system.mjs +7 -0
  5. package/dist/adapters/node-file-system/node-file-system.mjs.map +1 -1
  6. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs +19 -0
  7. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.cjs.map +1 -0
  8. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs +17 -0
  9. package/dist/adapters/pipe-safe-writer/pipe-safe-writer.mjs.map +1 -0
  10. package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs +5 -32
  11. package/dist/adapters/redocly-loader/bundled-mapping-copies.cjs.map +1 -1
  12. package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs +6 -33
  13. package/dist/adapters/redocly-loader/bundled-mapping-copies.mjs.map +1 -1
  14. package/dist/adapters/redocly-loader/component-schemas.cjs +17 -0
  15. package/dist/adapters/redocly-loader/component-schemas.cjs.map +1 -0
  16. package/dist/adapters/redocly-loader/component-schemas.mjs +14 -0
  17. package/dist/adapters/redocly-loader/component-schemas.mjs.map +1 -0
  18. package/dist/adapters/redocly-loader/mapping-schema-names.cjs +22 -0
  19. package/dist/adapters/redocly-loader/mapping-schema-names.cjs.map +1 -0
  20. package/dist/adapters/redocly-loader/mapping-schema-names.mjs +20 -0
  21. package/dist/adapters/redocly-loader/mapping-schema-names.mjs.map +1 -0
  22. package/dist/adapters/redocly-loader/query-document-names.cjs +50 -0
  23. package/dist/adapters/redocly-loader/query-document-names.cjs.map +1 -0
  24. package/dist/adapters/redocly-loader/query-document-names.mjs +48 -0
  25. package/dist/adapters/redocly-loader/query-document-names.mjs.map +1 -0
  26. package/dist/adapters/redocly-loader/query-named-components.cjs +129 -0
  27. package/dist/adapters/redocly-loader/query-named-components.cjs.map +1 -0
  28. package/dist/adapters/redocly-loader/query-named-components.mjs +126 -0
  29. package/dist/adapters/redocly-loader/query-named-components.mjs.map +1 -0
  30. package/dist/adapters/redocly-loader/redocly-config-source.cjs +3 -0
  31. package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -1
  32. package/dist/adapters/redocly-loader/redocly-config-source.mjs +4 -1
  33. package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -1
  34. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +39 -18
  35. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  36. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +40 -19
  37. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  38. package/dist/adapters/redocly-loader/ref-access.cjs +25 -4
  39. package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
  40. package/dist/adapters/redocly-loader/ref-access.mjs +26 -5
  41. package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
  42. package/dist/adapters/redocly-loader/ref-holders.cjs +52 -10
  43. package/dist/adapters/redocly-loader/ref-holders.cjs.map +1 -1
  44. package/dist/adapters/redocly-loader/ref-holders.mjs +52 -11
  45. package/dist/adapters/redocly-loader/ref-holders.mjs.map +1 -1
  46. package/dist/adapters/redocly-loader/remote-fetch.cjs +20 -3
  47. package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
  48. package/dist/adapters/redocly-loader/remote-fetch.mjs +20 -4
  49. package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
  50. package/dist/adapters/redocly-loader/remote-node-limit.cjs +17 -3
  51. package/dist/adapters/redocly-loader/remote-node-limit.cjs.map +1 -1
  52. package/dist/adapters/redocly-loader/remote-node-limit.mjs +17 -3
  53. package/dist/adapters/redocly-loader/remote-node-limit.mjs.map +1 -1
  54. package/dist/adapters/redocly-loader/schema-source.cjs +7 -2
  55. package/dist/adapters/redocly-loader/schema-source.cjs.map +1 -1
  56. package/dist/adapters/redocly-loader/schema-source.mjs +8 -3
  57. package/dist/adapters/redocly-loader/schema-source.mjs.map +1 -1
  58. package/dist/adapters/terminal-logger/terminal-logger.cjs +7 -3
  59. package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
  60. package/dist/adapters/terminal-logger/terminal-logger.mjs +7 -3
  61. package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
  62. package/dist/api/cwd-option.cjs +58 -0
  63. package/dist/api/cwd-option.cjs.map +1 -0
  64. package/dist/api/cwd-option.mjs +52 -0
  65. package/dist/api/cwd-option.mjs.map +1 -0
  66. package/dist/api/default-ports.cjs +15 -7
  67. package/dist/api/default-ports.cjs.map +1 -1
  68. package/dist/api/default-ports.mjs +14 -8
  69. package/dist/api/default-ports.mjs.map +1 -1
  70. package/dist/api/document-refs.cjs +16 -1
  71. package/dist/api/document-refs.cjs.map +1 -1
  72. package/dist/api/document-refs.mjs +16 -1
  73. package/dist/api/document-refs.mjs.map +1 -1
  74. package/dist/api/document-run.cjs +6 -26
  75. package/dist/api/document-run.cjs.map +1 -1
  76. package/dist/api/document-run.mjs +5 -21
  77. package/dist/api/document-run.mjs.map +1 -1
  78. package/dist/api/legacy-utils.cjs +1 -1
  79. package/dist/api/legacy-utils.cjs.map +1 -1
  80. package/dist/api/legacy-utils.mjs +1 -1
  81. package/dist/api/legacy-utils.mjs.map +1 -1
  82. package/dist/api/openapi-ts.cjs +1 -2
  83. package/dist/api/openapi-ts.cjs.map +1 -1
  84. package/dist/api/openapi-ts.mjs +2 -3
  85. package/dist/api/openapi-ts.mjs.map +1 -1
  86. package/dist/api/option-errors.cjs +24 -0
  87. package/dist/api/option-errors.cjs.map +1 -0
  88. package/dist/api/option-errors.mjs +21 -0
  89. package/dist/api/option-errors.mjs.map +1 -0
  90. package/dist/api/ref-limit-options.cjs +58 -0
  91. package/dist/api/ref-limit-options.cjs.map +1 -0
  92. package/dist/api/ref-limit-options.mjs +52 -0
  93. package/dist/api/ref-limit-options.mjs.map +1 -0
  94. package/dist/api/transform-schema.cjs +12 -5
  95. package/dist/api/transform-schema.cjs.map +1 -1
  96. package/dist/api/transform-schema.mjs +12 -5
  97. package/dist/api/transform-schema.mjs.map +1 -1
  98. package/dist/application/transform/declared-value-types.cjs +36 -0
  99. package/dist/application/transform/declared-value-types.cjs.map +1 -0
  100. package/dist/application/transform/declared-value-types.mjs +34 -0
  101. package/dist/application/transform/declared-value-types.mjs.map +1 -0
  102. package/dist/application/transform/document/document.cjs +3 -1
  103. package/dist/application/transform/document/document.cjs.map +1 -1
  104. package/dist/application/transform/document/document.mjs +3 -1
  105. package/dist/application/transform/document/document.mjs.map +1 -1
  106. package/dist/application/transform/document/exploded-query-values.cjs +63 -0
  107. package/dist/application/transform/document/exploded-query-values.cjs.map +1 -0
  108. package/dist/application/transform/document/exploded-query-values.mjs +59 -0
  109. package/dist/application/transform/document/exploded-query-values.mjs.map +1 -0
  110. package/dist/application/transform/document/header.cjs +11 -3
  111. package/dist/application/transform/document/header.cjs.map +1 -1
  112. package/dist/application/transform/document/header.mjs +10 -2
  113. package/dist/application/transform/document/header.mjs.map +1 -1
  114. package/dist/application/transform/document/parameter.cjs +1 -1
  115. package/dist/application/transform/document/parameter.cjs.map +1 -1
  116. package/dist/application/transform/document/parameter.mjs +1 -1
  117. package/dist/application/transform/document/parameter.mjs.map +1 -1
  118. package/dist/application/transform/document/parameters.cjs +23 -5
  119. package/dist/application/transform/document/parameters.cjs.map +1 -1
  120. package/dist/application/transform/document/parameters.mjs +23 -5
  121. package/dist/application/transform/document/parameters.mjs.map +1 -1
  122. package/dist/application/transform/document/path-item.cjs +4 -3
  123. package/dist/application/transform/document/path-item.cjs.map +1 -1
  124. package/dist/application/transform/document/path-item.mjs +4 -4
  125. package/dist/application/transform/document/path-item.mjs.map +1 -1
  126. package/dist/application/transform/document/path-template-key.cjs +84 -0
  127. package/dist/application/transform/document/path-template-key.cjs.map +1 -0
  128. package/dist/application/transform/document/path-template-key.mjs +79 -0
  129. package/dist/application/transform/document/path-template-key.mjs.map +1 -0
  130. package/dist/application/transform/document/path-template-refs.cjs +80 -0
  131. package/dist/application/transform/document/path-template-refs.cjs.map +1 -0
  132. package/dist/application/transform/document/path-template-refs.mjs +77 -0
  133. package/dist/application/transform/document/path-template-refs.mjs.map +1 -0
  134. package/dist/application/transform/document/paths-enum.cjs +7 -6
  135. package/dist/application/transform/document/paths-enum.cjs.map +1 -1
  136. package/dist/application/transform/document/paths-enum.mjs +7 -6
  137. package/dist/application/transform/document/paths-enum.mjs.map +1 -1
  138. package/dist/application/transform/document/paths.cjs +38 -66
  139. package/dist/application/transform/document/paths.cjs.map +1 -1
  140. package/dist/application/transform/document/paths.mjs +36 -66
  141. package/dist/application/transform/document/paths.mjs.map +1 -1
  142. package/dist/application/transform/document/webhooks.cjs +10 -3
  143. package/dist/application/transform/document/webhooks.cjs.map +1 -1
  144. package/dist/application/transform/document/webhooks.mjs +9 -2
  145. package/dist/application/transform/document/webhooks.mjs.map +1 -1
  146. package/dist/application/transform/footer/document-footer.cjs +6 -3
  147. package/dist/application/transform/footer/document-footer.cjs.map +1 -1
  148. package/dist/application/transform/footer/document-footer.mjs +6 -3
  149. package/dist/application/transform/footer/document-footer.mjs.map +1 -1
  150. package/dist/application/transform/helper-types.cjs +3 -3
  151. package/dist/application/transform/helper-types.cjs.map +1 -1
  152. package/dist/application/transform/helper-types.mjs +3 -3
  153. package/dist/application/transform/helper-types.mjs.map +1 -1
  154. package/dist/application/transform/ref-pointer/generated-location.cjs +4 -4
  155. package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -1
  156. package/dist/application/transform/ref-pointer/generated-location.mjs +1 -1
  157. package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -1
  158. package/dist/application/transform/ref-pointer/generated-shape.cjs +63 -64
  159. package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -1
  160. package/dist/application/transform/ref-pointer/generated-shape.mjs +57 -53
  161. package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -1
  162. package/dist/application/transform/ref-pointer/inline-cycles.cjs +2 -2
  163. package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -1
  164. package/dist/application/transform/ref-pointer/inline-cycles.mjs +1 -1
  165. package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -1
  166. package/dist/application/transform/ref-pointer/located-node.cjs +23 -0
  167. package/dist/application/transform/ref-pointer/located-node.cjs.map +1 -0
  168. package/dist/application/transform/ref-pointer/located-node.mjs +18 -0
  169. package/dist/application/transform/ref-pointer/located-node.mjs.map +1 -0
  170. package/dist/application/transform/ref-pointer/original-index.cjs +69 -14
  171. package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -1
  172. package/dist/application/transform/ref-pointer/original-index.mjs +71 -16
  173. package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -1
  174. package/dist/application/transform/ref-pointer/pointer-type.cjs +2 -2
  175. package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -1
  176. package/dist/application/transform/ref-pointer/pointer-type.mjs +1 -1
  177. package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -1
  178. package/dist/application/transform/ref-pointer/pointer-walk.cjs +54 -13
  179. package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -1
  180. package/dist/application/transform/ref-pointer/pointer-walk.mjs +46 -7
  181. package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -1
  182. package/dist/application/transform/ref-pointer/property-shape.cjs +57 -0
  183. package/dist/application/transform/ref-pointer/property-shape.cjs.map +1 -0
  184. package/dist/application/transform/ref-pointer/property-shape.mjs +49 -0
  185. package/dist/application/transform/ref-pointer/property-shape.mjs.map +1 -0
  186. package/dist/application/transform/ref-pointer/typed-walk.cjs +90 -22
  187. package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -1
  188. package/dist/application/transform/ref-pointer/typed-walk.mjs +87 -19
  189. package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -1
  190. package/dist/application/transform/schema/access-flags.cjs.map +1 -1
  191. package/dist/application/transform/schema/access-flags.mjs.map +1 -1
  192. package/dist/application/transform/schema/index-signature-type.cjs +21 -0
  193. package/dist/application/transform/schema/index-signature-type.cjs.map +1 -0
  194. package/dist/application/transform/schema/index-signature-type.mjs +19 -0
  195. package/dist/application/transform/schema/index-signature-type.mjs.map +1 -0
  196. package/dist/application/transform/schema/input-location.cjs +23 -0
  197. package/dist/application/transform/schema/input-location.cjs.map +1 -0
  198. package/dist/application/transform/schema/input-location.mjs +21 -0
  199. package/dist/application/transform/schema/input-location.mjs.map +1 -0
  200. package/dist/application/transform/schema/object-type.cjs +15 -5
  201. package/dist/application/transform/schema/object-type.cjs.map +1 -1
  202. package/dist/application/transform/schema/object-type.mjs +15 -5
  203. package/dist/application/transform/schema/object-type.mjs.map +1 -1
  204. package/dist/application/transform/schema/schema-transform.cjs +2 -1
  205. package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
  206. package/dist/application/transform/schema/schema-transform.mjs +2 -1
  207. package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
  208. package/dist/application/transform/schema/unevaluated-properties.cjs +2 -30
  209. package/dist/application/transform/schema/unevaluated-properties.cjs.map +1 -1
  210. package/dist/application/transform/schema/unevaluated-properties.mjs +3 -31
  211. package/dist/application/transform/schema/unevaluated-properties.mjs.map +1 -1
  212. package/dist/cli/api-logger.cjs +13 -0
  213. package/dist/cli/api-logger.cjs.map +1 -0
  214. package/dist/cli/api-logger.mjs +11 -0
  215. package/dist/cli/api-logger.mjs.map +1 -0
  216. package/dist/cli/api-settings.cjs +10 -17
  217. package/dist/cli/api-settings.cjs.map +1 -1
  218. package/dist/cli/api-settings.mjs +10 -17
  219. package/dist/cli/api-settings.mjs.map +1 -1
  220. package/dist/cli/api-writes.cjs +7 -1
  221. package/dist/cli/api-writes.cjs.map +1 -1
  222. package/dist/cli/api-writes.mjs +7 -1
  223. package/dist/cli/api-writes.mjs.map +1 -1
  224. package/dist/cli/cli-arguments.cjs +32 -74
  225. package/dist/cli/cli-arguments.cjs.map +1 -1
  226. package/dist/cli/cli-arguments.mjs +28 -70
  227. package/dist/cli/cli-arguments.mjs.map +1 -1
  228. package/dist/cli/cli-errors.cjs +18 -0
  229. package/dist/cli/cli-errors.cjs.map +1 -1
  230. package/dist/cli/cli-errors.mjs +18 -1
  231. package/dist/cli/cli-errors.mjs.map +1 -1
  232. package/dist/cli/cli-flag-names.cjs +77 -0
  233. package/dist/cli/cli-flag-names.cjs.map +1 -0
  234. package/dist/cli/cli-flag-names.mjs +64 -0
  235. package/dist/cli/cli-flag-names.mjs.map +1 -0
  236. package/dist/cli/cli-output.cjs +13 -6
  237. package/dist/cli/cli-output.cjs.map +1 -1
  238. package/dist/cli/cli-output.mjs +14 -7
  239. package/dist/cli/cli-output.mjs.map +1 -1
  240. package/dist/cli/main.cjs +11 -5
  241. package/dist/cli/main.cjs.map +1 -1
  242. package/dist/cli/main.mjs +11 -5
  243. package/dist/cli/main.mjs.map +1 -1
  244. package/dist/cli/redocly-apis.cjs +33 -12
  245. package/dist/cli/redocly-apis.cjs.map +1 -1
  246. package/dist/cli/redocly-apis.mjs +35 -14
  247. package/dist/cli/redocly-apis.mjs.map +1 -1
  248. package/dist/cli/ref-limits.cjs +15 -1
  249. package/dist/cli/ref-limits.cjs.map +1 -1
  250. package/dist/cli/ref-limits.mjs +15 -2
  251. package/dist/cli/ref-limits.mjs.map +1 -1
  252. package/dist/cli/run-cli.cjs +24 -7
  253. package/dist/cli/run-cli.cjs.map +1 -1
  254. package/dist/cli/run-cli.mjs +25 -8
  255. package/dist/cli/run-cli.mjs.map +1 -1
  256. package/dist/cli/written-flags.cjs +83 -0
  257. package/dist/cli/written-flags.cjs.map +1 -0
  258. package/dist/cli/written-flags.mjs +77 -0
  259. package/dist/cli/written-flags.mjs.map +1 -0
  260. package/dist/domain/cause-secrets.cjs +31 -16
  261. package/dist/domain/cause-secrets.cjs.map +1 -1
  262. package/dist/domain/cause-secrets.mjs +31 -16
  263. package/dist/domain/cause-secrets.mjs.map +1 -1
  264. package/dist/domain/errors.cjs +3 -0
  265. package/dist/domain/errors.cjs.map +1 -1
  266. package/dist/domain/errors.mjs +3 -0
  267. package/dist/domain/errors.mjs.map +1 -1
  268. package/dist/domain/location-text.cjs +15 -0
  269. package/dist/domain/location-text.cjs.map +1 -0
  270. package/dist/domain/location-text.mjs +13 -0
  271. package/dist/domain/location-text.mjs.map +1 -0
  272. package/dist/domain/openapi/document-places.cjs +55 -0
  273. package/dist/domain/openapi/document-places.cjs.map +1 -0
  274. package/dist/domain/openapi/document-places.mjs +53 -0
  275. package/dist/domain/openapi/document-places.mjs.map +1 -0
  276. package/dist/domain/output-fixes.cjs +8 -2
  277. package/dist/domain/output-fixes.cjs.map +1 -1
  278. package/dist/domain/output-fixes.mjs +8 -2
  279. package/dist/domain/output-fixes.mjs.map +1 -1
  280. package/dist/domain/terminal-text.cjs +31 -0
  281. package/dist/domain/terminal-text.cjs.map +1 -0
  282. package/dist/domain/terminal-text.mjs +29 -0
  283. package/dist/domain/terminal-text.mjs.map +1 -0
  284. package/dist/domain/warnings.cjs +1 -0
  285. package/dist/domain/warnings.cjs.map +1 -1
  286. package/dist/domain/warnings.mjs +1 -0
  287. package/dist/domain/warnings.mjs.map +1 -1
  288. package/dist/index.d.cts +29 -18
  289. package/dist/index.d.mts +29 -18
  290. package/dist/index.d.ts +29 -18
  291. package/package.json +1 -1
  292. package/src/adapters/node-file-system/node-file-system.ts +14 -1
  293. package/src/adapters/pipe-safe-writer/pipe-safe-writer.ts +29 -0
  294. package/src/adapters/redocly-loader/bundled-mapping-copies.ts +7 -42
  295. package/src/adapters/redocly-loader/component-schemas.ts +19 -0
  296. package/src/adapters/redocly-loader/mapping-schema-names.ts +25 -0
  297. package/src/adapters/redocly-loader/query-document-names.ts +79 -0
  298. package/src/adapters/redocly-loader/query-named-components.ts +200 -0
  299. package/src/adapters/redocly-loader/redocly-config-source.ts +11 -1
  300. package/src/adapters/redocly-loader/redocly-schema-loader.ts +63 -17
  301. package/src/adapters/redocly-loader/ref-access.ts +32 -5
  302. package/src/adapters/redocly-loader/ref-holders.ts +75 -14
  303. package/src/adapters/redocly-loader/remote-fetch.ts +37 -2
  304. package/src/adapters/redocly-loader/remote-node-limit.ts +44 -4
  305. package/src/adapters/redocly-loader/schema-source.ts +15 -3
  306. package/src/adapters/terminal-logger/terminal-logger.ts +10 -4
  307. package/src/api/cwd-option.ts +76 -0
  308. package/src/api/default-ports.ts +33 -10
  309. package/src/api/document-refs.ts +29 -1
  310. package/src/api/document-run.ts +7 -32
  311. package/src/api/legacy-utils.ts +1 -1
  312. package/src/api/openapi-ts.ts +20 -4
  313. package/src/api/option-errors.ts +22 -0
  314. package/src/api/ref-limit-options.ts +69 -0
  315. package/src/api/transform-schema.ts +20 -5
  316. package/src/application/ports/file-system.ts +8 -0
  317. package/src/application/ports/redocly-config-source.ts +5 -0
  318. package/src/application/transform/declared-value-types.ts +42 -0
  319. package/src/application/transform/document/document.ts +4 -2
  320. package/src/application/transform/document/exploded-query-values.ts +88 -0
  321. package/src/application/transform/document/header.ts +25 -5
  322. package/src/application/transform/document/parameter.ts +4 -4
  323. package/src/application/transform/document/parameters.ts +45 -10
  324. package/src/application/transform/document/path-item.ts +3 -3
  325. package/src/application/transform/document/path-template-key.ts +152 -0
  326. package/src/application/transform/document/path-template-refs.ts +127 -0
  327. package/src/application/transform/document/paths-enum.ts +23 -9
  328. package/src/application/transform/document/paths.ts +53 -123
  329. package/src/application/transform/document/webhooks.ts +18 -5
  330. package/src/application/transform/footer/document-footer.ts +18 -8
  331. package/src/application/transform/helper-types.ts +4 -4
  332. package/src/application/transform/ref-pointer/generated-location.ts +1 -1
  333. package/src/application/transform/ref-pointer/generated-shape.ts +115 -83
  334. package/src/application/transform/ref-pointer/inline-cycles.ts +1 -1
  335. package/src/application/transform/ref-pointer/located-node.ts +38 -0
  336. package/src/application/transform/ref-pointer/original-index.ts +106 -20
  337. package/src/application/transform/ref-pointer/pointer-type.ts +1 -1
  338. package/src/application/transform/ref-pointer/pointer-walk.ts +82 -8
  339. package/src/application/transform/ref-pointer/property-shape.ts +106 -0
  340. package/src/application/transform/ref-pointer/typed-walk.ts +143 -29
  341. package/src/application/transform/schema/access-flags.ts +5 -2
  342. package/src/application/transform/schema/index-signature-type.ts +31 -0
  343. package/src/application/transform/schema/input-location.ts +35 -0
  344. package/src/application/transform/schema/object-type.ts +18 -8
  345. package/src/application/transform/schema/schema-transform.ts +2 -1
  346. package/src/application/transform/schema/unevaluated-properties.ts +4 -44
  347. package/src/cli/api-logger.ts +17 -0
  348. package/src/cli/api-settings.ts +12 -20
  349. package/src/cli/api-writes.ts +11 -3
  350. package/src/cli/cli-arguments.ts +57 -92
  351. package/src/cli/cli-dependencies.ts +7 -2
  352. package/src/cli/cli-errors.ts +23 -0
  353. package/src/cli/cli-flag-names.ts +99 -0
  354. package/src/cli/cli-output.ts +31 -16
  355. package/src/cli/main.ts +12 -5
  356. package/src/cli/redocly-apis.ts +56 -20
  357. package/src/cli/ref-limits.ts +21 -2
  358. package/src/cli/run-cli.ts +39 -7
  359. package/src/cli/written-flags.ts +131 -0
  360. package/src/domain/cause-secrets.ts +59 -25
  361. package/src/domain/errors.ts +3 -0
  362. package/src/domain/location-text.ts +27 -0
  363. package/src/domain/openapi/document-places.ts +78 -0
  364. package/src/domain/output-fixes.ts +9 -2
  365. package/src/domain/terminal-text.ts +44 -0
  366. package/src/domain/warnings.ts +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property-shape.cjs","sources":["../../../../src/application/transform/ref-pointer/property-shape.ts"],"sourcesContent":["import type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { propertyAccessFlags } from \"../schema/access-flags.js\";\nimport { isInputLocation } from \"../schema/input-location.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport {\n followLocated,\n followRefs,\n isJsonObject,\n type JsonObject,\n type LocatedNode,\n} from \"./located-node.js\";\n\n/**\n * What the generated type of an object schema makes of one of its properties: optional, left\n * out, wrapped in a read or write marker, or a value that may be `undefined` or `null`.\n */\n\n/** `nullable: true` or a `type` list with `null`: the generated type includes `null`. */\nexport function isNullableSchema(node: unknown): boolean {\n if (!isJsonObject(node)) {\n return false;\n }\n return node.nullable === true || (Array.isArray(node.type) && node.type.includes(\"null\"));\n}\n\n/**\n * Whether the generated type has the property as optional, as `objectType` decides: a `default`\n * makes a property required except in an input location, where the client may leave it out.\n */\nexport function isOptionalProperty(\n owner: LocatedNode & { node: JsonObject },\n key: string,\n options: SchemaOptions,\n): boolean {\n const { node } = owner;\n const required = Array.isArray(node.required) ? node.required : undefined;\n const property = (node.properties as JsonObject)[key];\n const hasDefault = isJsonObject(property) && property.default !== undefined;\n const isDefaultRequired =\n hasDefault && options.defaultNonNullable && !isInputLocation(owner.location, options.fixes);\n const isRequired =\n required?.includes(key) === true ||\n (required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\n/**\n * Whether `--exclude-deprecated` leaves the property out: its object, or the one its `$ref`\n * names, is deprecated (`objectType`). The key is then not in the generated type at all.\n */\nexport function isExcludedProperty(\n property: unknown,\n options: SchemaOptions,\n refs: RefResolver,\n): boolean {\n const resolved = followRefs(property, refs);\n return options.excludeDeprecated && isJsonObject(resolved) && Boolean(resolved.deprecated);\n}\n\n/**\n * Whether the generated type keeps one of the schema's properties. The index signature next to\n * them then holds their types too (`withPropertyTypes`), so it is not its value schema's type.\n */\nexport function hasKeptProperties(node: JsonObject, options: SchemaOptions, refs: RefResolver) {\n const properties = isJsonObject(node.properties) ? node.properties : {};\n return Object.values(properties).some((value) => !isExcludedProperty(value, options, refs));\n}\n\n/**\n * Whether `--read-write-markers` wraps the type of a property or `$defs` member: one that is only\n * `readOnly` or only `writeOnly` is `$Read<T>` or `$Write<T>` (object-type.ts).\n */\nexport function isMarkedProperty(value: unknown, options: SchemaOptions, refs: RefResolver) {\n if (!options.readWriteMarkers || !isJsonObject(value)) {\n return false;\n }\n const flags = propertyAccessFlags(value as Schema, { options, refs });\n return flags.isReadOnly !== flags.isWriteOnly;\n}\n\n/** Whether a value is there: `present`, `absent` (may be `undefined` or `null`) or `unknown`. */\nexport type Presence = \"present\" | \"absent\" | \"unknown\";\n\n/** The presence of a value of `schema` itself: `absent` when its type includes `null`. */\nexport function schemaPresence(schema: unknown, refs: RefResolver): Presence {\n return isNullableSchema(followRefs(schema, refs)) ? \"absent\" : \"present\";\n}\n\n/** The presence of property `key` of `schema`: optional or nullable is `absent`. */\nexport function propertyPresence(\n schema: LocatedNode,\n key: string,\n options: SchemaOptions,\n refs: RefResolver,\n): Presence {\n const owner = followLocated(schema, refs);\n const { node } = owner;\n const properties = isJsonObject(node) && isJsonObject(node.properties) ? node.properties : {};\n if (!isJsonObject(node) || !Object.hasOwn(properties, key)) {\n return \"unknown\";\n }\n return isOptionalProperty({ ...owner, node }, key, options)\n ? \"absent\"\n : schemaPresence(properties[key], refs);\n}\n"],"names":["isJsonObject","isInputLocation","followRefs","propertyAccessFlags","followLocated"],"mappings":";;;;;;AAkBO,SAAS,iBAAiB,IAAA,EAAwB;AACvD,EAAA,IAAI,CAACA,wBAAA,CAAa,IAAI,CAAA,EAAG;AACvB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAA,CAAK,QAAA,KAAa,IAAA,IAAS,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA,IAAK,IAAA,CAAK,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA;AACzF;AAMO,SAAS,kBAAA,CACd,KAAA,EACA,GAAA,EACA,OAAA,EACS;AACT,EAAA,MAAM,EAAE,MAAK,GAAI,KAAA;AACjB,EAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,QAAQ,CAAA,GAAI,KAAK,QAAA,GAAW,MAAA;AAChE,EAAA,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AAA,EAAiB,EAAE,OAAA,EAAS,MAAM,CAAA;AACpE,EAAA,OAAO,KAAA,CAAM,eAAe,KAAA,CAAM,WAAA;AACpC;AAMO,SAAS,cAAA,CAAe,QAAiB,IAAA,EAA6B;AAC3E,EAAA,OAAO,iBAAiBD,sBAAA,CAAW,MAAA,EAAQ,IAAI,CAAC,IAAI,QAAA,GAAW,SAAA;AACjE;AAGO,SAAS,gBAAA,CACd,MAAA,EACA,GAAA,EACA,OAAA,EACA,IAAA,EACU;AACV,EAAA,MAAM,KAAA,GAAQE,yBAAA,CAAc,MAAA,EAAQ,IAAI,CAAA;AACxC,EAAA,MAAM,EAAE,MAAK,GAAI,KAAA;AACjB,EAAA,MAAM,UAAA,GAAaJ,wBAAA,CAAa,IAAI,CAAA,IAAKA,wBAAA,CAAa,KAAK,UAAU,CAAA,GAAI,IAAA,CAAK,UAAA,GAAa,EAAC;AAC5F,EAAA,IAAI,CAACA,yBAAa,IAAI,CAAA,IAAK,CAAC,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY,GAAG,CAAA,EAAG;AAC1D,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,kBAAA,CAAmB,EAAE,GAAG,KAAA,EAAO,MAAK,EAAG,GAAA,EAAK,OAAO,CAAA,GACtD,QAAA,GACA,cAAA,CAAe,UAAA,CAAW,GAAG,GAAG,IAAI,CAAA;AAC1C;;;;;;;;"}
@@ -0,0 +1,49 @@
1
+ import { propertyAccessFlags } from '../schema/access-flags.mjs';
2
+ import { isInputLocation } from '../schema/input-location.mjs';
3
+ import { followRefs, isJsonObject, followLocated } from './located-node.mjs';
4
+
5
+ function isNullableSchema(node) {
6
+ if (!isJsonObject(node)) {
7
+ return false;
8
+ }
9
+ return node.nullable === true || Array.isArray(node.type) && node.type.includes("null");
10
+ }
11
+ function isOptionalProperty(owner, key, options) {
12
+ const { node } = owner;
13
+ const required = Array.isArray(node.required) ? node.required : void 0;
14
+ const property = node.properties[key];
15
+ const hasDefault = isJsonObject(property) && property.default !== void 0;
16
+ const isDefaultRequired = hasDefault && options.defaultNonNullable && !isInputLocation(owner.location, options.fixes);
17
+ const isRequired = required?.includes(key) === true || required === void 0 && options.propertiesRequiredByDefault || isDefaultRequired;
18
+ return !isRequired;
19
+ }
20
+ function isExcludedProperty(property, options, refs) {
21
+ const resolved = followRefs(property, refs);
22
+ return options.excludeDeprecated && isJsonObject(resolved) && Boolean(resolved.deprecated);
23
+ }
24
+ function hasKeptProperties(node, options, refs) {
25
+ const properties = isJsonObject(node.properties) ? node.properties : {};
26
+ return Object.values(properties).some((value) => !isExcludedProperty(value, options, refs));
27
+ }
28
+ function isMarkedProperty(value, options, refs) {
29
+ if (!options.readWriteMarkers || !isJsonObject(value)) {
30
+ return false;
31
+ }
32
+ const flags = propertyAccessFlags(value, { options, refs });
33
+ return flags.isReadOnly !== flags.isWriteOnly;
34
+ }
35
+ function schemaPresence(schema, refs) {
36
+ return isNullableSchema(followRefs(schema, refs)) ? "absent" : "present";
37
+ }
38
+ function propertyPresence(schema, key, options, refs) {
39
+ const owner = followLocated(schema, refs);
40
+ const { node } = owner;
41
+ const properties = isJsonObject(node) && isJsonObject(node.properties) ? node.properties : {};
42
+ if (!isJsonObject(node) || !Object.hasOwn(properties, key)) {
43
+ return "unknown";
44
+ }
45
+ return isOptionalProperty({ ...owner, node }, key, options) ? "absent" : schemaPresence(properties[key], refs);
46
+ }
47
+
48
+ export { hasKeptProperties, isExcludedProperty, isMarkedProperty, isNullableSchema, isOptionalProperty, propertyPresence, schemaPresence };
49
+ //# sourceMappingURL=property-shape.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"property-shape.mjs","sources":["../../../../src/application/transform/ref-pointer/property-shape.ts"],"sourcesContent":["import type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { propertyAccessFlags } from \"../schema/access-flags.js\";\nimport { isInputLocation } from \"../schema/input-location.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport {\n followLocated,\n followRefs,\n isJsonObject,\n type JsonObject,\n type LocatedNode,\n} from \"./located-node.js\";\n\n/**\n * What the generated type of an object schema makes of one of its properties: optional, left\n * out, wrapped in a read or write marker, or a value that may be `undefined` or `null`.\n */\n\n/** `nullable: true` or a `type` list with `null`: the generated type includes `null`. */\nexport function isNullableSchema(node: unknown): boolean {\n if (!isJsonObject(node)) {\n return false;\n }\n return node.nullable === true || (Array.isArray(node.type) && node.type.includes(\"null\"));\n}\n\n/**\n * Whether the generated type has the property as optional, as `objectType` decides: a `default`\n * makes a property required except in an input location, where the client may leave it out.\n */\nexport function isOptionalProperty(\n owner: LocatedNode & { node: JsonObject },\n key: string,\n options: SchemaOptions,\n): boolean {\n const { node } = owner;\n const required = Array.isArray(node.required) ? node.required : undefined;\n const property = (node.properties as JsonObject)[key];\n const hasDefault = isJsonObject(property) && property.default !== undefined;\n const isDefaultRequired =\n hasDefault && options.defaultNonNullable && !isInputLocation(owner.location, options.fixes);\n const isRequired =\n required?.includes(key) === true ||\n (required === undefined && options.propertiesRequiredByDefault) ||\n isDefaultRequired;\n return !isRequired;\n}\n\n/**\n * Whether `--exclude-deprecated` leaves the property out: its object, or the one its `$ref`\n * names, is deprecated (`objectType`). The key is then not in the generated type at all.\n */\nexport function isExcludedProperty(\n property: unknown,\n options: SchemaOptions,\n refs: RefResolver,\n): boolean {\n const resolved = followRefs(property, refs);\n return options.excludeDeprecated && isJsonObject(resolved) && Boolean(resolved.deprecated);\n}\n\n/**\n * Whether the generated type keeps one of the schema's properties. The index signature next to\n * them then holds their types too (`withPropertyTypes`), so it is not its value schema's type.\n */\nexport function hasKeptProperties(node: JsonObject, options: SchemaOptions, refs: RefResolver) {\n const properties = isJsonObject(node.properties) ? node.properties : {};\n return Object.values(properties).some((value) => !isExcludedProperty(value, options, refs));\n}\n\n/**\n * Whether `--read-write-markers` wraps the type of a property or `$defs` member: one that is only\n * `readOnly` or only `writeOnly` is `$Read<T>` or `$Write<T>` (object-type.ts).\n */\nexport function isMarkedProperty(value: unknown, options: SchemaOptions, refs: RefResolver) {\n if (!options.readWriteMarkers || !isJsonObject(value)) {\n return false;\n }\n const flags = propertyAccessFlags(value as Schema, { options, refs });\n return flags.isReadOnly !== flags.isWriteOnly;\n}\n\n/** Whether a value is there: `present`, `absent` (may be `undefined` or `null`) or `unknown`. */\nexport type Presence = \"present\" | \"absent\" | \"unknown\";\n\n/** The presence of a value of `schema` itself: `absent` when its type includes `null`. */\nexport function schemaPresence(schema: unknown, refs: RefResolver): Presence {\n return isNullableSchema(followRefs(schema, refs)) ? \"absent\" : \"present\";\n}\n\n/** The presence of property `key` of `schema`: optional or nullable is `absent`. */\nexport function propertyPresence(\n schema: LocatedNode,\n key: string,\n options: SchemaOptions,\n refs: RefResolver,\n): Presence {\n const owner = followLocated(schema, refs);\n const { node } = owner;\n const properties = isJsonObject(node) && isJsonObject(node.properties) ? node.properties : {};\n if (!isJsonObject(node) || !Object.hasOwn(properties, key)) {\n return \"unknown\";\n }\n return isOptionalProperty({ ...owner, node }, key, options)\n ? \"absent\"\n : schemaPresence(properties[key], refs);\n}\n"],"names":[],"mappings":";;;;AAkBO,SAAS,iBAAiB,IAAA,EAAwB;AACvD,EAAA,IAAI,CAAC,YAAA,CAAa,IAAI,CAAA,EAAG;AACvB,IAAA,OAAO,KAAA;AAAA,EACT;AACA,EAAA,OAAO,IAAA,CAAK,QAAA,KAAa,IAAA,IAAS,KAAA,CAAM,OAAA,CAAQ,IAAA,CAAK,IAAI,CAAA,IAAK,IAAA,CAAK,IAAA,CAAK,QAAA,CAAS,MAAM,CAAA;AACzF;AAMO,SAAS,kBAAA,CACd,KAAA,EACA,GAAA,EACA,OAAA,EACS;AACT,EAAA,MAAM,EAAE,MAAK,GAAI,KAAA;AACjB,EAAA,MAAM,WAAW,KAAA,CAAM,OAAA,CAAQ,KAAK,QAAQ,CAAA,GAAI,KAAK,QAAA,GAAW,MAAA;AAChE,EAAA,MAAM,QAAA,GAAY,IAAA,CAAK,UAAA,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EAAA,OAAO,KAAA,CAAM,eAAe,KAAA,CAAM,WAAA;AACpC;AAMO,SAAS,cAAA,CAAe,QAAiB,IAAA,EAA6B;AAC3E,EAAA,OAAO,iBAAiB,UAAA,CAAW,MAAA,EAAQ,IAAI,CAAC,IAAI,QAAA,GAAW,SAAA;AACjE;AAGO,SAAS,gBAAA,CACd,MAAA,EACA,GAAA,EACA,OAAA,EACA,IAAA,EACU;AACV,EAAA,MAAM,KAAA,GAAQ,aAAA,CAAc,MAAA,EAAQ,IAAI,CAAA;AACxC,EAAA,MAAM,EAAE,MAAK,GAAI,KAAA;AACjB,EAAA,MAAM,UAAA,GAAa,YAAA,CAAa,IAAI,CAAA,IAAK,YAAA,CAAa,KAAK,UAAU,CAAA,GAAI,IAAA,CAAK,UAAA,GAAa,EAAC;AAC5F,EAAA,IAAI,CAAC,aAAa,IAAI,CAAA,IAAK,CAAC,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY,GAAG,CAAA,EAAG;AAC1D,IAAA,OAAO,SAAA;AAAA,EACT;AACA,EAAA,OAAO,kBAAA,CAAmB,EAAE,GAAG,KAAA,EAAO,MAAK,EAAG,GAAA,EAAK,OAAO,CAAA,GACtD,QAAA,GACA,cAAA,CAAe,UAAA,CAAW,GAAG,GAAG,IAAI,CAAA;AAC1C;;"}
@@ -3,67 +3,93 @@
3
3
  const constructors = require('../../../domain/ir/constructors.cjs');
4
4
  const refType = require('../ref-type.cjs');
5
5
  const generatedShape = require('./generated-shape.cjs');
6
+ const locatedNode = require('./located-node.cjs');
6
7
  const pointerWalk = require('./pointer-walk.cjs');
8
+ const propertyShape = require('./property-shape.cjs');
7
9
 
8
10
  const DEFS_KEYWORD = "$defs";
9
11
  function present(walk) {
10
12
  return walk.presence === "present" ? walk.type : constructors.irReference("NonNullable", [walk.type]);
11
13
  }
12
14
  function indexEntries(walk, key, keyword, refs) {
13
- const owner = generatedShape.followRefs(walk.node, refs);
14
- const child = generatedShape.isJsonObject(owner) ? owner[keyword] : void 0;
15
+ const owner = locatedNode.followLocated(walk, refs);
16
+ const child = locatedNode.isJsonObject(owner.node) ? owner.node[keyword] : void 0;
15
17
  return {
16
18
  ...walk,
17
19
  type: constructors.irIndexedAccess(present(walk), constructors.irKeyword(key)),
18
20
  node: child,
19
- presence: generatedShape.schemaPresence(child, refs)
21
+ location: locatedNode.childLocation(owner.location, keyword),
22
+ presence: propertyShape.schemaPresence(child, refs)
20
23
  };
21
24
  }
22
25
  function nameStep(walk, name, isLast, input) {
23
- const owner = generatedShape.followRefs(walk.node, input.refs);
24
- const properties = generatedShape.isJsonObject(owner) && generatedShape.isJsonObject(owner.properties) ? owner.properties : {};
26
+ const owner = locatedNode.followLocated(walk, input.refs);
27
+ const { node } = owner;
28
+ const properties = locatedNode.isJsonObject(node) && locatedNode.isJsonObject(node.properties) ? node.properties : {};
29
+ const value = properties[name];
30
+ const { options, refs } = input;
31
+ const isMarkedOnTheWay = !isLast && propertyShape.isMarkedProperty(value, options, refs);
32
+ if (propertyShape.isExcludedProperty(value, options, refs) || isMarkedOnTheWay) {
33
+ return null;
34
+ }
25
35
  const type = walk.presence === "present" ? refType.indexKeyword(walk.type, name, isLast) : refType.indexBy(present(walk), name);
26
36
  return {
27
37
  ...walk,
28
38
  type,
29
- node: properties[name],
39
+ node: value,
40
+ location: locatedNode.childLocation(walk.namesLocation, name),
30
41
  isName: false,
31
- presence: generatedShape.propertyPresence(walk.node, name, input.options, input.refs)
42
+ presence: propertyShape.propertyPresence(walk, name, input.options, input.refs)
32
43
  };
33
44
  }
34
45
  function defsStep(walk, owner, isLast) {
35
- const defs = generatedShape.isJsonObject(owner) && generatedShape.isJsonObject(owner[DEFS_KEYWORD]) ? owner[DEFS_KEYWORD] : {};
46
+ const { node } = owner;
47
+ const defs = locatedNode.isJsonObject(node) && locatedNode.isJsonObject(node[DEFS_KEYWORD]) ? node[DEFS_KEYWORD] : {};
48
+ const namesLocation = locatedNode.childLocation(owner.location, DEFS_KEYWORD);
36
49
  return {
37
50
  ...walk,
38
51
  type: refType.indexKeyword(present(walk), DEFS_KEYWORD, isLast),
52
+ // A node of its own, not in the document: its properties are the definitions.
39
53
  node: { properties: defs, required: Object.keys(defs) },
54
+ location: namesLocation,
55
+ namesLocation,
40
56
  isName: true,
41
57
  presence: "present"
42
58
  };
43
59
  }
60
+ const COMPOSITION_KEYWORDS = ["allOf", "anyOf", "oneOf"];
44
61
  const SHAPED_KEYWORDS = /* @__PURE__ */ new Set([
45
62
  "properties",
46
63
  "items",
47
64
  "additionalProperties"
48
65
  ]);
49
66
  function hasKeywordMember(owner, segment) {
50
- if (!SHAPED_KEYWORDS.has(segment) || !generatedShape.isJsonObject(owner)) {
67
+ if (!SHAPED_KEYWORDS.has(segment) || !locatedNode.isJsonObject(owner)) {
51
68
  return true;
52
69
  }
53
70
  return segment === "items" ? generatedShape.isArrayShape(owner) : generatedShape.isObjectShape(owner);
54
71
  }
72
+ function isIndexedByValue(owner, input) {
73
+ if (!locatedNode.isJsonObject(owner)) {
74
+ return true;
75
+ }
76
+ const patterns = owner.patternProperties;
77
+ const hasPatterns = locatedNode.isJsonObject(patterns) && Object.keys(patterns).length > 0;
78
+ const isComposed = COMPOSITION_KEYWORDS.some((keyword) => keyword in owner);
79
+ return !hasPatterns && !isComposed && !propertyShape.hasKeptProperties(owner, input.options, input.refs);
80
+ }
55
81
  function keywordStep(walk, segment, isLast, input) {
56
- const owner = generatedShape.followRefs(walk.node, input.refs);
57
- if (!hasKeywordMember(owner, segment)) {
82
+ const owner = locatedNode.followLocated(walk, input.refs);
83
+ if (!hasKeywordMember(owner.node, segment)) {
58
84
  return null;
59
85
  }
60
86
  switch (segment) {
61
87
  case "properties":
62
- return { ...walk, isName: true };
88
+ return { ...walk, isName: true, namesLocation: locatedNode.childLocation(owner.location, segment) };
63
89
  case "items":
64
90
  return indexEntries(walk, "number", "items", input.refs);
65
91
  case "additionalProperties":
66
- return indexEntries(walk, "string", "additionalProperties", input.refs);
92
+ return isIndexedByValue(owner.node, input) ? indexEntries(walk, "string", "additionalProperties", input.refs) : null;
67
93
  case DEFS_KEYWORD:
68
94
  return defsStep(walk, owner, isLast);
69
95
  default:
@@ -72,15 +98,56 @@ function keywordStep(walk, segment, isLast, input) {
72
98
  }
73
99
  function containerStep(walk, index, input) {
74
100
  const segment = input.pointer.segments[index];
75
- const owner = generatedShape.followRefs(walk.node, input.refs);
101
+ const owner = locatedNode.followRefs(walk.node, input.refs);
76
102
  const isOptional = segment === "requestBody" && pointerWalk.isOptionalRequestBody(owner, input.refs) || pointerWalk.isOptionalHeader(input.pointer, index, owner);
77
103
  return {
78
104
  ...walk,
79
105
  type: refType.indexBy(present(walk), segment),
80
- node: generatedShape.isJsonObject(owner) ? owner[segment] : void 0,
106
+ node: locatedNode.isJsonObject(owner) ? owner[segment] : void 0,
107
+ location: locatedNode.childLocation(locatedNode.followLocated(walk, input.refs).location, segment),
81
108
  presence: isOptional ? "absent" : "present"
82
109
  };
83
110
  }
111
+ function contentStep(walk, form, isLast, refs) {
112
+ const isMapTyped = form === "media-type-members" || form === "first-media-type" && !isLast;
113
+ if (!isMapTyped) {
114
+ return null;
115
+ }
116
+ const owner = locatedNode.followLocated(walk, refs);
117
+ return {
118
+ ...walk,
119
+ node: locatedNode.isJsonObject(owner.node) ? owner.node.content : void 0,
120
+ location: locatedNode.childLocation(owner.location, "content"),
121
+ isFirstMediaType: form === "first-media-type"
122
+ };
123
+ }
124
+ function firstMediaTypeStep(walk, segment) {
125
+ const content = locatedNode.isJsonObject(walk.node) ? walk.node : {};
126
+ if (Object.keys(content)[0] !== segment) {
127
+ return null;
128
+ }
129
+ const location = locatedNode.childLocation(walk.location, segment);
130
+ return { ...walk, node: content[segment], location, isFirstMediaType: false };
131
+ }
132
+ function schemaStep(walk, refs) {
133
+ const owner = locatedNode.followLocated(walk, refs);
134
+ const schema = locatedNode.isJsonObject(owner.node) ? owner.node.schema : void 0;
135
+ const location = locatedNode.childLocation(owner.location, "schema");
136
+ const presence = walk.presence === "absent" ? "absent" : propertyShape.schemaPresence(schema, refs);
137
+ return { ...walk, node: schema, location, isSchema: true, presence };
138
+ }
139
+ function documentStep(walk, index, input) {
140
+ const owner = locatedNode.followRefs(walk.node, input.refs);
141
+ const form = pointerWalk.headerParameterContentForm(input.pointer, index, owner, input.options);
142
+ if (form !== null) {
143
+ const isLast = index === input.pointer.segments.length - 1;
144
+ return contentStep(walk, form, isLast, input.refs);
145
+ }
146
+ if (pointerWalk.isParameterList(input.pointer, index) || pointerWalk.isExcludedOperation(input.pointer, index, owner, input)) {
147
+ return null;
148
+ }
149
+ return containerStep(walk, index, input);
150
+ }
84
151
  function step(walk, index, input) {
85
152
  const { segments } = input.pointer;
86
153
  const segment = segments[index];
@@ -88,17 +155,17 @@ function step(walk, index, input) {
88
155
  if (walk.isSchema) {
89
156
  return walk.isName ? nameStep(walk, segment, isLast, input) : keywordStep(walk, segment, isLast, input);
90
157
  }
158
+ if (walk.isFirstMediaType) {
159
+ return firstMediaTypeStep(walk, segment);
160
+ }
91
161
  if (segment === "schema" && pointerWalk.isTypedAsSchema(input.pointer, index)) {
92
- const owner = generatedShape.followRefs(walk.node, input.refs);
93
- const schema = generatedShape.isJsonObject(owner) ? owner.schema : void 0;
94
- const presence = walk.presence === "absent" ? "absent" : generatedShape.schemaPresence(schema, input.refs);
95
- return { ...walk, node: schema, isSchema: true, presence };
162
+ return schemaStep(walk, input.refs);
96
163
  }
97
- return pointerWalk.isParameterList(input.pointer, index) ? null : containerStep(walk, index, input);
164
+ return documentStep(walk, index, input);
98
165
  }
99
166
  function typedWalk(input) {
100
167
  const { pointer } = input;
101
- const node = pointerWalk.leadingNode(pointer, input.refs);
168
+ const { node, location } = pointerWalk.leadingLocated(pointer, input.refs);
102
169
  const isSchema = pointerWalk.startsInSchema(pointer);
103
170
  let walk = {
104
171
  type: refType.indexBy(
@@ -106,9 +173,10 @@ function typedWalk(input) {
106
173
  ...pointer.segments.slice(0, pointerWalk.leadingSegmentsOf(pointer))
107
174
  ),
108
175
  node,
176
+ location,
109
177
  isSchema,
110
178
  isName: false,
111
- presence: isSchema ? generatedShape.schemaPresence(node, input.refs) : "present"
179
+ presence: isSchema ? propertyShape.schemaPresence(node, input.refs) : "present"
112
180
  };
113
181
  for (let index = pointerWalk.leadingSegmentsOf(pointer); index < pointer.segments.length; index++) {
114
182
  const next = step(walk, index, input);
@@ -1 +1 @@
1
- {"version":3,"file":"typed-walk.cjs","sources":["../../../../src/application/transform/ref-pointer/typed-walk.ts"],"sourcesContent":["import { irIndexedAccess, irKeyword, irReference } from \"../../../domain/ir/constructors.js\";\nimport type { IrKeyword, IrType } from \"../../../domain/ir/nodes.js\";\nimport { indexBy, indexKeyword, rootType } from \"../ref-type.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport {\n followRefs,\n isArrayShape,\n isJsonObject,\n isObjectShape,\n type Presence,\n propertyPresence,\n schemaPresence,\n} from \"./generated-shape.js\";\nimport {\n isOptionalHeader,\n isOptionalRequestBody,\n isParameterList,\n isTypedAsSchema,\n leadingNode,\n leadingSegmentsOf,\n type RefPointer,\n startsInSchema,\n} from \"./pointer-walk.js\";\n\n/**\n * The type of a `$ref` pointer as the generated types have it: the `schema` of a media type,\n * header or component parameter is its type, `items` is indexed by `number`,\n * `additionalProperties` by `string`, and a value that may be `undefined` or `null` is wrapped in\n * `NonNullable` before it is indexed. The walk stops at a segment with no type of its own\n * (`allOf/0`, `definitions/A`, operation `parameters/0`): the caller types the target itself.\n */\n\nconst DEFS_KEYWORD = \"$defs\";\n\nexport interface TypedWalk {\n readonly type: IrType;\n /** The document node the type stands for (not followed through a `$ref`). */\n readonly node: unknown;\n readonly isSchema: boolean;\n /** The segment is a property or `$defs` name, not a keyword. */\n readonly isName: boolean;\n readonly presence: Presence;\n}\n\nexport interface TypedWalkInput {\n readonly pointer: RefPointer;\n readonly options: SchemaOptions;\n readonly refs: RefResolver;\n}\n\n/** The walk result: a type, or the index of the first segment that has no type. */\nexport type TypedWalkResult =\n | { readonly kind: \"typed\"; readonly walk: TypedWalk }\n | { readonly kind: \"untyped\"; readonly index: number };\n\nfunction present(walk: TypedWalk): IrType {\n return walk.presence === \"present\" ? walk.type : irReference(\"NonNullable\", [walk.type]);\n}\n\nfunction indexEntries(walk: TypedWalk, key: IrKeyword, keyword: string, refs: RefResolver) {\n const owner = followRefs(walk.node, refs);\n const child = isJsonObject(owner) ? owner[keyword] : undefined;\n return {\n ...walk,\n type: irIndexedAccess(present(walk), irKeyword(key)),\n node: child,\n presence: schemaPresence(child, refs),\n };\n}\n\nfunction nameStep(walk: TypedWalk, name: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followRefs(walk.node, input.refs);\n const properties = isJsonObject(owner) && isJsonObject(owner.properties) ? owner.properties : {};\n const type =\n walk.presence === \"present\"\n ? indexKeyword(walk.type, name, isLast)\n : indexBy(present(walk), name);\n return {\n ...walk,\n type,\n node: properties[name],\n isName: false,\n presence: propertyPresence(walk.node, name, input.options, input.refs),\n };\n}\n\n/** `$defs` is optional (`NonNullable` when more follows); its members are present. */\nfunction defsStep(walk: TypedWalk, owner: unknown, isLast: boolean): TypedWalk {\n const defs = isJsonObject(owner) && isJsonObject(owner[DEFS_KEYWORD]) ? owner[DEFS_KEYWORD] : {};\n return {\n ...walk,\n type: indexKeyword(present(walk), DEFS_KEYWORD, isLast),\n node: { properties: defs, required: Object.keys(defs) },\n isName: true,\n presence: \"present\",\n };\n}\n\nconst SHAPED_KEYWORDS: ReadonlySet<string> = new Set([\n \"properties\",\n \"items\",\n \"additionalProperties\",\n]);\n\n/**\n * Whether the keyword gives the owner's generated type a member: `items` only an array,\n * `properties` and `additionalProperties` only an object (`type: string` ignores them). A node\n * that is not in the document is indexed as the keyword says.\n */\nfunction hasKeywordMember(owner: unknown, segment: string): boolean {\n if (!SHAPED_KEYWORDS.has(segment) || !isJsonObject(owner)) {\n return true;\n }\n return segment === \"items\" ? isArrayShape(owner) : isObjectShape(owner);\n}\n\nfunction keywordStep(walk: TypedWalk, segment: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followRefs(walk.node, input.refs);\n if (!hasKeywordMember(owner, segment)) {\n return null;\n }\n switch (segment) {\n case \"properties\":\n return { ...walk, isName: true };\n case \"items\":\n return indexEntries(walk, \"number\", \"items\", input.refs);\n case \"additionalProperties\":\n return indexEntries(walk, \"string\", \"additionalProperties\", input.refs);\n case DEFS_KEYWORD:\n return defsStep(walk, owner, isLast);\n default:\n return null;\n }\n}\n\nfunction containerStep(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk {\n const segment = input.pointer.segments[index] as string;\n const owner = followRefs(walk.node, input.refs);\n const isOptional =\n (segment === \"requestBody\" && isOptionalRequestBody(owner, input.refs)) ||\n isOptionalHeader(input.pointer, index, owner);\n return {\n ...walk,\n type: indexBy(present(walk), segment),\n node: isJsonObject(owner) ? owner[segment] : undefined,\n presence: isOptional ? \"absent\" : \"present\",\n };\n}\n\nfunction step(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk | null {\n const { segments } = input.pointer;\n const segment = segments[index] as string;\n const isLast = index === segments.length - 1;\n if (walk.isSchema) {\n return walk.isName\n ? nameStep(walk, segment, isLast, input)\n : keywordStep(walk, segment, isLast, input);\n }\n if (segment === \"schema\" && isTypedAsSchema(input.pointer, index)) {\n const owner = followRefs(walk.node, input.refs);\n const schema = isJsonObject(owner) ? owner.schema : undefined;\n // The container's type is its schema's type: an optional header stays optional.\n const presence = walk.presence === \"absent\" ? \"absent\" : schemaPresence(schema, input.refs);\n return { ...walk, node: schema, isSchema: true, presence };\n }\n return isParameterList(input.pointer, index) ? null : containerStep(walk, index, input);\n}\n\n/** Walk the whole pointer; see the module comment. */\nexport function typedWalk(input: TypedWalkInput): TypedWalkResult {\n const { pointer } = input;\n const node = leadingNode(pointer, input.refs);\n const isSchema = startsInSchema(pointer);\n let walk: TypedWalk = {\n type: indexBy(\n rootType(pointer.rootSegment, false),\n ...pointer.segments.slice(0, leadingSegmentsOf(pointer)),\n ),\n node,\n isSchema,\n isName: false,\n presence: isSchema ? schemaPresence(node, input.refs) : \"present\",\n };\n for (let index = leadingSegmentsOf(pointer); index < pointer.segments.length; index++) {\n const next = step(walk, index, input);\n if (next === null) {\n return { kind: \"untyped\", index };\n }\n walk = next;\n }\n return { kind: \"typed\", walk };\n}\n"],"names":["irReference","followRefs","isJsonObject","irIndexedAccess","irKeyword","schemaPresence","indexKeyword","indexBy","propertyPresence","isArrayShape","isObjectShape","isOptionalRequestBody","isOptionalHeader","isTypedAsSchema","isParameterList","leadingNode","startsInSchema","rootType","leadingSegmentsOf"],"mappings":";;;;;;;AAgCA,MAAM,YAAA,GAAe,OAAA;AAuBrB,SAAS,QAAQ,IAAA,EAAyB;AACxC,EAAA,OAAO,IAAA,CAAK,QAAA,KAAa,SAAA,GAAY,IAAA,CAAK,IAAA,GAAOA,yBAAY,aAAA,EAAe,CAAC,IAAA,CAAK,IAAI,CAAC,CAAA;AACzF;AAEA,SAAS,YAAA,CAAa,IAAA,EAAiB,GAAA,EAAgB,OAAA,EAAiB,IAAA,EAAmB;AACzF,EAAA,MAAM,KAAA,GAAQC,yBAAA,CAAW,IAAA,CAAK,IAAA,EAAM,IAAI,CAAA;AACxC,EAAA,MAAM,QAAQC,2BAAA,CAAa,KAAK,CAAA,GAAI,KAAA,CAAM,OAAO,CAAA,GAAI,MAAA;AACrD,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,MAAMC,4BAAA,CAAgB,OAAA,CAAQ,IAAI,CAAA,EAAGC,sBAAA,CAAU,GAAG,CAAC,CAAA;AAAA,IACnD,IAAA,EAAM,KAAA;AAAA,IACN,QAAA,EAAUC,6BAAA,CAAe,KAAA,EAAO,IAAI;AAAA,GACtC;AACF;AAEA,SAAS,QAAA,CAAS,IAAA,EAAiB,IAAA,EAAc,MAAA,EAAiB,KAAA,EAAuB;AACvF,EAAA,MAAM,KAAA,GAAQJ,yBAAA,CAAW,IAAA,CAAK,IAAA,EAAM,MAAM,IAAI,CAAA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C/B;;"}
1
+ {"version":3,"file":"typed-walk.cjs","sources":["../../../../src/application/transform/ref-pointer/typed-walk.ts"],"sourcesContent":["import { irIndexedAccess, irKeyword, irReference } from \"../../../domain/ir/constructors.js\";\nimport type { IrKeyword, IrType } from \"../../../domain/ir/nodes.js\";\nimport { indexBy, indexKeyword, rootType } from \"../ref-type.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport { isArrayShape, isObjectShape } from \"./generated-shape.js\";\nimport {\n childLocation,\n followLocated,\n followRefs,\n isJsonObject,\n type LocatedNode,\n} from \"./located-node.js\";\nimport {\n type ContentForm,\n headerParameterContentForm,\n isExcludedOperation,\n isOptionalHeader,\n isOptionalRequestBody,\n isParameterList,\n isTypedAsSchema,\n leadingLocated,\n leadingSegmentsOf,\n type RefPointer,\n startsInSchema,\n} from \"./pointer-walk.js\";\nimport {\n hasKeptProperties,\n isExcludedProperty,\n isMarkedProperty,\n type Presence,\n propertyPresence,\n schemaPresence,\n} from \"./property-shape.js\";\n\n/**\n * The type of a `$ref` pointer as the generated types have it: the `schema` of a media type,\n * header or component parameter is its type, `items` is indexed by `number`,\n * `additionalProperties` by `string` where the index signature is its type alone, and a value\n * that may be `undefined` or `null` is wrapped in `NonNullable` before it is indexed. The walk\n * stops at a segment with no type of its own (`allOf/0`, `definitions/A`, operation\n * `parameters/0`): the caller types the target itself.\n */\n\nconst DEFS_KEYWORD = \"$defs\";\n\nexport interface TypedWalk {\n readonly type: IrType;\n /** The document node the type stands for (not followed through a `$ref`). */\n readonly node: unknown;\n /** The node's JSON Pointer, where the generator writes its type (`LocatedNode`). */\n readonly location: string | undefined;\n readonly isSchema: boolean;\n /** The segment is a property or `$defs` name, not a keyword. */\n readonly isName: boolean;\n /** The location of the map of names (`properties` or `$defs`) when `isName`. */\n readonly namesLocation?: string | undefined;\n /**\n * The node is the `content` of a header or parameter typed as its first media type, so the\n * next segment must name that media type and adds no member.\n */\n readonly isFirstMediaType?: boolean;\n readonly presence: Presence;\n}\n\nexport interface TypedWalkInput {\n readonly pointer: RefPointer;\n readonly options: SchemaOptions;\n readonly refs: RefResolver;\n}\n\n/** The walk result: a type, or the index of the first segment that has no type. */\nexport type TypedWalkResult =\n | { readonly kind: \"typed\"; readonly walk: TypedWalk }\n | { readonly kind: \"untyped\"; readonly index: number };\n\nfunction present(walk: TypedWalk): IrType {\n return walk.presence === \"present\" ? walk.type : irReference(\"NonNullable\", [walk.type]);\n}\n\nfunction indexEntries(walk: TypedWalk, key: IrKeyword, keyword: string, refs: RefResolver) {\n const owner = followLocated(walk, refs);\n const child = isJsonObject(owner.node) ? owner.node[keyword] : undefined;\n return {\n ...walk,\n type: irIndexedAccess(present(walk), irKeyword(key)),\n node: child,\n location: childLocation(owner.location, keyword),\n presence: schemaPresence(child, refs),\n };\n}\n\n/**\n * A property `--exclude-deprecated` left out has no member to index, and the `$Read<T>` or\n * `$Write<T>` of a marked property has no member but the marker's: such a pointer is typed in\n * place.\n */\nfunction nameStep(walk: TypedWalk, name: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followLocated(walk, input.refs);\n const { node } = owner;\n const properties = isJsonObject(node) && isJsonObject(node.properties) ? node.properties : {};\n const value = properties[name];\n const { options, refs } = input;\n const isMarkedOnTheWay = !isLast && isMarkedProperty(value, options, refs);\n if (isExcludedProperty(value, options, refs) || isMarkedOnTheWay) {\n return null;\n }\n const type =\n walk.presence === \"present\"\n ? indexKeyword(walk.type, name, isLast)\n : indexBy(present(walk), name);\n return {\n ...walk,\n type,\n node: value,\n location: childLocation(walk.namesLocation, name),\n isName: false,\n presence: propertyPresence(walk, name, input.options, input.refs),\n };\n}\n\n/** `$defs` is optional (`NonNullable` when more follows); its members are present. */\nfunction defsStep(walk: TypedWalk, owner: LocatedNode, isLast: boolean): TypedWalk {\n const { node } = owner;\n const defs = isJsonObject(node) && isJsonObject(node[DEFS_KEYWORD]) ? node[DEFS_KEYWORD] : {};\n const namesLocation = childLocation(owner.location, DEFS_KEYWORD);\n return {\n ...walk,\n type: indexKeyword(present(walk), DEFS_KEYWORD, isLast),\n // A node of its own, not in the document: its properties are the definitions.\n node: { properties: defs, required: Object.keys(defs) },\n location: namesLocation,\n namesLocation,\n isName: true,\n presence: \"present\",\n };\n}\n\nconst COMPOSITION_KEYWORDS = [\"allOf\", \"anyOf\", \"oneOf\"] as const;\n\nconst SHAPED_KEYWORDS: ReadonlySet<string> = new Set([\n \"properties\",\n \"items\",\n \"additionalProperties\",\n]);\n\n/**\n * Whether the keyword gives the owner's generated type a member: `items` only an array,\n * `properties` and `additionalProperties` only an object (`type: string` ignores them). A node\n * that is not in the document is indexed as the keyword says.\n */\nfunction hasKeywordMember(owner: unknown, segment: string): boolean {\n if (!SHAPED_KEYWORDS.has(segment) || !isJsonObject(owner)) {\n return true;\n }\n return segment === \"items\" ? isArrayShape(owner) : isObjectShape(owner);\n}\n\n/**\n * Whether `[string]` of the owner's type is its `additionalProperties` type. Not where the index\n * signature also holds pattern or property types (`withPropertyTypes`), nor next to `allOf` /\n * `anyOf` / `oneOf`, whose members may add an index signature or an inherited discriminator.\n */\nfunction isIndexedByValue(owner: unknown, input: TypedWalkInput): boolean {\n if (!isJsonObject(owner)) {\n return true;\n }\n const patterns = owner.patternProperties;\n const hasPatterns = isJsonObject(patterns) && Object.keys(patterns).length > 0;\n const isComposed = COMPOSITION_KEYWORDS.some((keyword) => keyword in owner);\n return !hasPatterns && !isComposed && !hasKeptProperties(owner, input.options, input.refs);\n}\n\nfunction keywordStep(walk: TypedWalk, segment: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followLocated(walk, input.refs);\n if (!hasKeywordMember(owner.node, segment)) {\n return null;\n }\n switch (segment) {\n case \"properties\":\n return { ...walk, isName: true, namesLocation: childLocation(owner.location, segment) };\n case \"items\":\n return indexEntries(walk, \"number\", \"items\", input.refs);\n case \"additionalProperties\":\n // Otherwise the walk stops, and the target is typed in place.\n return isIndexedByValue(owner.node, input)\n ? indexEntries(walk, \"string\", \"additionalProperties\", input.refs)\n : null;\n case DEFS_KEYWORD:\n return defsStep(walk, owner, isLast);\n default:\n return null;\n }\n}\n\nfunction containerStep(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk {\n const segment = input.pointer.segments[index] as string;\n const owner = followRefs(walk.node, input.refs);\n const isOptional =\n (segment === \"requestBody\" && isOptionalRequestBody(owner, input.refs)) ||\n isOptionalHeader(input.pointer, index, owner);\n return {\n ...walk,\n type: indexBy(present(walk), segment),\n node: isJsonObject(owner) ? owner[segment] : undefined,\n location: childLocation(followLocated(walk, input.refs).location, segment),\n presence: isOptional ? \"absent\" : \"present\",\n };\n}\n\n/**\n * The `content` of a header or parameter: no member of its own, since the type holds its media\n * types (or the first one's type). Untyped where the type is `string` or a `schema`'s, and as the\n * last segment of the first media type form, whose type is not the map's.\n */\nfunction contentStep(walk: TypedWalk, form: ContentForm, isLast: boolean, refs: RefResolver) {\n const isMapTyped = form === \"media-type-members\" || (form === \"first-media-type\" && !isLast);\n if (!isMapTyped) {\n return null;\n }\n const owner = followLocated(walk, refs);\n return {\n ...walk,\n node: isJsonObject(owner.node) ? owner.node.content : undefined,\n location: childLocation(owner.location, \"content\"),\n isFirstMediaType: form === \"first-media-type\",\n };\n}\n\n/** The first media type of such a `content` is the type itself; another one has no type. */\nfunction firstMediaTypeStep(walk: TypedWalk, segment: string): TypedWalk | null {\n const content = isJsonObject(walk.node) ? walk.node : {};\n if (Object.keys(content)[0] !== segment) {\n return null;\n }\n const location = childLocation(walk.location, segment);\n return { ...walk, node: content[segment], location, isFirstMediaType: false };\n}\n\nfunction schemaStep(walk: TypedWalk, refs: RefResolver): TypedWalk {\n const owner = followLocated(walk, refs);\n const schema = isJsonObject(owner.node) ? owner.node.schema : undefined;\n const location = childLocation(owner.location, \"schema\");\n // The container's type is its schema's type: an optional header stays optional.\n const presence = walk.presence === \"absent\" ? \"absent\" : schemaPresence(schema, refs);\n return { ...walk, node: schema, location, isSchema: true, presence };\n}\n\nfunction documentStep(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk | null {\n const owner = followRefs(walk.node, input.refs);\n const form = headerParameterContentForm(input.pointer, index, owner, input.options);\n if (form !== null) {\n const isLast = index === input.pointer.segments.length - 1;\n return contentStep(walk, form, isLast, input.refs);\n }\n if (\n isParameterList(input.pointer, index) ||\n isExcludedOperation(input.pointer, index, owner, input)\n ) {\n return null;\n }\n return containerStep(walk, index, input);\n}\n\nfunction step(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk | null {\n const { segments } = input.pointer;\n const segment = segments[index] as string;\n const isLast = index === segments.length - 1;\n if (walk.isSchema) {\n return walk.isName\n ? nameStep(walk, segment, isLast, input)\n : keywordStep(walk, segment, isLast, input);\n }\n if (walk.isFirstMediaType) {\n return firstMediaTypeStep(walk, segment);\n }\n if (segment === \"schema\" && isTypedAsSchema(input.pointer, index)) {\n return schemaStep(walk, input.refs);\n }\n return documentStep(walk, index, input);\n}\n\n/** Walk the whole pointer; see the module comment. */\nexport function typedWalk(input: TypedWalkInput): TypedWalkResult {\n const { pointer } = input;\n const { node, location } = leadingLocated(pointer, input.refs);\n const isSchema = startsInSchema(pointer);\n let walk: TypedWalk = {\n type: indexBy(\n rootType(pointer.rootSegment, false),\n ...pointer.segments.slice(0, leadingSegmentsOf(pointer)),\n ),\n node,\n location,\n isSchema,\n isName: false,\n presence: isSchema ? schemaPresence(node, input.refs) : \"present\",\n };\n for (let index = leadingSegmentsOf(pointer); index < pointer.segments.length; index++) {\n const next = step(walk, index, input);\n if (next === null) {\n return { kind: \"untyped\", index };\n }\n walk = next;\n }\n return { kind: \"typed\", walk };\n}\n"],"names":["irReference","followLocated","isJsonObject","irIndexedAccess","irKeyword","childLocation","schemaPresence","isMarkedProperty","isExcludedProperty","indexKeyword","indexBy","propertyPresence","isArrayShape","isObjectShape","hasKeptProperties","followRefs","isOptionalRequestBody","isOptionalHeader","headerParameterContentForm","isParameterList","isExcludedOperation","isTypedAsSchema","leadingLocated","startsInSchema","rootType","leadingSegmentsO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,EAAa,KAAK,CAAA;AAAA,MACnC,GAAG,OAAA,CAAQ,QAAA,CAAS,MAAM,CAAA,EAAGC,6BAAA,CAAkB,OAAO,CAAC;AAAA,KACzD;AAAA,IACA,IAAA;AAAA,IACA,QAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA,EAAQ,KAAA;AAAA,IACR,UAAU,QAAA,GAAWnB,4BAAA,CAAe,IAAA,EAAM,KAAA,CAAM,IAAI,CAAA,GAAI;AAAA,GAC1D;AACA,EAAA,KAAA,IAAS,KAAA,GAAQmB,8BAAkB,OAAO,CAAA,EAAG,QAAQ,OAAA,CAAQ,QAAA,CAAS,QAAQ,KAAA,EAAA,EAAS;AACrF,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,IAAA,EAAM,KAAA,EAAO,KAAK,CAAA;AACpC,IAAA,IAAI,SAAS,IAAA,EAAM;AACjB,MAAA,OAAO,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAM;AAAA,IAClC;AACA,IAAA,IAAA,GAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAK;AAC/B;;"}
@@ -1,44 +1,61 @@
1
1
  import { irReference, irIndexedAccess, irKeyword } from '../../../domain/ir/constructors.mjs';
2
2
  import { indexBy, rootType, indexKeyword } from '../ref-type.mjs';
3
- import { schemaPresence, followRefs, isJsonObject, propertyPresence, isArrayShape, isObjectShape } from './generated-shape.mjs';
4
- import { leadingNode, startsInSchema, leadingSegmentsOf, isTypedAsSchema, isParameterList, isOptionalRequestBody, isOptionalHeader } from './pointer-walk.mjs';
3
+ import { isArrayShape, isObjectShape } from './generated-shape.mjs';
4
+ import { followLocated, isJsonObject, childLocation, followRefs } from './located-node.mjs';
5
+ import { leadingLocated, startsInSchema, leadingSegmentsOf, isTypedAsSchema, headerParameterContentForm, isParameterList, isExcludedOperation, isOptionalRequestBody, isOptionalHeader } from './pointer-walk.mjs';
6
+ import { schemaPresence, isMarkedProperty, isExcludedProperty, propertyPresence, hasKeptProperties } from './property-shape.mjs';
5
7
 
6
8
  const DEFS_KEYWORD = "$defs";
7
9
  function present(walk) {
8
10
  return walk.presence === "present" ? walk.type : irReference("NonNullable", [walk.type]);
9
11
  }
10
12
  function indexEntries(walk, key, keyword, refs) {
11
- const owner = followRefs(walk.node, refs);
12
- const child = isJsonObject(owner) ? owner[keyword] : void 0;
13
+ const owner = followLocated(walk, refs);
14
+ const child = isJsonObject(owner.node) ? owner.node[keyword] : void 0;
13
15
  return {
14
16
  ...walk,
15
17
  type: irIndexedAccess(present(walk), irKeyword(key)),
16
18
  node: child,
19
+ location: childLocation(owner.location, keyword),
17
20
  presence: schemaPresence(child, refs)
18
21
  };
19
22
  }
20
23
  function nameStep(walk, name, isLast, input) {
21
- const owner = followRefs(walk.node, input.refs);
22
- const properties = isJsonObject(owner) && isJsonObject(owner.properties) ? owner.properties : {};
24
+ const owner = followLocated(walk, input.refs);
25
+ const { node } = owner;
26
+ const properties = isJsonObject(node) && isJsonObject(node.properties) ? node.properties : {};
27
+ const value = properties[name];
28
+ const { options, refs } = input;
29
+ const isMarkedOnTheWay = !isLast && isMarkedProperty(value, options, refs);
30
+ if (isExcludedProperty(value, options, refs) || isMarkedOnTheWay) {
31
+ return null;
32
+ }
23
33
  const type = walk.presence === "present" ? indexKeyword(walk.type, name, isLast) : indexBy(present(walk), name);
24
34
  return {
25
35
  ...walk,
26
36
  type,
27
- node: properties[name],
37
+ node: value,
38
+ location: childLocation(walk.namesLocation, name),
28
39
  isName: false,
29
- presence: propertyPresence(walk.node, name, input.options, input.refs)
40
+ presence: propertyPresence(walk, name, input.options, input.refs)
30
41
  };
31
42
  }
32
43
  function defsStep(walk, owner, isLast) {
33
- const defs = isJsonObject(owner) && isJsonObject(owner[DEFS_KEYWORD]) ? owner[DEFS_KEYWORD] : {};
44
+ const { node } = owner;
45
+ const defs = isJsonObject(node) && isJsonObject(node[DEFS_KEYWORD]) ? node[DEFS_KEYWORD] : {};
46
+ const namesLocation = childLocation(owner.location, DEFS_KEYWORD);
34
47
  return {
35
48
  ...walk,
36
49
  type: indexKeyword(present(walk), DEFS_KEYWORD, isLast),
50
+ // A node of its own, not in the document: its properties are the definitions.
37
51
  node: { properties: defs, required: Object.keys(defs) },
52
+ location: namesLocation,
53
+ namesLocation,
38
54
  isName: true,
39
55
  presence: "present"
40
56
  };
41
57
  }
58
+ const COMPOSITION_KEYWORDS = ["allOf", "anyOf", "oneOf"];
42
59
  const SHAPED_KEYWORDS = /* @__PURE__ */ new Set([
43
60
  "properties",
44
61
  "items",
@@ -50,18 +67,27 @@ function hasKeywordMember(owner, segment) {
50
67
  }
51
68
  return segment === "items" ? isArrayShape(owner) : isObjectShape(owner);
52
69
  }
70
+ function isIndexedByValue(owner, input) {
71
+ if (!isJsonObject(owner)) {
72
+ return true;
73
+ }
74
+ const patterns = owner.patternProperties;
75
+ const hasPatterns = isJsonObject(patterns) && Object.keys(patterns).length > 0;
76
+ const isComposed = COMPOSITION_KEYWORDS.some((keyword) => keyword in owner);
77
+ return !hasPatterns && !isComposed && !hasKeptProperties(owner, input.options, input.refs);
78
+ }
53
79
  function keywordStep(walk, segment, isLast, input) {
54
- const owner = followRefs(walk.node, input.refs);
55
- if (!hasKeywordMember(owner, segment)) {
80
+ const owner = followLocated(walk, input.refs);
81
+ if (!hasKeywordMember(owner.node, segment)) {
56
82
  return null;
57
83
  }
58
84
  switch (segment) {
59
85
  case "properties":
60
- return { ...walk, isName: true };
86
+ return { ...walk, isName: true, namesLocation: childLocation(owner.location, segment) };
61
87
  case "items":
62
88
  return indexEntries(walk, "number", "items", input.refs);
63
89
  case "additionalProperties":
64
- return indexEntries(walk, "string", "additionalProperties", input.refs);
90
+ return isIndexedByValue(owner.node, input) ? indexEntries(walk, "string", "additionalProperties", input.refs) : null;
65
91
  case DEFS_KEYWORD:
66
92
  return defsStep(walk, owner, isLast);
67
93
  default:
@@ -76,9 +102,50 @@ function containerStep(walk, index, input) {
76
102
  ...walk,
77
103
  type: indexBy(present(walk), segment),
78
104
  node: isJsonObject(owner) ? owner[segment] : void 0,
105
+ location: childLocation(followLocated(walk, input.refs).location, segment),
79
106
  presence: isOptional ? "absent" : "present"
80
107
  };
81
108
  }
109
+ function contentStep(walk, form, isLast, refs) {
110
+ const isMapTyped = form === "media-type-members" || form === "first-media-type" && !isLast;
111
+ if (!isMapTyped) {
112
+ return null;
113
+ }
114
+ const owner = followLocated(walk, refs);
115
+ return {
116
+ ...walk,
117
+ node: isJsonObject(owner.node) ? owner.node.content : void 0,
118
+ location: childLocation(owner.location, "content"),
119
+ isFirstMediaType: form === "first-media-type"
120
+ };
121
+ }
122
+ function firstMediaTypeStep(walk, segment) {
123
+ const content = isJsonObject(walk.node) ? walk.node : {};
124
+ if (Object.keys(content)[0] !== segment) {
125
+ return null;
126
+ }
127
+ const location = childLocation(walk.location, segment);
128
+ return { ...walk, node: content[segment], location, isFirstMediaType: false };
129
+ }
130
+ function schemaStep(walk, refs) {
131
+ const owner = followLocated(walk, refs);
132
+ const schema = isJsonObject(owner.node) ? owner.node.schema : void 0;
133
+ const location = childLocation(owner.location, "schema");
134
+ const presence = walk.presence === "absent" ? "absent" : schemaPresence(schema, refs);
135
+ return { ...walk, node: schema, location, isSchema: true, presence };
136
+ }
137
+ function documentStep(walk, index, input) {
138
+ const owner = followRefs(walk.node, input.refs);
139
+ const form = headerParameterContentForm(input.pointer, index, owner, input.options);
140
+ if (form !== null) {
141
+ const isLast = index === input.pointer.segments.length - 1;
142
+ return contentStep(walk, form, isLast, input.refs);
143
+ }
144
+ if (isParameterList(input.pointer, index) || isExcludedOperation(input.pointer, index, owner, input)) {
145
+ return null;
146
+ }
147
+ return containerStep(walk, index, input);
148
+ }
82
149
  function step(walk, index, input) {
83
150
  const { segments } = input.pointer;
84
151
  const segment = segments[index];
@@ -86,17 +153,17 @@ function step(walk, index, input) {
86
153
  if (walk.isSchema) {
87
154
  return walk.isName ? nameStep(walk, segment, isLast, input) : keywordStep(walk, segment, isLast, input);
88
155
  }
156
+ if (walk.isFirstMediaType) {
157
+ return firstMediaTypeStep(walk, segment);
158
+ }
89
159
  if (segment === "schema" && isTypedAsSchema(input.pointer, index)) {
90
- const owner = followRefs(walk.node, input.refs);
91
- const schema = isJsonObject(owner) ? owner.schema : void 0;
92
- const presence = walk.presence === "absent" ? "absent" : schemaPresence(schema, input.refs);
93
- return { ...walk, node: schema, isSchema: true, presence };
160
+ return schemaStep(walk, input.refs);
94
161
  }
95
- return isParameterList(input.pointer, index) ? null : containerStep(walk, index, input);
162
+ return documentStep(walk, index, input);
96
163
  }
97
164
  function typedWalk(input) {
98
165
  const { pointer } = input;
99
- const node = leadingNode(pointer, input.refs);
166
+ const { node, location } = leadingLocated(pointer, input.refs);
100
167
  const isSchema = startsInSchema(pointer);
101
168
  let walk = {
102
169
  type: indexBy(
@@ -104,6 +171,7 @@ function typedWalk(input) {
104
171
  ...pointer.segments.slice(0, leadingSegmentsOf(pointer))
105
172
  ),
106
173
  node,
174
+ location,
107
175
  isSchema,
108
176
  isName: false,
109
177
  presence: isSchema ? schemaPresence(node, input.refs) : "present"
@@ -1 +1 @@
1
- {"version":3,"file":"typed-walk.mjs","sources":["../../../../src/application/transform/ref-pointer/typed-walk.ts"],"sourcesContent":["import { irIndexedAccess, irKeyword, irReference } from \"../../../domain/ir/constructors.js\";\nimport type { IrKeyword, IrType } from \"../../../domain/ir/nodes.js\";\nimport { indexBy, indexKeyword, rootType } from \"../ref-type.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport {\n followRefs,\n isArrayShape,\n isJsonObject,\n isObjectShape,\n type Presence,\n propertyPresence,\n schemaPresence,\n} from \"./generated-shape.js\";\nimport {\n isOptionalHeader,\n isOptionalRequestBody,\n isParameterList,\n isTypedAsSchema,\n leadingNode,\n leadingSegmentsOf,\n type RefPointer,\n startsInSchema,\n} from \"./pointer-walk.js\";\n\n/**\n * The type of a `$ref` pointer as the generated types have it: the `schema` of a media type,\n * header or component parameter is its type, `items` is indexed by `number`,\n * `additionalProperties` by `string`, and a value that may be `undefined` or `null` is wrapped in\n * `NonNullable` before it is indexed. The walk stops at a segment with no type of its own\n * (`allOf/0`, `definitions/A`, operation `parameters/0`): the caller types the target itself.\n */\n\nconst DEFS_KEYWORD = \"$defs\";\n\nexport interface TypedWalk {\n readonly type: IrType;\n /** The document node the type stands for (not followed through a `$ref`). */\n readonly node: unknown;\n readonly isSchema: boolean;\n /** The segment is a property or `$defs` name, not a keyword. */\n readonly isName: boolean;\n readonly presence: Presence;\n}\n\nexport interface TypedWalkInput {\n readonly pointer: RefPointer;\n readonly options: SchemaOptions;\n readonly refs: RefResolver;\n}\n\n/** The walk result: a type, or the index of the first segment that has no type. */\nexport type TypedWalkResult =\n | { readonly kind: \"typed\"; readonly walk: TypedWalk }\n | { readonly kind: \"untyped\"; readonly index: number };\n\nfunction present(walk: TypedWalk): IrType {\n return walk.presence === \"present\" ? walk.type : irReference(\"NonNullable\", [walk.type]);\n}\n\nfunction indexEntries(walk: TypedWalk, key: IrKeyword, keyword: string, refs: RefResolver) {\n const owner = followRefs(walk.node, refs);\n const child = isJsonObject(owner) ? owner[keyword] : undefined;\n return {\n ...walk,\n type: irIndexedAccess(present(walk), irKeyword(key)),\n node: child,\n presence: schemaPresence(child, refs),\n };\n}\n\nfunction nameStep(walk: TypedWalk, name: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followRefs(walk.node, input.refs);\n const properties = isJsonObject(owner) && isJsonObject(owner.properties) ? owner.properties : {};\n const type =\n walk.presence === \"present\"\n ? indexKeyword(walk.type, name, isLast)\n : indexBy(present(walk), name);\n return {\n ...walk,\n type,\n node: properties[name],\n isName: false,\n presence: propertyPresence(walk.node, name, input.options, input.refs),\n };\n}\n\n/** `$defs` is optional (`NonNullable` when more follows); its members are present. */\nfunction defsStep(walk: TypedWalk, owner: unknown, isLast: boolean): TypedWalk {\n const defs = isJsonObject(owner) && isJsonObject(owner[DEFS_KEYWORD]) ? owner[DEFS_KEYWORD] : {};\n return {\n ...walk,\n type: indexKeyword(present(walk), DEFS_KEYWORD, isLast),\n node: { properties: defs, required: Object.keys(defs) },\n isName: true,\n presence: \"present\",\n };\n}\n\nconst SHAPED_KEYWORDS: ReadonlySet<string> = new Set([\n \"properties\",\n \"items\",\n \"additionalProperties\",\n]);\n\n/**\n * Whether the keyword gives the owner's generated type a member: `items` only an array,\n * `properties` and `additionalProperties` only an object (`type: string` ignores them). A node\n * that is not in the document is indexed as the keyword says.\n */\nfunction hasKeywordMember(owner: unknown, segment: string): boolean {\n if (!SHAPED_KEYWORDS.has(segment) || !isJsonObject(owner)) {\n return true;\n }\n return segment === \"items\" ? isArrayShape(owner) : isObjectShape(owner);\n}\n\nfunction keywordStep(walk: TypedWalk, segment: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followRefs(walk.node, input.refs);\n if (!hasKeywordMember(owner, segment)) {\n return null;\n }\n switch (segment) {\n case \"properties\":\n return { ...walk, isName: true };\n case \"items\":\n return indexEntries(walk, \"number\", \"items\", input.refs);\n case \"additionalProperties\":\n return indexEntries(walk, \"string\", \"additionalProperties\", input.refs);\n case DEFS_KEYWORD:\n return defsStep(walk, owner, isLast);\n default:\n return null;\n }\n}\n\nfunction containerStep(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk {\n const segment = input.pointer.segments[index] as string;\n const owner = followRefs(walk.node, input.refs);\n const isOptional =\n (segment === \"requestBody\" && isOptionalRequestBody(owner, input.refs)) ||\n isOptionalHeader(input.pointer, index, owner);\n return {\n ...walk,\n type: indexBy(present(walk), segment),\n node: isJsonObject(owner) ? owner[segment] : undefined,\n presence: isOptional ? \"absent\" : \"present\",\n };\n}\n\nfunction step(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk | null {\n const { segments } = input.pointer;\n const segment = segments[index] as string;\n const isLast = index === segments.length - 1;\n if (walk.isSchema) {\n return walk.isName\n ? nameStep(walk, segment, isLast, input)\n : keywordStep(walk, segment, isLast, input);\n }\n if (segment === \"schema\" && isTypedAsSchema(input.pointer, index)) {\n const owner = followRefs(walk.node, input.refs);\n const schema = isJsonObject(owner) ? owner.schema : undefined;\n // The container's type is its schema's type: an optional header stays optional.\n const presence = walk.presence === \"absent\" ? \"absent\" : schemaPresence(schema, input.refs);\n return { ...walk, node: schema, isSchema: true, presence };\n }\n return isParameterList(input.pointer, index) ? null : containerStep(walk, index, input);\n}\n\n/** Walk the whole pointer; see the module comment. */\nexport function typedWalk(input: TypedWalkInput): TypedWalkResult {\n const { pointer } = input;\n const node = leadingNode(pointer, input.refs);\n const isSchema = startsInSchema(pointer);\n let walk: TypedWalk = {\n type: indexBy(\n rootType(pointer.rootSegment, false),\n ...pointer.segments.slice(0, leadingSegmentsOf(pointer)),\n ),\n node,\n isSchema,\n isName: false,\n presence: isSchema ? schemaPresence(node, input.refs) : \"present\",\n };\n for (let index = leadingSegmentsOf(pointer); index < pointer.segments.length; index++) {\n const next = step(walk, index, input);\n if (next === null) {\n return { kind: \"untyped\", index };\n }\n walk = next;\n }\n return { kind: \"typed\", walk };\n}\n"],"names":[],"mappings":";;;;;AAgCA,MAAM,YAAA,GAAe,OAAA;AAuBrB,SAAS,QAAQ,IAAA,EAAyB;AACxC,EAAA,OAAO,IAAA,CAAK,QAAA,KAAa,SAAA,GAAY,IAAA,CAAK,IAAA,GAAO,YAAY,aAAA,EAAe,CAAC,IAAA,CAAK,IAAI,CAAC,CAAA;AACzF;AAEA,SAAS,YAAA,CAAa,IAAA,EAAiB,GAAA,EAAgB,OAAA,EAAiB,IAAA,EAAmB;AACzF,EAAA,MAAM,KAAA,GAAQ,UAAA,CAAW,IAAA,CAAK,IAAA,EAAM,IAAI,CAAA;AACxC,EAAA,MAAM,QAAQ,YAAA,CAAa,KAAK,CAAA,GAAI,KAAA,CAAM,OAAO,CAAA,GAAI,MAAA;AACrD,EAAA,OAAO;AAAA,IACL,GAAG,IAAA;AAAA,IACH,MAAM,eAAA,CAAgB,OAAA,CAAQ,IAAI,CAAA,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IAAA,EAAM,KAAA,EAAO,KAAK,CAAA;AACpC,IAAA,IAAI,SAAS,IAAA,EAAM;AACjB,MAAA,OAAO,EAAE,IAAA,EAAM,SAAA,EAAW,KAAA,EAAM;AAAA,IAClC;AACA,IAAA,IAAA,GAAO,IAAA;AAAA,EACT;AACA,EAAA,OAAO,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAK;AAC/B;;"}
1
+ {"version":3,"file":"typed-walk.mjs","sources":["../../../../src/application/transform/ref-pointer/typed-walk.ts"],"sourcesContent":["import { irIndexedAccess, irKeyword, irReference } from \"../../../domain/ir/constructors.js\";\nimport type { IrKeyword, IrType } from \"../../../domain/ir/nodes.js\";\nimport { indexBy, indexKeyword, rootType } from \"../ref-type.js\";\nimport type { RefResolver, SchemaOptions } from \"../schema/schema-context.js\";\nimport { isArrayShape, isObjectShape } from \"./generated-shape.js\";\nimport {\n childLocation,\n followLocated,\n followRefs,\n isJsonObject,\n type LocatedNode,\n} from \"./located-node.js\";\nimport {\n type ContentForm,\n headerParameterContentForm,\n isExcludedOperation,\n isOptionalHeader,\n isOptionalRequestBody,\n isParameterList,\n isTypedAsSchema,\n leadingLocated,\n leadingSegmentsOf,\n type RefPointer,\n startsInSchema,\n} from \"./pointer-walk.js\";\nimport {\n hasKeptProperties,\n isExcludedProperty,\n isMarkedProperty,\n type Presence,\n propertyPresence,\n schemaPresence,\n} from \"./property-shape.js\";\n\n/**\n * The type of a `$ref` pointer as the generated types have it: the `schema` of a media type,\n * header or component parameter is its type, `items` is indexed by `number`,\n * `additionalProperties` by `string` where the index signature is its type alone, and a value\n * that may be `undefined` or `null` is wrapped in `NonNullable` before it is indexed. The walk\n * stops at a segment with no type of its own (`allOf/0`, `definitions/A`, operation\n * `parameters/0`): the caller types the target itself.\n */\n\nconst DEFS_KEYWORD = \"$defs\";\n\nexport interface TypedWalk {\n readonly type: IrType;\n /** The document node the type stands for (not followed through a `$ref`). */\n readonly node: unknown;\n /** The node's JSON Pointer, where the generator writes its type (`LocatedNode`). */\n readonly location: string | undefined;\n readonly isSchema: boolean;\n /** The segment is a property or `$defs` name, not a keyword. */\n readonly isName: boolean;\n /** The location of the map of names (`properties` or `$defs`) when `isName`. */\n readonly namesLocation?: string | undefined;\n /**\n * The node is the `content` of a header or parameter typed as its first media type, so the\n * next segment must name that media type and adds no member.\n */\n readonly isFirstMediaType?: boolean;\n readonly presence: Presence;\n}\n\nexport interface TypedWalkInput {\n readonly pointer: RefPointer;\n readonly options: SchemaOptions;\n readonly refs: RefResolver;\n}\n\n/** The walk result: a type, or the index of the first segment that has no type. */\nexport type TypedWalkResult =\n | { readonly kind: \"typed\"; readonly walk: TypedWalk }\n | { readonly kind: \"untyped\"; readonly index: number };\n\nfunction present(walk: TypedWalk): IrType {\n return walk.presence === \"present\" ? walk.type : irReference(\"NonNullable\", [walk.type]);\n}\n\nfunction indexEntries(walk: TypedWalk, key: IrKeyword, keyword: string, refs: RefResolver) {\n const owner = followLocated(walk, refs);\n const child = isJsonObject(owner.node) ? owner.node[keyword] : undefined;\n return {\n ...walk,\n type: irIndexedAccess(present(walk), irKeyword(key)),\n node: child,\n location: childLocation(owner.location, keyword),\n presence: schemaPresence(child, refs),\n };\n}\n\n/**\n * A property `--exclude-deprecated` left out has no member to index, and the `$Read<T>` or\n * `$Write<T>` of a marked property has no member but the marker's: such a pointer is typed in\n * place.\n */\nfunction nameStep(walk: TypedWalk, name: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followLocated(walk, input.refs);\n const { node } = owner;\n const properties = isJsonObject(node) && isJsonObject(node.properties) ? node.properties : {};\n const value = properties[name];\n const { options, refs } = input;\n const isMarkedOnTheWay = !isLast && isMarkedProperty(value, options, refs);\n if (isExcludedProperty(value, options, refs) || isMarkedOnTheWay) {\n return null;\n }\n const type =\n walk.presence === \"present\"\n ? indexKeyword(walk.type, name, isLast)\n : indexBy(present(walk), name);\n return {\n ...walk,\n type,\n node: value,\n location: childLocation(walk.namesLocation, name),\n isName: false,\n presence: propertyPresence(walk, name, input.options, input.refs),\n };\n}\n\n/** `$defs` is optional (`NonNullable` when more follows); its members are present. */\nfunction defsStep(walk: TypedWalk, owner: LocatedNode, isLast: boolean): TypedWalk {\n const { node } = owner;\n const defs = isJsonObject(node) && isJsonObject(node[DEFS_KEYWORD]) ? node[DEFS_KEYWORD] : {};\n const namesLocation = childLocation(owner.location, DEFS_KEYWORD);\n return {\n ...walk,\n type: indexKeyword(present(walk), DEFS_KEYWORD, isLast),\n // A node of its own, not in the document: its properties are the definitions.\n node: { properties: defs, required: Object.keys(defs) },\n location: namesLocation,\n namesLocation,\n isName: true,\n presence: \"present\",\n };\n}\n\nconst COMPOSITION_KEYWORDS = [\"allOf\", \"anyOf\", \"oneOf\"] as const;\n\nconst SHAPED_KEYWORDS: ReadonlySet<string> = new Set([\n \"properties\",\n \"items\",\n \"additionalProperties\",\n]);\n\n/**\n * Whether the keyword gives the owner's generated type a member: `items` only an array,\n * `properties` and `additionalProperties` only an object (`type: string` ignores them). A node\n * that is not in the document is indexed as the keyword says.\n */\nfunction hasKeywordMember(owner: unknown, segment: string): boolean {\n if (!SHAPED_KEYWORDS.has(segment) || !isJsonObject(owner)) {\n return true;\n }\n return segment === \"items\" ? isArrayShape(owner) : isObjectShape(owner);\n}\n\n/**\n * Whether `[string]` of the owner's type is its `additionalProperties` type. Not where the index\n * signature also holds pattern or property types (`withPropertyTypes`), nor next to `allOf` /\n * `anyOf` / `oneOf`, whose members may add an index signature or an inherited discriminator.\n */\nfunction isIndexedByValue(owner: unknown, input: TypedWalkInput): boolean {\n if (!isJsonObject(owner)) {\n return true;\n }\n const patterns = owner.patternProperties;\n const hasPatterns = isJsonObject(patterns) && Object.keys(patterns).length > 0;\n const isComposed = COMPOSITION_KEYWORDS.some((keyword) => keyword in owner);\n return !hasPatterns && !isComposed && !hasKeptProperties(owner, input.options, input.refs);\n}\n\nfunction keywordStep(walk: TypedWalk, segment: string, isLast: boolean, input: TypedWalkInput) {\n const owner = followLocated(walk, input.refs);\n if (!hasKeywordMember(owner.node, segment)) {\n return null;\n }\n switch (segment) {\n case \"properties\":\n return { ...walk, isName: true, namesLocation: childLocation(owner.location, segment) };\n case \"items\":\n return indexEntries(walk, \"number\", \"items\", input.refs);\n case \"additionalProperties\":\n // Otherwise the walk stops, and the target is typed in place.\n return isIndexedByValue(owner.node, input)\n ? indexEntries(walk, \"string\", \"additionalProperties\", input.refs)\n : null;\n case DEFS_KEYWORD:\n return defsStep(walk, owner, isLast);\n default:\n return null;\n }\n}\n\nfunction containerStep(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk {\n const segment = input.pointer.segments[index] as string;\n const owner = followRefs(walk.node, input.refs);\n const isOptional =\n (segment === \"requestBody\" && isOptionalRequestBody(owner, input.refs)) ||\n isOptionalHeader(input.pointer, index, owner);\n return {\n ...walk,\n type: indexBy(present(walk), segment),\n node: isJsonObject(owner) ? owner[segment] : undefined,\n location: childLocation(followLocated(walk, input.refs).location, segment),\n presence: isOptional ? \"absent\" : \"present\",\n };\n}\n\n/**\n * The `content` of a header or parameter: no member of its own, since the type holds its media\n * types (or the first one's type). Untyped where the type is `string` or a `schema`'s, and as the\n * last segment of the first media type form, whose type is not the map's.\n */\nfunction contentStep(walk: TypedWalk, form: ContentForm, isLast: boolean, refs: RefResolver) {\n const isMapTyped = form === \"media-type-members\" || (form === \"first-media-type\" && !isLast);\n if (!isMapTyped) {\n return null;\n }\n const owner = followLocated(walk, refs);\n return {\n ...walk,\n node: isJsonObject(owner.node) ? owner.node.content : undefined,\n location: childLocation(owner.location, \"content\"),\n isFirstMediaType: form === \"first-media-type\",\n };\n}\n\n/** The first media type of such a `content` is the type itself; another one has no type. */\nfunction firstMediaTypeStep(walk: TypedWalk, segment: string): TypedWalk | null {\n const content = isJsonObject(walk.node) ? walk.node : {};\n if (Object.keys(content)[0] !== segment) {\n return null;\n }\n const location = childLocation(walk.location, segment);\n return { ...walk, node: content[segment], location, isFirstMediaType: false };\n}\n\nfunction schemaStep(walk: TypedWalk, refs: RefResolver): TypedWalk {\n const owner = followLocated(walk, refs);\n const schema = isJsonObject(owner.node) ? owner.node.schema : undefined;\n const location = childLocation(owner.location, \"schema\");\n // The container's type is its schema's type: an optional header stays optional.\n const presence = walk.presence === \"absent\" ? \"absent\" : schemaPresence(schema, refs);\n return { ...walk, node: schema, location, isSchema: true, presence };\n}\n\nfunction documentStep(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk | null {\n const owner = followRefs(walk.node, input.refs);\n const form = headerParameterContentForm(input.pointer, index, owner, input.options);\n if (form !== null) {\n const isLast = index === input.pointer.segments.length - 1;\n return contentStep(walk, form, isLast, input.refs);\n }\n if (\n isParameterList(input.pointer, index) ||\n isExcludedOperation(input.pointer, index, owner, input)\n ) {\n return null;\n }\n return containerStep(walk, index, input);\n}\n\nfunction step(walk: TypedWalk, index: number, input: TypedWalkInput): TypedWalk | null {\n const { segments } = input.pointer;\n const segment = segments[index] as string;\n const isLast = index === segments.length - 1;\n if (walk.isSchema) {\n return walk.isName\n ? nameStep(walk, segment, isLast, input)\n : keywordStep(walk, segment, isLast, input);\n }\n if (walk.isFirstMediaType) {\n return firstMediaTypeStep(walk, segment);\n }\n if (segment === \"schema\" && isTypedAsSchema(input.pointer, index)) {\n return schemaStep(walk, input.refs);\n }\n return documentStep(walk, index, input);\n}\n\n/** Walk the whole pointer; see the module comment. */\nexport function typedWalk(input: TypedWalkInput): TypedWalkResult {\n const { pointer } = input;\n const { node, location } = leadingLocated(pointer, input.refs);\n const isSchema = startsInSchema(pointer);\n let walk: TypedWalk = {\n type: indexBy(\n rootType(pointer.rootSegment, false),\n ...pointer.segments.slice(0, leadingSegmentsOf(pointer)),\n ),\n node,\n location,\n isSchema,\n isName: false,\n presence: isSchema ? schemaPresence(node, input.refs) : \"present\",\n };\n for (let index = leadingSegmentsOf(pointer); index < pointer.segments.length; index++) {\n const next = step(walk, index, input);\n if (next === null) {\n return { kind: \"untyped\", index };\n }\n walk = next;\n }\n return { kind: \"typed\",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