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,34 @@
1
+ import { irReference, irKeyword } from '../../domain/ir/constructors.mjs';
2
+ import { HELPER_TYPES } from './helper-types.mjs';
3
+
4
+ function memberValueTypes(member) {
5
+ if (member.kind === "indexSignature") {
6
+ return [member.type];
7
+ }
8
+ return member.isOptional ? [member.type, irKeyword("undefined")] : [member.type];
9
+ }
10
+ function declaredValueTypes(type, footer) {
11
+ switch (type.kind) {
12
+ case "object":
13
+ return type.members.flatMap(memberValueTypes);
14
+ case "union":
15
+ case "intersection":
16
+ return type.types.flatMap((member) => declaredValueTypes(member, footer));
17
+ case "reference":
18
+ case "indexedAccess":
19
+ case "raw":
20
+ footer.requirePropertyValues();
21
+ return [irReference(HELPER_TYPES.propertyValues.name, [type])];
22
+ case "keyword":
23
+ case "stringLiteral":
24
+ case "numberLiteral":
25
+ case "booleanLiteral":
26
+ case "array":
27
+ case "tuple":
28
+ case "readonly":
29
+ return [];
30
+ }
31
+ }
32
+
33
+ export { declaredValueTypes };
34
+ //# sourceMappingURL=declared-value-types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declared-value-types.mjs","sources":["../../../src/application/transform/declared-value-types.ts"],"sourcesContent":["import { irKeyword, irReference } from \"../../domain/ir/constructors.js\";\nimport type { IrMember, IrType } from \"../../domain/ir/nodes.js\";\nimport { HELPER_TYPES } from \"./helper-types.js\";\nimport type { FooterDeclarations } from \"./schema/schema-context.js\";\n\n/** The footer part that declares the `PropertyValues` helper type. */\nexport type PropertyValuesFooter = Pick<FooterDeclarations, \"requirePropertyValues\">;\n\nfunction memberValueTypes(member: IrMember): IrType[] {\n if (member.kind === \"indexSignature\") {\n return [member.type];\n }\n return member.isOptional ? [member.type, irKeyword(\"undefined\")] : [member.type];\n}\n\n/**\n * The value types a key of the type can have, read from its IR: the members of object types,\n * through unions and intersections. A reference (a `$ref`, `Omit`, `WithRequired`) or a raw\n * type is read with `PropertyValues`. Primitives, literals and arrays declare no keys.\n */\nexport function declaredValueTypes(type: IrType, footer: PropertyValuesFooter): IrType[] {\n switch (type.kind) {\n case \"object\":\n return type.members.flatMap(memberValueTypes);\n case \"union\":\n case \"intersection\":\n return type.types.flatMap((member) => declaredValueTypes(member, footer));\n case \"reference\":\n case \"indexedAccess\":\n case \"raw\":\n footer.requirePropertyValues();\n return [irReference(HELPER_TYPES.propertyValues.name, [type])];\n case \"keyword\":\n case \"stringLiteral\":\n case \"numberLiteral\":\n case \"booleanLiteral\":\n case \"array\":\n case \"tuple\":\n case \"readonly\":\n return [];\n }\n}\n"],"names":[],"mappings":";;;AAQA,SAAS,iBAAiB,MAAA,EAA4B;AACpD,EAAA,IAAI,MAAA,CAAO,SAAS,gBAAA,EAAkB;AACpC,IAAA,OAAO,CAAC,OAAO,IAAI,CAAA;AAAA,EACrB;AACA,EAAA,OAAO,MAAA,CAAO,UAAA,GAAa,CAAC,MAAA,CAAO,IAAA,EAAM,SAAA,CAAU,WAAW,CAAC,CAAA,GAAI,CAAC,MAAA,CAAO,IAAI,CAAA;AACjF;AAOO,SAAS,kBAAA,CAAmB,MAAc,MAAA,EAAwC;AACvF,EAAA,QAAQ,KAAK,IAAA;AAAM,IACjB,KAAK,QAAA;AACH,MAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,OAAA,CAAQ,gBAAgB,CAAA;AAAA,IAC9C,KAAK,OAAA;AAAA,IACL,KAAK,cAAA;AACH,MAAA,OAAO,IAAA,CAAK,MAAM,OAAA,CAAQ,CAAC,WAAW,kBAAA,CAAmB,MAAA,EAAQ,MAAM,CAAC,CAAA;AAAA,IAC1E,KAAK,WAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,KAAA;AACH,MAAA,MAAA,CAAO,qBAAA,EAAsB;AAC7B,MAAA,OAAO,CAAC,YAAY,YAAA,CAAa,cAAA,CAAe,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;AAAA,IAC/D,KAAK,SAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,eAAA;AAAA,IACL,KAAK,gBAAA;AAAA,IACL,KAAK,OAAA;AAAA,IACL,KAAK,OAAA;AAAA,IACL,KAAK,UAAA;AACH,MAAA,OAAO,EAAC;AAAA;AAEd;;"}
@@ -7,6 +7,7 @@ const components = require('./components.cjs');
7
7
  const declaredTypes = require('./declared-types.cjs');
8
8
  const defsRoot = require('./defs-root.cjs');
9
9
  const keptDeprecated$1 = require('./kept-deprecated.cjs');
10
+ const pathItem = require('./path-item.cjs');
10
11
  const paths = require('./paths.cjs');
11
12
  const pathsEnum = require('./paths-enum.cjs');
12
13
  const webhooks = require('./webhooks.cjs');
@@ -100,7 +101,8 @@ function documentClosing(document, context, hasOperations) {
100
101
  declarations.push(emptyAlias(OPERATIONS_NAME));
101
102
  }
102
103
  if (context.options.makePathsEnum && document.paths) {
103
- declarations.push(pathsEnum.apiPathsEnumDeclaration(document.paths));
104
+ const isIncluded = (operation) => pathItem.isIncludedOperation(operation, context);
105
+ declarations.push(pathsEnum.apiPathsEnumDeclaration(document.paths, isIncluded));
104
106
  }
105
107
  return declarations;
106
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"document.cjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { appendAll } from \"../../../domain/append-all.js\";\nimport { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nexport const ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nexport const OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n appendAll(declarations, rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n declarations.push(apiPathsEnumDeclaration(document.paths));\n }\n return declarations;\n}\n"],"names":["irRecord","irKeyword","keptDeprecatedComponents","pathMembers","irOb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EAAI;AACjB,IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,QAAQ,CAAA;AAAA,EAC5D;AACA,EAAAC,mBAAA,CAAU,YAAA,EAAc,iBAAA,CAAkB,QAAA,EAAU,OAAA,EAAS,MAAM,CAAC,CAAA;AACpE,EAAA,OAAO,YAAA;AACT;AAMO,SAAS,eAAA,CACd,QAAA,EACA,OAAA,EACA,aAAA,EACiB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,YAAA,CAAa,IAAA,CAAK,UAAA,CAAW,eAAe,CAAC,CAAA;AAAA,EAC/C;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,aAAA,IAAiB,QAAA,CAAS,KAAA,EAAO;AACnD,IAAA,YAAA,CAAa,IAAA,CAAKC,iCAAA,CAAwB,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EAC3D;AACA,EAAA,OAAO,YAAA;AACT;;;;;"}
1
+ {"version":3,"file":"document.cjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { appendAll } from \"../../../domain/append-all.js\";\nimport { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { OperationEntry, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { isIncludedOperation } from \"./path-item.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nexport const ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nexport const OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n appendAll(declarations, rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n const isIncluded = (operation: OperationEntry) => isIncludedOperation(operation, context);\n declarations.push(apiPathsEnumDeclaration(document.paths, isIncluded));\n }\n return declarations;\n}\n"],"names":["irRecord","irKeyword","keptDeprecatedComponents","pathMembers","irObject","pathsObjectType","webhooksType","componentsType","defsRootType","declaredTypeLookup","READ_WRITE_MARKER_TYPES","appendAll","isIncludedOperation","apiPathsEnumDeclaration"],"mappings":";;;;;;;;;;;;;;AAwBO,MAAM,SAAA,GAAY,OAAO,MAAA,CAAO,CAAC,SAAS,UAAA,EAAY,YAAA,EAAc,OAAO,CAAU;AAGrF,MAAM,eAAA,GAAkB;AAE/B,MAAM,kBAAkBA,qBAAA,CAASC,sBAAA,CAAU,QAAQ,CAAA,EAAGA,sBAAA,CAAU,OAAO,CAAC,CAAA;AAoBxE,SAAS,cAAA,CAAe,UAA0B,OAAA,EAAgD;AAChG,EAAA,OAAO,OAAA,CAAQ,QAAQ,iBAAA,GACnBC,yCAAA,CAAyB,UAAU,OAAA,CAAQ,IAAI,CAAA,mBAC/C,IAAI,GAAA,EAAI;AACd;AAEA,MAAM,eAAA,GAA4D;AAAA,EAChE,KAAA,EAAO,CAAC,IAAA,EAAM,OAAA,KAAY;AACxB,IAAA,MAAM,OAAA,GAAUC,iBAAA,CAAY,IAAA,EAAqB,OAAO,CAAA;AACxD,IAAA,OAAO;AAAA,MACL,IAAA,EAAMC,sBAAS,OAAA,CAAQ,GAAA,CAAI,CAAC,EAAE,MAAA,EAAO,KAAM,MAAM,CAAC,CAAA;AAAA,MAClD,SAAS,EAAC;AAAA,MACV,iBAAA,EAAmB,CAAC,MAAA,KAAWC,qBAAA,CAAgB,SAAS,MAAM;AAAA,KAChE;AAAA,EACF,CAAA;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AA,GAAyC,SAAA,EACxB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,OAAA,CAAQ,QAAQ,gBAAA,EAAkB;AACpC,IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAMC,qCAAyB,CAAA;AAAA,EAC7E;AACA,EAAA,MAAM,MAAA,GAAS,uBAAA,CAAwB,OAAA,CAAQ,OAAA,CAAQ,UAAU,EAAE,CAAA;AACnE,EAAA,IAAI,WAAW,EAAA,EAAI;AACjB,IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,QAAQ,CAAA;AAAA,EAC5D;AACA,EAAAC,mBAAA,CAAU,YAAA,EAAc,iBAAA,CAAkB,QAAA,EAAU,OAAA,EAAS,MAAM,CAAC,CAAA;AACpE,EAAA,OAAO,YAAA;AACT;AAMO,SAAS,eAAA,CACd,QAAA,EACA,OAAA,EACA,aAAA,EACiB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,YAAA,CAAa,IAAA,CAAK,UAAA,CAAW,eAAe,CAAC,CAAA;AAAA,EAC/C;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,aAAA,IAAiB,QAAA,CAAS,KAAA,EAAO;AACnD,IAAA,MAAM,UAAA,GAAa,CAAC,SAAA,KAA8BC,4BAAA,CAAoB,WAAW,OAAO,CAAA;AACxF,IAAA,YAAA,CAAa,IAAA,CAAKC,iCAAA,CAAwB,QAAA,CAAS,KAAA,EAAO,UAAU,CAAC,CAAA;AAAA,EACvE;AACA,EAAA,OAAO,YAAA;AACT;;;;;"}
@@ -5,6 +5,7 @@ import { componentsType } from './components.mjs';
5
5
  import { declaredTypeLookup } from './declared-types.mjs';
6
6
  import { defsRootType } from './defs-root.mjs';
7
7
  import { keptDeprecatedComponents } from './kept-deprecated.mjs';
8
+ import { isIncludedOperation } from './path-item.mjs';
8
9
  import { pathMembers, pathsObjectType } from './paths.mjs';
9
10
  import { apiPathsEnumDeclaration } from './paths-enum.mjs';
10
11
  import { webhooksType } from './webhooks.mjs';
@@ -98,7 +99,8 @@ function documentClosing(document, context, hasOperations) {
98
99
  declarations.push(emptyAlias(OPERATIONS_NAME));
99
100
  }
100
101
  if (context.options.makePathsEnum && document.paths) {
101
- declarations.push(apiPathsEnumDeclaration(document.paths));
102
+ const isIncluded = (operation) => isIncludedOperation(operation, context);
103
+ declarations.push(apiPathsEnumDeclaration(document.paths, isIncluded));
102
104
  }
103
105
  return declarations;
104
106
  }
@@ -1 +1 @@
1
- {"version":3,"file":"document.mjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { appendAll } from \"../../../domain/append-all.js\";\nimport { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nexport const ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nexport const OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n appendAll(declarations, rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n declarations.push(apiPathsEnumDeclaration(document.paths));\n }\n return declarations;\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAuBO,MAAM,SAAA,GAAY,OAAO,MAAA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AA,EAAS,MAAM,CAAC,CAAA;AACpE,EAAA,OAAO,YAAA;AACT;AAMO,SAAS,eAAA,CACd,QAAA,EACA,OAAA,EACA,aAAA,EACiB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,YAAA,CAAa,IAAA,CAAK,UAAA,CAAW,eAAe,CAAC,CAAA;AAAA,EAC/C;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,aAAA,IAAiB,QAAA,CAAS,KAAA,EAAO;AACnD,IAAA,YAAA,CAAa,IAAA,CAAK,uBAAA,CAAwB,QAAA,CAAS,KAAK,CAAC,CAAA;AAAA,EAC3D;AACA,EAAA,OAAO,YAAA;AACT;;"}
1
+ {"version":3,"file":"document.mjs","sources":["../../../../src/application/transform/document/document.ts"],"sourcesContent":["import { appendAll } from \"../../../domain/append-all.js\";\nimport { irKeyword, irObject, irRecord } from \"../../../domain/ir/constructors.js\";\nimport type {\n IrDeclaration,\n IrIntersectionType,\n IrObjectType,\n IrType,\n IrTypeAliasDeclaration,\n} from \"../../../domain/ir/nodes.js\";\nimport type { ComponentsObject } from \"../../../domain/openapi/components-object.js\";\nimport type { DocumentObject } from \"../../../domain/openapi/document-object.js\";\nimport type { OperationEntry, PathsObject } from \"../../../domain/openapi/path-item-object.js\";\nimport { READ_WRITE_MARKER_TYPES } from \"../helper-types.js\";\nimport type { TransformContext, TransformOptions } from \"../transform-context.js\";\nimport { componentsType } from \"./components.js\";\nimport { type DeclaredTypeLookup, declaredTypeLookup } from \"./declared-types.js\";\nimport { defsRootType } from \"./defs-root.js\";\nimport { keptDeprecatedComponents } from \"./kept-deprecated.js\";\nimport { isIncludedOperation } from \"./path-item.js\";\nimport { pathMembers, pathsObjectType } from \"./paths.js\";\nimport { apiPathsEnumDeclaration } from \"./paths-enum.js\";\nimport { webhooksType } from \"./webhooks.js\";\n\n/** The root types, in output order. */\nexport const ROOT_KEYS = Object.freeze([\"paths\", \"webhooks\", \"components\", \"$defs\"] as const);\ntype RootKey = (typeof ROOT_KEYS)[number];\n\nexport const OPERATIONS_NAME = \"operations\";\n/** The type of a root without members: `Record<string, never>`. */\nconst EMPTY_ROOT_TYPE = irRecord(irKeyword(\"string\"), irKeyword(\"never\"));\n\n/** A root's type and the declarations that follow it (the `--root-types` aliases). */\ninterface RootResult {\n readonly type: IrType;\n readonly aliases: readonly IrTypeAliasDeclaration[];\n /**\n * The root's final type, for a root that reads the types the whole file declares (`paths`, whose\n * overlap check follows references). `type` then only tells whether the root has members.\n */\n readonly withDeclaredTypes?: (lookup: DeclaredTypeLookup) => IrType;\n}\n\ntype RootTransform = (\n node: object,\n context: TransformContext,\n document: DocumentObject,\n) => RootResult;\n\n/** Without `--exclude-deprecated` nothing is left out, so the scan is skipped. */\nfunction keptDeprecated(document: DocumentObject, context: TransformContext): ReadonlySet<object> {\n return context.options.excludeDeprecated\n ? keptDeprecatedComponents(document, context.refs)\n : new Set();\n}\n\nconst ROOT_TRANSFORMS: Readonly<Record<RootKey, RootTransform>> = {\n paths: (node, context) => {\n const members = pathMembers(node as PathsObject, context);\n return {\n type: irObject(members.map(({ member }) => member)),\n aliases: [],\n withDeclaredTypes: (lookup) => pathsObjectType(members, lookup),\n };\n },\n webhooks: (node, context) => ({ type: webhooksType(node as PathsObject, context), aliases: [] }),\n components: (node, context, document) => {\n const kept = keptDeprecated(document, context);\n const { type, rootTypes } = componentsType(node as ComponentsObject, context, kept);\n return { type, aliases: rootTypes };\n },\n $defs: (node, context) => ({\n type: defsRootType(node as NonNullable<DocumentObject[\"$defs\"]>, context),\n aliases: [],\n }),\n};\n\nfunction emptyAlias(name: string): IrTypeAliasDeclaration {\n return { kind: \"typeAlias\", name, isExported: true, type: EMPTY_ROOT_TYPE, comments: [] };\n}\n\n/** A root type that declares something: an object with members, or an intersection of them. */\ntype RootBodyType = IrObjectType | IrIntersectionType;\n\nfunction isRootBody(type: IrType): type is RootBodyType {\n return (type.kind === \"object\" && type.members.length > 0) || type.kind === \"intersection\";\n}\n\n/**\n * A root with members: an interface, or a type alias with `--export-type`. An intersection (the\n * `paths` of overlapping `--path-params-as-types` keys) can only be a type alias.\n */\nfunction rootDeclaration(\n name: RootKey,\n type: RootBodyType,\n options: TransformOptions,\n): IrDeclaration {\n return options.exportType || type.kind === \"intersection\"\n ? { kind: \"typeAlias\", name, isExported: true, type, comments: [] }\n : { kind: \"interface\", name, isExported: true, members: type.members, comments: [] };\n}\n\n/**\n * The declarations of one root: its type, then its aliases. `finish` gives the root's declaration\n * again from the types the whole file declares, for a root with `withDeclaredTypes`.\n */\ninterface RootDeclarations {\n readonly declarations: readonly IrDeclaration[];\n readonly finish?: (lookup: DeclaredTypeLookup) => IrDeclaration;\n}\n\n/**\n * The declarations of one root. A root that is missing, or whose type has no members, is\n * `Record<string, never>`. Only an object type (or the `paths` intersection) counts as having\n * members: a callback type the IR keeps as raw text does not (ADR-004).\n */\nfunction rootDeclarations(\n root: RootKey,\n document: DocumentObject,\n context: TransformContext,\n): RootDeclarations {\n const node: unknown = document[root];\n if (!node || typeof node !== \"object\") {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root)] };\n }\n const startedAt = context.diagnostics.now();\n const { type, aliases, withDeclaredTypes } = ROOT_TRANSFORMS[root](node, context, document);\n if (!isRootBody(type)) {\n context.diagnostics.debug(`${root} done (skipped)`, 0);\n return { declarations: [emptyAlias(root), ...aliases] };\n }\n const declaration = rootDeclaration(root, type, context.options);\n context.diagnostics.debug(`${root} done`, context.diagnostics.now() - startedAt);\n const finish =\n withDeclaredTypes &&\n ((lookup: DeclaredTypeLookup) => {\n const finished = withDeclaredTypes(lookup);\n return isRootBody(finished) ? rootDeclaration(root, finished, context.options) : declaration;\n });\n return { declarations: [declaration, ...aliases], ...(finish ? { finish } : {}) };\n}\n\n/**\n * Every root's declarations in output order. A root with `finish` gets its declaration from the\n * types of the other roots and of the footer (the `operations` interface), which exist only once\n * every root is transformed.\n */\nfunction rootsDeclarations(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[],\n): IrDeclaration[] {\n const roots = ROOT_KEYS.map((root) => rootDeclarations(root, document, context));\n const transformed = roots.flatMap(({ declarations }) => declarations);\n if (roots.every(({ finish }) => finish === undefined)) {\n return transformed;\n }\n const lookup = declaredTypeLookup([...transformed, ...footer()]);\n return roots.flatMap(({ declarations, finish }) => {\n const [declaration, ...aliases] = declarations;\n return finish === undefined || declaration === undefined\n ? declarations\n : [finish(lookup), ...aliases];\n });\n}\n\n/**\n * The `inject` text as written (ADR-010, decision 4), without the blank lines around it. The\n * original reprinted it with the TypeScript printer; text without code printed nothing then.\n */\nfunction withoutBlankLinesAround(text: string): string {\n return text.replace(/^(?:[ \\t]*\\r?\\n)+/, \"\").trimEnd();\n}\n\n/** No footer declarations: the roots' references to `operations` stay unresolved. */\nconst NO_FOOTER = (): readonly IrDeclaration[] => [];\n\n/**\n * The document's declarations before the footer: helper types, injected code, then one root type\n * per root key with the aliases that follow it. `footer` reads the footer's declarations once the\n * roots are transformed.\n */\nexport function documentBody(\n document: DocumentObject,\n context: TransformContext,\n footer: () => readonly IrDeclaration[] = NO_FOOTER,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (context.options.readWriteMarkers) {\n declarations.push({ kind: \"rawDeclaration\", text: READ_WRITE_MARKER_TYPES });\n }\n const inject = withoutBlankLinesAround(context.options.inject ?? \"\");\n if (inject !== \"\") {\n declarations.push({ kind: \"rawDeclaration\", text: inject });\n }\n appendAll(declarations, rootsDeclarations(document, context, footer));\n return declarations;\n}\n\n/**\n * The declarations after the footer: an empty `operations` type when the footer has no\n * operations, and the `--make-paths-enum` enum.\n */\nexport function documentClosing(\n document: DocumentObject,\n context: TransformContext,\n hasOperations: boolean,\n): IrDeclaration[] {\n const declarations: IrDeclaration[] = [];\n if (!hasOperations) {\n declarations.push(emptyAlias(OPERATIONS_NAME));\n }\n if (context.options.makePathsEnum && document.paths) {\n const isIncluded = (operation: OperationEntry) => isIncludedOperation(operation, context);\n declarations.push(apiPathsEnumDeclaration(document.paths, isIncluded));\n }\n return declarations;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;AAwBO,MAAM,SAAA,GAAY,OAAO,MAAA,CAAO,CAAC,SAAS,UAAA,EAAY,YAAA,EAAc,OAAO,CAAU;AAGrF,MAAM,eAAA,GAAkB;AAE/B,MAAM,kBAAkB,QAAA,CAAS,SAAA,CAAU,QAAQ,CAAA,EAAG,SAAA,CAAU,OAAO,CAAC,CAAA;AAoBxE,SAAS,cAAA,CAAe,UAA0B,OAAA,EAAgD;AAChG,EAAA,OAAO,OAAA,CAAQ,QAAQ,iBAAA,GACnB,wBAAA,CAAyB,UAAU,OAAA,CAAQ,IAAI,CAAA,mBAC/C,IAAI,GAAA,EAAI;AACd;AAEA,MAAM,eAAA,GAA4D;AAAA,EAChE,KAAA,EAAO,CAAC,IAAA,EAAM,OAAA,KAAY;AACxB,IAAA,MAAM,OAAA,GAAU,WAAA,CAAY,IAAA,EAAqB,OAAO,CAAA;AACxD,IAAA,OAAO;AAAA,MACL,IAAA,EAAM,SAAS,OAAA,CAAQ,GAAA,CAAI,CAAC,EAAE,MAAA,EAAO,KAAM,MAAM,CAAC,CAAA;AAAA,MAClD,SAAS,EAAC;AAAA,MACV,iBAAA,EAAmB,CAAC,MAAA,KAAW,eAAA,CAAgB,SAAS,MAAM;AAAA,KAChE;AAAA,EACF,CAAA;AAAA,EACA,QAAA,EAAU,CAAC,IAAA,EAAM,OAAA,MAAa,EAAE,IAAA,EAAM,YAAA,CAAa,IAAA,EAAqB,OAAO,CAAA,EAAG,OAAA,EAAS,EAAC,EAAE,CAAA;AAAA,EAC9F,UAAA,EAAY,CAAC,IAAA,EAAM,OAAA,EAAS,QAAA,KAAa;AACvC,IAAA,MAAM,IAAA,GAAO,cAAA,CAAe,QAAA,EAAU,OAAO,CAAA;AAC7C,IAAA,MAAM,EAAE,IAAA,EAAM,SAAA,KAAc,cAAA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IAAA,YAAA,CAAa,KAAK,EAAE,IAAA,EAAM,gBAAA,EAAkB,IAAA,EAAM,QAAQ,CAAA;AAAA,EAC5D;AACA,EAAA,SAAA,CAAU,YAAA,EAAc,iBAAA,CAAkB,QAAA,EAAU,OAAA,EAAS,MAAM,CAAC,CAAA;AACpE,EAAA,OAAO,YAAA;AACT;AAMO,SAAS,eAAA,CACd,QAAA,EACA,OAAA,EACA,aAAA,EACiB;AACjB,EAAA,MAAM,eAAgC,EAAC;AACvC,EAAA,IAAI,CAAC,aAAA,EAAe;AAClB,IAAA,YAAA,CAAa,IAAA,CAAK,UAAA,CAAW,eAAe,CAAC,CAAA;AAAA,EAC/C;AACA,EAAA,IAAI,OAAA,CAAQ,OAAA,CAAQ,aAAA,IAAiB,QAAA,CAAS,KAAA,EAAO;AACnD,IAAA,MAAM,UAAA,GAAa,CAAC,SAAA,KAA8B,mBAAA,CAAoB,WAAW,OAAO,CAAA;AACxF,IAAA,YAAA,CAAa,IAAA,CAAK,uBAAA,CAAwB,QAAA,CAAS,KAAA,EAAO,UAAU,CAAC,CAAA;AAAA,EACvE;AACA,EAAA,OAAO,YAAA;AACT;;"}
@@ -0,0 +1,63 @@
1
+ 'use strict';
2
+
3
+ const schemaTransform = require('../schema/schema-transform.cjs');
4
+ const typeCombinators = require('../type-combinators.cjs');
5
+
6
+ function refOf(value) {
7
+ const ref = value?.$ref;
8
+ return typeof ref === "string" ? ref : void 0;
9
+ }
10
+ function declaredSchema(schema, ref, context) {
11
+ let declared = { schema, path: ref };
12
+ const seen = /* @__PURE__ */ new Set();
13
+ for (let next = refOf(schema); next !== void 0 && !seen.has(next); ) {
14
+ seen.add(next);
15
+ declared = { schema: context.refs.resolve(next), path: next };
16
+ next = refOf(declared.schema);
17
+ }
18
+ return declared;
19
+ }
20
+ function declaredObjectType(entry, context) {
21
+ const { original, resolved } = entry;
22
+ const schemaRef = refOf(resolved.schema);
23
+ if (schemaRef !== void 0) {
24
+ const { schema, path } = declaredSchema(resolved.schema, schemaRef, context);
25
+ return schemaTransform.transformSchema(schema, { path, schema }, context);
26
+ }
27
+ const parameterRef = refOf(original);
28
+ return parameterRef === void 0 ? null : schemaTransform.transformSchema(resolved.schema, { path: parameterRef, schema: resolved }, context);
29
+ }
30
+ function isIndexSignature(member) {
31
+ return member.kind === "indexSignature";
32
+ }
33
+ function hasIndexSignature(type) {
34
+ switch (type.kind) {
35
+ case "object":
36
+ return type.members.some(isIndexSignature);
37
+ case "union":
38
+ case "intersection":
39
+ return type.types.some(hasIndexSignature);
40
+ default:
41
+ return false;
42
+ }
43
+ }
44
+ function widenedMember(member, values) {
45
+ const isUnknown = member.type.kind === "keyword" && member.type.keyword === "unknown";
46
+ return isIndexSignature(member) && !isUnknown ? { ...member, type: typeCombinators.unionOf([member.type, ...values]) } : member;
47
+ }
48
+ function withIndexValues(type, values) {
49
+ switch (type.kind) {
50
+ case "object":
51
+ return { ...type, members: type.members.map((member) => widenedMember(member, values)) };
52
+ case "union":
53
+ case "intersection":
54
+ return { ...type, types: type.types.map((member) => withIndexValues(member, values)) };
55
+ default:
56
+ return type;
57
+ }
58
+ }
59
+
60
+ exports.declaredObjectType = declaredObjectType;
61
+ exports.hasIndexSignature = hasIndexSignature;
62
+ exports.withIndexValues = withIndexValues;
63
+ //# sourceMappingURL=exploded-query-values.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exploded-query-values.cjs","sources":["../../../../src/application/transform/document/exploded-query-values.ts"],"sourcesContent":["import type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { ResolvedEntry } from \"./parameter-entries.js\";\n\n/**\n * `exploded-query-objects` and index signatures. The keys of an exploded object are keys of\n * `query`, next to the other parameters. TypeScript checks an index signature against every key\n * of a value, so `{ page?: number } & { [key: string]: string }` admits no `page`, and no value\n * with another parameter at all. An index signature of an exploded object therefore also takes\n * the value types of the other keys of `query`: those keys carry their own values.\n */\n\nfunction refOf(value: unknown): string | undefined {\n const ref = (value as { $ref?: unknown } | undefined)?.$ref;\n return typeof ref === \"string\" ? ref : undefined;\n}\n\n/** A schema `$ref` chain followed to its end, with the pointer where that schema is declared. */\nfunction declaredSchema(schema: Schema | undefined, ref: string, context: TransformContext) {\n let declared = { schema, path: ref };\n const seen = new Set<string>();\n for (let next = refOf(schema); next !== undefined && !seen.has(next); ) {\n seen.add(next);\n declared = { schema: context.refs.resolve(next) as Schema | undefined, path: next };\n next = refOf(declared.schema);\n }\n return declared;\n}\n\n/**\n * The type of an exploded parameter whose own type is a reference (its `$ref`, or the `$ref` of\n * its schema), written out where its schema is declared: the index signature of a referenced type\n * cannot be changed. The location is the one `components` types it at, so the enums it declares\n * are the ones the reference names. Null when no `$ref` is involved.\n */\nexport function declaredObjectType(entry: ResolvedEntry, context: TransformContext): IrType | null {\n const { original, resolved } = entry;\n const schemaRef = refOf(resolved.schema);\n if (schemaRef !== undefined) {\n const { schema, path } = declaredSchema(resolved.schema, schemaRef, context);\n return transformSchema(schema, { path, schema }, context);\n }\n const parameterRef = refOf(original);\n return parameterRef === undefined\n ? null\n : transformSchema(resolved.schema, { path: parameterRef, schema: resolved }, context);\n}\n\nfunction isIndexSignature(member: IrMember): boolean {\n return member.kind === \"indexSignature\";\n}\n\n/** Whether the type has an index signature in its objects, through unions and intersections. */\nexport function hasIndexSignature(type: IrType): boolean {\n switch (type.kind) {\n case \"object\":\n return type.members.some(isIndexSignature);\n case \"union\":\n case \"intersection\":\n return type.types.some(hasIndexSignature);\n default:\n return false;\n }\n}\n\nfunction widenedMember(member: IrMember, values: readonly IrType[]): IrMember {\n // `unknown` takes every value already.\n const isUnknown = member.type.kind === \"keyword\" && member.type.keyword === \"unknown\";\n return isIndexSignature(member) && !isUnknown\n ? { ...member, type: unionOf([member.type, ...values]) }\n : member;\n}\n\n/** The type with the values added to each index signature of its objects. */\nexport function withIndexValues(type: IrType, values: readonly IrType[]): IrType {\n switch (type.kind) {\n case \"object\":\n return { ...type, members: type.members.map((member) => widenedMember(member, values)) };\n case \"union\":\n case \"intersection\":\n return { ...type, types: type.types.map((member) => withIndexValues(member, values)) };\n default:\n return type;\n }\n}\n"],"names":["transformSchema","unionOf"],"mappings":";;;;;AAeA,SAAS,MAAM,KAAA,EAAoC;AACjD,EAAA,MAAM,MAAO,KAAA,EAA0C,IAAA;AACvD,EAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,GAAW,GAAA,GAAM,MAAA;AACzC;AAGA,SAAS,cAAA,CAAe,MAAA,EAA4B,GAAA,EAAa,OAAA,EAA2B;AAC1F,EAAA,IAAI,QAAA,GAAW,EAAE,MAAA,EAAQ,IAAA,EAAM,GAAA,EAAI;AACnC,EAAA,MAAM,IAAA,uBAAW,GAAA,EAAY;AAC7B,EAAA,KAAA,IAAS,IAAA,GAAO,KAAA,CAAM,MAAM,CAAA,EAAG,IAAA,KAAS,UAAa,CAAC,IAAA,CAAK,GAAA,CAAI,IAAI,CAAA,IAAK;AACtE,IAAA,IAAA,CAAK,IAAI,IAAI,CAAA;AACb,IAAA,QAAA,GAAW,EAAE,QAAQ,OAAA,CAAQ,IAAA,CAAK,QAAQ,IAAI,CAAA,EAAyB,MAAM,IAAA,EAAK;AAClF,IAAA,IAAA,GAAO,KAAA,CAAM,SAAS,MAAM,CAAA;AAAA,EAC9B;AACA,EAAA,OAAO,QAAA;AACT;AAQO,SAAS,kBAAA,CAAmB,OAAsB,OAAA,EAA0C;AACjG,EAAA,MAAM,EAAE,QAAA,EAAU,QAAA,EAAS,GAAI,KAAA;AAC/B,EAAA,MAAM,SAAA,GAAY,KAAA,CAAM,QAAA,CAAS,MAAM,CAAA;AACvC,EAAA,IAAI,cAAc,MAAA,EAAW;AAC3B,IAAA,MAAM,EAAE,QAAQ,IAAA,EAAK,GAAI,eAAe,QAAA,CAAS,MAAA,EAAQ,WAAW,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CAAK,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW,aAAA,CAAc,MAAA,EAAQ,MAAM,CAAC,CAAA,EAAE;AAAA,IACzF,KAAK,OAAA;AAAA,IACL,KAAK,cAAA;AACH,MAAA,OAAO,EAAE,GAAG,IAAA,EAAM,KAAA,EAAO,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,CAAC,MAAA,KAAW,eAAA,CAAgB,MAAA,EAAQ,MAAM,CAAC,CAAA,EAAE;AAAA,IACvF;AACE,MAAA,OAAO,IAAA;AAAA;AAEb;;;;"}
@@ -0,0 +1,59 @@
1
+ import { transformSchema } from '../schema/schema-transform.mjs';
2
+ import { unionOf } from '../type-combinators.mjs';
3
+
4
+ function refOf(value) {
5
+ const ref = value?.$ref;
6
+ return typeof ref === "string" ? ref : void 0;
7
+ }
8
+ function declaredSchema(schema, ref, context) {
9
+ let declared = { schema, path: ref };
10
+ const seen = /* @__PURE__ */ new Set();
11
+ for (let next = refOf(schema); next !== void 0 && !seen.has(next); ) {
12
+ seen.add(next);
13
+ declared = { schema: context.refs.resolve(next), path: next };
14
+ next = refOf(declared.schema);
15
+ }
16
+ return declared;
17
+ }
18
+ function declaredObjectType(entry, context) {
19
+ const { original, resolved } = entry;
20
+ const schemaRef = refOf(resolved.schema);
21
+ if (schemaRef !== void 0) {
22
+ const { schema, path } = declaredSchema(resolved.schema, schemaRef, context);
23
+ return transformSchema(schema, { path, schema }, context);
24
+ }
25
+ const parameterRef = refOf(original);
26
+ return parameterRef === void 0 ? null : transformSchema(resolved.schema, { path: parameterRef, schema: resolved }, context);
27
+ }
28
+ function isIndexSignature(member) {
29
+ return member.kind === "indexSignature";
30
+ }
31
+ function hasIndexSignature(type) {
32
+ switch (type.kind) {
33
+ case "object":
34
+ return type.members.some(isIndexSignature);
35
+ case "union":
36
+ case "intersection":
37
+ return type.types.some(hasIndexSignature);
38
+ default:
39
+ return false;
40
+ }
41
+ }
42
+ function widenedMember(member, values) {
43
+ const isUnknown = member.type.kind === "keyword" && member.type.keyword === "unknown";
44
+ return isIndexSignature(member) && !isUnknown ? { ...member, type: unionOf([member.type, ...values]) } : member;
45
+ }
46
+ function withIndexValues(type, values) {
47
+ switch (type.kind) {
48
+ case "object":
49
+ return { ...type, members: type.members.map((member) => widenedMember(member, values)) };
50
+ case "union":
51
+ case "intersection":
52
+ return { ...type, types: type.types.map((member) => withIndexValues(member, values)) };
53
+ default:
54
+ return type;
55
+ }
56
+ }
57
+
58
+ export { declaredObjectType, hasIndexSignature, withIndexValues };
59
+ //# sourceMappingURL=exploded-query-values.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exploded-query-values.mjs","sources":["../../../../src/application/transform/document/exploded-query-values.ts"],"sourcesContent":["import type { IrMember, IrType } from \"../../../domain/ir/nodes.js\";\nimport type { Schema } from \"../../../domain/openapi/schema-object.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport type { TransformContext } from \"../transform-context.js\";\nimport { unionOf } from \"../type-combinators.js\";\nimport type { ResolvedEntry } from \"./parameter-entries.js\";\n\n/**\n * `exploded-query-objects` and index signatures. The keys of an exploded object are keys of\n * `query`, next to the other parameters. TypeScript checks an index signature against every key\n * of a value, so `{ page?: number } & { [key: string]: string }` admits no `page`, and no value\n * with another parameter at all. An index signature of an exploded object therefore also takes\n * the value types of the other keys of `query`: those keys carry their own values.\n */\n\nfunction refOf(value: unknown): string | undefined {\n const ref = (value as { $ref?: unknown } | undefined)?.$ref;\n return typeof ref === \"string\" ? ref : undefined;\n}\n\n/** A schema `$ref` chain followed to its end, with the pointer where that schema is declared. */\nfunction declaredSchema(schema: Schema | undefined, ref: string, context: TransformContext) {\n let declared = { schema, path: ref };\n const seen = new Set<string>();\n for (let next = refOf(schema); next !== undefined && !seen.has(next); ) {\n seen.add(next);\n declared = { schema: context.refs.resolve(next) as Schema | undefined, path: next };\n next = refOf(declared.schema);\n }\n return declared;\n}\n\n/**\n * The type of an exploded parameter whose own type is a reference (its `$ref`, or the `$ref` of\n * its schema), written out where its schema is declared: the index signature of a referenced type\n * cannot be changed. The location is the one `components` types it at, so the enums it declares\n * are the ones the reference names. Null when no `$ref` is involved.\n */\nexport function declaredObjectType(entry: ResolvedEntry, context: TransformContext): IrType | null {\n const { original, resolved } = entry;\n const schemaRef = refOf(resolved.schema);\n if (schemaRef !== undefined) {\n const { schema, path } = declaredSchema(resolved.schema, schemaRef, context);\n return transformSchema(schema, { path, schema }, context);\n }\n const parameterRef = refOf(original);\n return parameterRef === undefined\n ? null\n : transformSchema(resolved.schema, { path: parameterRef, schema: resolved }, context);\n}\n\nfunction isIndexSignature(member: IrMember): boolean {\n return member.kind === \"indexSignature\";\n}\n\n/** Whether the type has an index signature in its objects, through unions and intersections. */\nexport function hasIndexSignature(type: IrType): boolean {\n switch (type.kind) {\n case \"object\":\n return type.members.some(isIndexSignature);\n case \"union\":\n case \"intersection\":\n return type.types.some(hasIndexSignature);\n default:\n return false;\n }\n}\n\nfunction widenedMember(member: IrMember, values: readonly IrType[]): IrMember {\n // `unknown` takes every value already.\n const isUnknown = member.type.kind === \"keyword\" && member.type.keyword === \"unknown\";\n return isIndexSignature(member) && !isUnknown\n ? { ...member, type: unionOf([member.type, ...values]) }\n : member;\n}\n\n/** The type with the values added to each index signature of its objects. */\nexport function withIndexValues(type: IrType, values: readonly IrType[]): IrType {\n switch (type.kind) {\n case \"object\":\n return { ...type, members: type.members.map((member) => widenedMember(member, values)) };\n case \"union\":\n case \"intersection\":\n return { ...type, types: type.types.map((member) => withIndexValues(member, values)) };\n default:\n return type;\n }\n}\n"],"names":[],"mappings":";;;AAeA,SAAS,MAAM,KAAA,EAAoC;AACjD,EAAA,MAAM,MAAO,KAAA,EAA0C,IAAA;AACvD,EAAA,OAAO,OAAO,GAAA,KAAQ,QAAA,GAAW,GAAA,GAAM,MAAA;AACzC;AAGA,SAAS,cAAA,CAAe,MAAA,EAA4B,GAAA,EAAa,OAAA,EAA2B;AAC1F,EAAA,IAAI,QAAA,GAAW,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IAAA;AAAM,IACjB,KAAK,QAAA;AACH,MAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,IAAA,CAAK,gBAAgB,CAAA;AAAA,IAC3C,KAAK,OAAA;AAAA,IACL,KAAK,cAAA;AACH,MAAA,OAAO,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,iBAAiB,CAAA;AAAA,IAC1C;AACE,MAAA,OAAO,KAAA;AAAA;AAEb;AAEA,SAAS,aAAA,CAAc,QAAkB,MAAA,EAAqC;AAE5E,EAAA,MAAM,YAAY,MAAA,CAAO,IAAA,CAAK,SAAS,SAAA,IAAa,MAAA,CAAO,KAAK,OAAA,KAAY,SAAA;AAC5E,EAAA,OAAO,iBAAiB,MAAM,CAAA,IAAK,CAAC,SAAA,GAChC,EAAE,GAAG,MAAA,EAAQ,IAAA,EAAM,OAAA,CAAQ,CAAC,MAAA,CAAO,IAAA,EAAM,GAAG,MAAM,CAAC,GAAE,GACrD,MAAA;AACN;AAGO,SAAS,eAAA,CAAgB,MAAc,MAAA,EAAmC;AAC/E,EAAA,QAAQ,KAAK,IAAA;AAAM,IACjB,KAAK,QAAA;AACH,MAAA,OAAO,EAAE,GAAG,IAAA,EAAM,OAAA,EAAS,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,CAAC,MAAA,KAAW,aAAA,CAAc,MAAA,EAAQ,MAAM,CAAC,CAAA,EAAE;AAAA,IACzF,KAAK,OAAA;AAAA,IACL,KAAK,cAAA;AACH,MAAA,OAAO,EAAE,GAAG,IAAA,EAAM,KAAA,EAAO,IAAA,CAAK,KAAA,CAAM,GAAA,CAAI,CAAC,MAAA,KAAW,eAAA,CAAgB,MAAA,EAAQ,MAAM,CAAC,CAAA,EAAE;AAAA,IACvF;AACE,MAAA,OAAO,IAAA;AAAA;AAEb;;"}
@@ -2,11 +2,12 @@
2
2
 
3
3
  const constructors = require('../../../domain/ir/constructors.cjs');
4
4
  const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
5
+ const outputFixes = require('../../../domain/output-fixes.cjs');
5
6
  const documentEntries = require('../document-entries.cjs');
6
7
  const schemaTransform = require('../schema/schema-transform.cjs');
7
8
  const sharedTypes = require('../shared-types.cjs');
8
9
  const documentMember = require('./document-member.cjs');
9
- const mediaType = require('./media-type.cjs');
10
+ const mediaType$1 = require('./media-type.cjs');
10
11
 
11
12
  function headerType(header, location, context) {
12
13
  if (header.schema) {
@@ -15,13 +16,20 @@ function headerType(header, location, context) {
15
16
  if (!header.content) {
16
17
  return sharedTypes.UNKNOWN_TYPE;
17
18
  }
19
+ if (context.options.fixes.has(outputFixes.FIX.PARAMETER_HEADER_CONTENT)) {
20
+ const first = Object.entries(header.content)[0];
21
+ return first === void 0 ? sharedTypes.UNKNOWN_TYPE : mediaType(...first, location, context);
22
+ }
18
23
  const members = documentEntries.documentEntries(header.content, context.options).map(([contentType, entry]) => {
19
- const path = `${location.path ?? "#"}/${jsonPointer.escapePointerSegment(contentType)}`;
20
- const type = mediaType.contentEntryType(entry, { ...location, path }, context);
24
+ const type = mediaType(contentType, entry, location, context);
21
25
  return documentMember.documentMember(contentType, type, entry, { isReadonly: context.options.immutable });
22
26
  });
23
27
  return constructors.irObject(members);
24
28
  }
29
+ function mediaType(contentType, entry, location, context) {
30
+ const path = `${location.path ?? "#"}/${jsonPointer.escapePointerSegment(contentType)}`;
31
+ return mediaType$1.contentEntryType(entry, { ...location, path }, context);
32
+ }
25
33
 
26
34
  exports.headerType = headerType;
27
35
  //# sourceMappingURL=header.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"header.cjs","sources":["../../../../src/application/transform/document/header.ts"],"sourcesContent":["import { irObject } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { HeaderObject } from \"../../../domain/openapi/header-object.js\";\nimport { escapePointerSegment } from \"../../../domain/openapi/json-pointer.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A header's type (OpenAPI 3.1 §4.8.21): its schema, else an object with one property per media\n * type in `content`, else `unknown`.\n */\nexport function headerType(\n header: HeaderObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (header.schema) {\n return transformSchema(header.schema, location, context);\n }\n if (!header.content) {\n return UNKNOWN_TYPE;\n }\n const members = documentEntries(header.content, context.options).map(([contentType, entry]) => {\n // Unlike other content maps, the original joins this path by hand: a missing path is `#`.\n const path = `${location.path ?? \"#\"}/${escapePointerSegment(contentType)}`;\n const type = contentEntryType(entry, { ...location, path }, context);\n return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n"],"names":["transformSchema","UNKNOWN_TYPE","documentEntries","escapePointerSegment","contentEntryType","documentMember","irObject"],"mappings":";;;;;;;;;;AAeO,SAAS,UAAA,CACd,MAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,OAAO,MAAA,EAAQ;AACjB,IAAA,OAAOA,+BAAA,CAAgB,MAAA,CAAO,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AAAA,EACzD;AACA,EAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,IAAA,OAAOC,wBAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAA,GAAUC,+BAAA,CAAgB,MAAA,CAAO,OAAA,EAAS,OAAA,CAAQ,OAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,WAAA,EAAa,KAAK,CAAA,KAAM;AAE7F,IAAA,MAAM,IAAA,GAAO,GAAG,QAAA,CAAS,IAAA,IAAQ,GAAG,CAAA,CAAA,EAAIC,gCAAA,CAAqB,WAAW,CAAC,CAAA,CAAA;AACzE,IAAA,MAAM,IAAA,GAAOC,2BAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AACnE,IAAA,OAAOC,6BAAA,CAAe,aAAa,IAAA,EAAM,KAAA,EAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EAC3F,CAAC,CAAA;AACD,EAAA,OAAOC,sBAAS,OAAO,CAAA;AACzB;;"}
1
+ {"version":3,"file":"header.cjs","sources":["../../../../src/application/transform/document/header.ts"],"sourcesContent":["import { irObject } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { HeaderObject } from \"../../../domain/openapi/header-object.js\";\nimport { escapePointerSegment } from \"../../../domain/openapi/json-pointer.js\";\nimport type { ContentMap } from \"../../../domain/openapi/media-type-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A header's type (OpenAPI 3.1 §4.8.21): its schema, else the type of its `content`, else\n * `unknown`. `content` holds one media type whose schema describes the value; the original typed\n * it as an object with one property per media type, which the `parameter-header-content` fix\n * replaces by the media type's type, as for a parameter.\n */\nexport function headerType(\n header: HeaderObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (header.schema) {\n return transformSchema(header.schema, location, context);\n }\n if (!header.content) {\n return UNKNOWN_TYPE;\n }\n if (context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT)) {\n // The first media type in document order, as for a parameter: `--alphabetize` sorts only\n // the members it writes.\n const first = Object.entries(header.content)[0];\n return first === undefined ? UNKNOWN_TYPE : mediaType(...first, location, context);\n }\n const members = documentEntries(header.content, context.options).map(([contentType, entry]) => {\n const type = mediaType(contentType, entry, location, context);\n return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n\n/** The type of one media type of a header, at the path the original gave it. */\nfunction mediaType(\n contentType: string,\n entry: ContentMap[string],\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n // Unlike other content maps, the original joins this path by hand: a missing path is `#`.\n const path = `${location.path ?? \"#\"}/${escapePointerSegment(contentType)}`;\n return contentEntryType(entry, { ...location, path }, context);\n}\n"],"names":["transformSchema","UNKNOWN_TYPE","FIX","documentEntries","documentMember","irObject","escapePointerSegment","contentEntryType"],"mappings":";;;;;;;;;;;AAmBO,SAAS,UAAA,CACd,MAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,OAAO,MAAA,EAAQ;AACjB,IAAA,OAAOA,+BAAA,CAAgB,MAAA,CAAO,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AAAA,EACzD;AACA,EAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,IAAA,OAAOC,wBAAA;AAAA,EACT;AACA,EAAA,IAAI,QAAQ,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAIC,eAAA,CAAI,wBAAwB,CAAA,EAAG;AAG3D,IAAA,MAAM,QAAQ,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,OAAO,EAAE,CAAC,CAAA;AAC9C,IAAA,OAAO,UAAU,MAAA,GAAYD,wBAAA,GAAe,UAAU,GAAG,KAAA,EAAO,UAAU,OAAO,CAAA;AAAA,EACnF;AACA,EAAA,MAAM,OAAA,GAAUE,+BAAA,CAAgB,MAAA,CAAO,OAAA,EAAS,OAAA,CAAQ,OAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,WAAA,EAAa,KAAK,CAAA,KAAM;AAC7F,IAAA,MAAM,IAAA,GAAO,SAAA,CAAU,WAAA,EAAa,KAAA,EAAO,UAAU,OAAO,CAAA;AAC5D,IAAA,OAAOC,6BAAA,CAAe,aAAa,IAAA,EAAM,KAAA,EAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EAC3F,CAAC,CAAA;AACD,EAAA,OAAOC,sBAAS,OAAO,CAAA;AACzB;AAGA,SAAS,SAAA,CACP,WAAA,EACA,KAAA,EACA,QAAA,EACA,OAAA,EACQ;AAER,EAAA,MAAM,IAAA,GAAO,GAAG,QAAA,CAAS,IAAA,IAAQ,GAAG,CAAA,CAAA,EAAIC,gCAAA,CAAqB,WAAW,CAAC,CAAA,CAAA;AACzE,EAAA,OAAOC,6BAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AAC/D;;"}
@@ -1,5 +1,6 @@
1
1
  import { irObject } from '../../../domain/ir/constructors.mjs';
2
2
  import { escapePointerSegment } from '../../../domain/openapi/json-pointer.mjs';
3
+ import { FIX } from '../../../domain/output-fixes.mjs';
3
4
  import { documentEntries } from '../document-entries.mjs';
4
5
  import { transformSchema } from '../schema/schema-transform.mjs';
5
6
  import { UNKNOWN_TYPE } from '../shared-types.mjs';
@@ -13,13 +14,20 @@ function headerType(header, location, context) {
13
14
  if (!header.content) {
14
15
  return UNKNOWN_TYPE;
15
16
  }
17
+ if (context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT)) {
18
+ const first = Object.entries(header.content)[0];
19
+ return first === void 0 ? UNKNOWN_TYPE : mediaType(...first, location, context);
20
+ }
16
21
  const members = documentEntries(header.content, context.options).map(([contentType, entry]) => {
17
- const path = `${location.path ?? "#"}/${escapePointerSegment(contentType)}`;
18
- const type = contentEntryType(entry, { ...location, path }, context);
22
+ const type = mediaType(contentType, entry, location, context);
19
23
  return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });
20
24
  });
21
25
  return irObject(members);
22
26
  }
27
+ function mediaType(contentType, entry, location, context) {
28
+ const path = `${location.path ?? "#"}/${escapePointerSegment(contentType)}`;
29
+ return contentEntryType(entry, { ...location, path }, context);
30
+ }
23
31
 
24
32
  export { headerType };
25
33
  //# sourceMappingURL=header.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"header.mjs","sources":["../../../../src/application/transform/document/header.ts"],"sourcesContent":["import { irObject } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { HeaderObject } from \"../../../domain/openapi/header-object.js\";\nimport { escapePointerSegment } from \"../../../domain/openapi/json-pointer.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A header's type (OpenAPI 3.1 §4.8.21): its schema, else an object with one property per media\n * type in `content`, else `unknown`.\n */\nexport function headerType(\n header: HeaderObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (header.schema) {\n return transformSchema(header.schema, location, context);\n }\n if (!header.content) {\n return UNKNOWN_TYPE;\n }\n const members = documentEntries(header.content, context.options).map(([contentType, entry]) => {\n // Unlike other content maps, the original joins this path by hand: a missing path is `#`.\n const path = `${location.path ?? \"#\"}/${escapePointerSegment(contentType)}`;\n const type = contentEntryType(entry, { ...location, path }, context);\n return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n"],"names":[],"mappings":";;;;;;;;AAeO,SAAS,UAAA,CACd,MAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,OAAO,MAAA,EAAQ;AACjB,IAAA,OAAO,eAAA,CAAgB,MAAA,CAAO,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AAAA,EACzD;AACA,EAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,IAAA,OAAO,YAAA;AAAA,EACT;AACA,EAAA,MAAM,OAAA,GAAU,eAAA,CAAgB,MAAA,CAAO,OAAA,EAAS,OAAA,CAAQ,OAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,WAAA,EAAa,KAAK,CAAA,KAAM;AAE7F,IAAA,MAAM,IAAA,GAAO,GAAG,QAAA,CAAS,IAAA,IAAQ,GAAG,CAAA,CAAA,EAAI,oBAAA,CAAqB,WAAW,CAAC,CAAA,CAAA;AACzE,IAAA,MAAM,IAAA,GAAO,iBAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AACnE,IAAA,OAAO,cAAA,CAAe,aAAa,IAAA,EAAM,KAAA,EAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EAC3F,CAAC,CAAA;AACD,EAAA,OAAO,SAAS,OAAO,CAAA;AACzB;;"}
1
+ {"version":3,"file":"header.mjs","sources":["../../../../src/application/transform/document/header.ts"],"sourcesContent":["import { irObject } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport type { HeaderObject } from \"../../../domain/openapi/header-object.js\";\nimport { escapePointerSegment } from \"../../../domain/openapi/json-pointer.js\";\nimport type { ContentMap } from \"../../../domain/openapi/media-type-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport { documentEntries } from \"../document-entries.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { UNKNOWN_TYPE } from \"../shared-types.js\";\nimport { documentMember } from \"./document-member.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A header's type (OpenAPI 3.1 §4.8.21): its schema, else the type of its `content`, else\n * `unknown`. `content` holds one media type whose schema describes the value; the original typed\n * it as an object with one property per media type, which the `parameter-header-content` fix\n * replaces by the media type's type, as for a parameter.\n */\nexport function headerType(\n header: HeaderObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (header.schema) {\n return transformSchema(header.schema, location, context);\n }\n if (!header.content) {\n return UNKNOWN_TYPE;\n }\n if (context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT)) {\n // The first media type in document order, as for a parameter: `--alphabetize` sorts only\n // the members it writes.\n const first = Object.entries(header.content)[0];\n return first === undefined ? UNKNOWN_TYPE : mediaType(...first, location, context);\n }\n const members = documentEntries(header.content, context.options).map(([contentType, entry]) => {\n const type = mediaType(contentType, entry, location, context);\n return documentMember(contentType, type, entry, { isReadonly: context.options.immutable });\n });\n return irObject(members);\n}\n\n/** The type of one media type of a header, at the path the original gave it. */\nfunction mediaType(\n contentType: string,\n entry: ContentMap[string],\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n // Unlike other content maps, the original joins this path by hand: a missing path is `#`.\n const path = `${location.path ?? \"#\"}/${escapePointerSegment(contentType)}`;\n return contentEntryType(entry, { ...location, path }, context);\n}\n"],"names":[],"mappings":";;;;;;;;;AAmBO,SAAS,UAAA,CACd,MAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,OAAO,MAAA,EAAQ;AACjB,IAAA,OAAO,eAAA,CAAgB,MAAA,CAAO,MAAA,EAAQ,QAAA,EAAU,OAAO,CAAA;AAAA,EACzD;AACA,EAAA,IAAI,CAAC,OAAO,OAAA,EAAS;AACnB,IAAA,OAAO,YAAA;AAAA,EACT;AACA,EAAA,IAAI,QAAQ,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAI,GAAA,CAAI,wBAAwB,CAAA,EAAG;AAG3D,IAAA,MAAM,QAAQ,MAAA,CAAO,OAAA,CAAQ,MAAA,CAAO,OAAO,EAAE,CAAC,CAAA;AAC9C,IAAA,OAAO,UAAU,MAAA,GAAY,YAAA,GAAe,UAAU,GAAG,KAAA,EAAO,UAAU,OAAO,CAAA;AAAA,EACnF;AACA,EAAA,MAAM,OAAA,GAAU,eAAA,CAAgB,MAAA,CAAO,OAAA,EAAS,OAAA,CAAQ,OAAO,CAAA,CAAE,GAAA,CAAI,CAAC,CAAC,WAAA,EAAa,KAAK,CAAA,KAAM;AAC7F,IAAA,MAAM,IAAA,GAAO,SAAA,CAAU,WAAA,EAAa,KAAA,EAAO,UAAU,OAAO,CAAA;AAC5D,IAAA,OAAO,cAAA,CAAe,aAAa,IAAA,EAAM,KAAA,EAAO,EAAE,UAAA,EAAY,OAAA,CAAQ,OAAA,CAAQ,SAAA,EAAW,CAAA;AAAA,EAC3F,CAAC,CAAA;AACD,EAAA,OAAO,SAAS,OAAO,CAAA;AACzB;AAGA,SAAS,SAAA,CACP,WAAA,EACA,KAAA,EACA,QAAA,EACA,OAAA,EACQ;AAER,EAAA,MAAM,IAAA,GAAO,GAAG,QAAA,CAAS,IAAA,IAAQ,GAAG,CAAA,CAAA,EAAI,oBAAA,CAAqB,WAAW,CAAC,CAAA,CAAA;AACzE,EAAA,OAAO,iBAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AAC/D;;"}
@@ -20,7 +20,7 @@ function isTypedByContent(parameter, context) {
20
20
  return true;
21
21
  }
22
22
  const hasContent = parameter.schema === void 0 && parameter.content !== void 0;
23
- return hasContent && context.options.fixes.has(outputFixes.FIX.PARAMETER_CONTENT);
23
+ return hasContent && context.options.fixes.has(outputFixes.FIX.PARAMETER_HEADER_CONTENT);
24
24
  }
25
25
  function parameterType(parameter, location, context) {
26
26
  if (isTypedByContent(parameter, context)) {
@@ -1 +1 @@
1
- {"version":3,"file":"parameter.cjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ParameterObject,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A parameter typed by the schema of its one `content` media type. An `in: querystring` parameter\n * (OpenAPI 3.2) is the whole query string (ADR-020); without a media type it is `string`, the\n * query string as text. With the `parameter-content` fix, any other parameter with `content`\n * (OpenAPI 3.0 and later, for a JSON value in a query parameter) is typed the same way.\n */\nfunction contentParameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];\n if (mediaType === undefined || entry === undefined) {\n return irKeyword(\"string\");\n }\n const path = appendPointer(location.path, [\"content\", mediaType]);\n return contentEntryType(entry, { ...location, path }, context);\n}\n\nfunction isTypedByContent(parameter: ParameterObject, context: SchemaContext): boolean {\n if (parameter.in === QUERYSTRING_LOCATION) {\n return true;\n }\n const hasContent = parameter.schema === undefined && parameter.content !== undefined;\n return hasContent && context.options.fixes.has(FIX.PARAMETER_CONTENT);\n}\n\n/**\n * A parameter's type (OpenAPI 3.2 §4.8.12). Without a schema it is `string`, not `unknown`:\n * query, path, header and cookie values all arrive as text. `content` is read for\n * `in: querystring`, and with the `parameter-content` fix for every parameter; without the fix\n * other parameters with `content` keep the original's `string`.\n */\nexport function parameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (isTypedByContent(parameter, context)) {\n return contentParameterType(parameter, location, context);\n }\n return parameter.schema\n ? transformSchema(parameter.schema, location, context)\n : irKeyword(\"string\");\n}\n"],"names":["mediaType","irKeyword","appendPointer","contentEntryType","QUERYSTRING_LOCATION","FIX","transformSchema"],"mappings":";;;;;;;;;AAkBA,SAAS,oBAAA,CACP,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,CAACA,WAAA,EAAW,KAAK,CAAA,GAAI,MAAA,CAAO,OAAA,CAAQ,SAAA,CAAU,OAAA,IAAW,EAAE,CAAA,CAAE,CAAC,KAAK,EAAC;AAC1E,EAAA,IAAIA,WAAA,KAAc,MAAA,IAAa,KAAA,KAAU,MAAA,EAAW;AAClD,IAAA,OAAOC,uBAAU,QAAQ,CAAA;AAAA,EAC3B;AACA,EAAA,MAAM,OAAOC,yBAAA,CAAc,QAAA,CAAS,MAAM,CAAC,SAAA,EAAWF,WAAS,CAAC,CAAA;AAChE,EAAA,OAAOG,2BAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AAC/D;AAEA,SAAS,gBAAA,CAAiB,WAA4B,OAAA,EAAiC;AACrF,EAAA,IAAI,SAAA,CAAU,OAAOC,oCAAA,EAAsB;AACzC,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAA,GAAa,SAAA,CAAU,MAAA,KAAW,MAAA,IAAa,UAAU,OAAA,KAAY,MAAA;AAC3E,EAAA,OAAO,cAAc,OAAA,CAAQ,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAIC,gBAAI,iBAAiB,CAAA;AACtE;AAQO,SAAS,aAAA,CACd,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,gBAAA,CAAiB,SAAA,EAAW,OAAO,CAAA,EAAG;AACxC,IAAA,OAAO,oBAAA,CAAqB,SAAA,EAAW,QAAA,EAAU,OAAO,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,SAAA,CAAU,SACbC,+BAAA,CAAgB,SAAA,CAAU,QAAQ,QAAA,EAAU,OAAO,CAAA,GACnDL,sBAAA,CAAU,QAAQ,CAAA;AACxB;;"}
1
+ {"version":3,"file":"parameter.cjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ParameterObject,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A parameter typed by the schema of its one `content` media type. An `in: querystring` parameter\n * (OpenAPI 3.2) is the whole query string (ADR-020); without a media type it is `string`, the\n * query string as text. With the `parameter-header-content` fix, any other parameter with `content`\n * (OpenAPI 3.0 and later, for a JSON value in a query parameter) is typed the same way.\n */\nfunction contentParameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];\n if (mediaType === undefined || entry === undefined) {\n return irKeyword(\"string\");\n }\n const path = appendPointer(location.path, [\"content\", mediaType]);\n return contentEntryType(entry, { ...location, path }, context);\n}\n\nfunction isTypedByContent(parameter: ParameterObject, context: SchemaContext): boolean {\n if (parameter.in === QUERYSTRING_LOCATION) {\n return true;\n }\n const hasContent = parameter.schema === undefined && parameter.content !== undefined;\n return hasContent && context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT);\n}\n\n/**\n * A parameter's type (OpenAPI 3.2 §4.8.12). Without a schema it is `string`, not `unknown`:\n * query, path, header and cookie values all arrive as text. `content` is read for\n * `in: querystring`, and with the `parameter-header-content` fix for every parameter; without\n * the fix other parameters with `content` keep the original's `string`.\n */\nexport function parameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (isTypedByContent(parameter, context)) {\n return contentParameterType(parameter, location, context);\n }\n return parameter.schema\n ? transformSchema(parameter.schema, location, context)\n : irKeyword(\"string\");\n}\n"],"names":["mediaType","irKeyword","appendPointer","contentEntryType","QUERYSTRING_LOCATION","FIX","transformSchema"],"mappings":";;;;;;;;;AAkBA,SAAS,oBAAA,CACP,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,CAACA,WAAA,EAAW,KAAK,CAAA,GAAI,MAAA,CAAO,OAAA,CAAQ,SAAA,CAAU,OAAA,IAAW,EAAE,CAAA,CAAE,CAAC,KAAK,EAAC;AAC1E,EAAA,IAAIA,WAAA,KAAc,MAAA,IAAa,KAAA,KAAU,MAAA,EAAW;AAClD,IAAA,OAAOC,uBAAU,QAAQ,CAAA;AAAA,EAC3B;AACA,EAAA,MAAM,OAAOC,yBAAA,CAAc,QAAA,CAAS,MAAM,CAAC,SAAA,EAAWF,WAAS,CAAC,CAAA;AAChE,EAAA,OAAOG,2BAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AAC/D;AAEA,SAAS,gBAAA,CAAiB,WAA4B,OAAA,EAAiC;AACrF,EAAA,IAAI,SAAA,CAAU,OAAOC,oCAAA,EAAsB;AACzC,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAA,GAAa,SAAA,CAAU,MAAA,KAAW,MAAA,IAAa,UAAU,OAAA,KAAY,MAAA;AAC3E,EAAA,OAAO,cAAc,OAAA,CAAQ,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAIC,gBAAI,wBAAwB,CAAA;AAC7E;AAQO,SAAS,aAAA,CACd,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,gBAAA,CAAiB,SAAA,EAAW,OAAO,CAAA,EAAG;AACxC,IAAA,OAAO,oBAAA,CAAqB,SAAA,EAAW,QAAA,EAAU,OAAO,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,SAAA,CAAU,SACbC,+BAAA,CAAgB,SAAA,CAAU,QAAQ,QAAA,EAAU,OAAO,CAAA,GACnDL,sBAAA,CAAU,QAAQ,CAAA;AACxB;;"}
@@ -18,7 +18,7 @@ function isTypedByContent(parameter, context) {
18
18
  return true;
19
19
  }
20
20
  const hasContent = parameter.schema === void 0 && parameter.content !== void 0;
21
- return hasContent && context.options.fixes.has(FIX.PARAMETER_CONTENT);
21
+ return hasContent && context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT);
22
22
  }
23
23
  function parameterType(parameter, location, context) {
24
24
  if (isTypedByContent(parameter, context)) {
@@ -1 +1 @@
1
- {"version":3,"file":"parameter.mjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ParameterObject,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A parameter typed by the schema of its one `content` media type. An `in: querystring` parameter\n * (OpenAPI 3.2) is the whole query string (ADR-020); without a media type it is `string`, the\n * query string as text. With the `parameter-content` fix, any other parameter with `content`\n * (OpenAPI 3.0 and later, for a JSON value in a query parameter) is typed the same way.\n */\nfunction contentParameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];\n if (mediaType === undefined || entry === undefined) {\n return irKeyword(\"string\");\n }\n const path = appendPointer(location.path, [\"content\", mediaType]);\n return contentEntryType(entry, { ...location, path }, context);\n}\n\nfunction isTypedByContent(parameter: ParameterObject, context: SchemaContext): boolean {\n if (parameter.in === QUERYSTRING_LOCATION) {\n return true;\n }\n const hasContent = parameter.schema === undefined && parameter.content !== undefined;\n return hasContent && context.options.fixes.has(FIX.PARAMETER_CONTENT);\n}\n\n/**\n * A parameter's type (OpenAPI 3.2 §4.8.12). Without a schema it is `string`, not `unknown`:\n * query, path, header and cookie values all arrive as text. `content` is read for\n * `in: querystring`, and with the `parameter-content` fix for every parameter; without the fix\n * other parameters with `content` keep the original's `string`.\n */\nexport function parameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (isTypedByContent(parameter, context)) {\n return contentParameterType(parameter, location, context);\n }\n return parameter.schema\n ? transformSchema(parameter.schema, location, context)\n : irKeyword(\"string\");\n}\n"],"names":[],"mappings":";;;;;;;AAkBA,SAAS,oBAAA,CACP,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,CAAC,SAAA,EAAW,KAAK,CAAA,GAAI,MAAA,CAAO,OAAA,CAAQ,SAAA,CAAU,OAAA,IAAW,EAAE,CAAA,CAAE,CAAC,KAAK,EAAC;AAC1E,EAAA,IAAI,SAAA,KAAc,MAAA,IAAa,KAAA,KAAU,MAAA,EAAW;AAClD,IAAA,OAAO,UAAU,QAAQ,CAAA;AAAA,EAC3B;AACA,EAAA,MAAM,OAAO,aAAA,CAAc,QAAA,CAAS,MAAM,CAAC,SAAA,EAAW,SAAS,CAAC,CAAA;AAChE,EAAA,OAAO,iBAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AAC/D;AAEA,SAAS,gBAAA,CAAiB,WAA4B,OAAA,EAAiC;AACrF,EAAA,IAAI,SAAA,CAAU,OAAO,oBAAA,EAAsB;AACzC,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAA,GAAa,SAAA,CAAU,MAAA,KAAW,MAAA,IAAa,UAAU,OAAA,KAAY,MAAA;AAC3E,EAAA,OAAO,cAAc,OAAA,CAAQ,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAI,IAAI,iBAAiB,CAAA;AACtE;AAQO,SAAS,aAAA,CACd,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,gBAAA,CAAiB,SAAA,EAAW,OAAO,CAAA,EAAG;AACxC,IAAA,OAAO,oBAAA,CAAqB,SAAA,EAAW,QAAA,EAAU,OAAO,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,SAAA,CAAU,SACb,eAAA,CAAgB,SAAA,CAAU,QAAQ,QAAA,EAAU,OAAO,CAAA,GACnD,SAAA,CAAU,QAAQ,CAAA;AACxB;;"}
1
+ {"version":3,"file":"parameter.mjs","sources":["../../../../src/application/transform/document/parameter.ts"],"sourcesContent":["import { irKeyword } from \"../../../domain/ir/constructors.js\";\nimport type { IrType } from \"../../../domain/ir/nodes.js\";\nimport { appendPointer } from \"../../../domain/openapi/json-pointer.js\";\nimport {\n type ParameterObject,\n QUERYSTRING_LOCATION,\n} from \"../../../domain/openapi/parameter-object.js\";\nimport { FIX } from \"../../../domain/output-fixes.js\";\nimport type { SchemaContext, SchemaLocation } from \"../schema/schema-context.js\";\nimport { transformSchema } from \"../schema/schema-transform.js\";\nimport { contentEntryType } from \"./media-type.js\";\n\n/**\n * A parameter typed by the schema of its one `content` media type. An `in: querystring` parameter\n * (OpenAPI 3.2) is the whole query string (ADR-020); without a media type it is `string`, the\n * query string as text. With the `parameter-header-content` fix, any other parameter with `content`\n * (OpenAPI 3.0 and later, for a JSON value in a query parameter) is typed the same way.\n */\nfunction contentParameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n const [mediaType, entry] = Object.entries(parameter.content ?? {})[0] ?? [];\n if (mediaType === undefined || entry === undefined) {\n return irKeyword(\"string\");\n }\n const path = appendPointer(location.path, [\"content\", mediaType]);\n return contentEntryType(entry, { ...location, path }, context);\n}\n\nfunction isTypedByContent(parameter: ParameterObject, context: SchemaContext): boolean {\n if (parameter.in === QUERYSTRING_LOCATION) {\n return true;\n }\n const hasContent = parameter.schema === undefined && parameter.content !== undefined;\n return hasContent && context.options.fixes.has(FIX.PARAMETER_HEADER_CONTENT);\n}\n\n/**\n * A parameter's type (OpenAPI 3.2 §4.8.12). Without a schema it is `string`, not `unknown`:\n * query, path, header and cookie values all arrive as text. `content` is read for\n * `in: querystring`, and with the `parameter-header-content` fix for every parameter; without\n * the fix other parameters with `content` keep the original's `string`.\n */\nexport function parameterType(\n parameter: ParameterObject,\n location: SchemaLocation,\n context: SchemaContext,\n): IrType {\n if (isTypedByContent(parameter, context)) {\n return contentParameterType(parameter, location, context);\n }\n return parameter.schema\n ? transformSchema(parameter.schema, location, context)\n : irKeyword(\"string\");\n}\n"],"names":[],"mappings":";;;;;;;AAkBA,SAAS,oBAAA,CACP,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,MAAM,CAAC,SAAA,EAAW,KAAK,CAAA,GAAI,MAAA,CAAO,OAAA,CAAQ,SAAA,CAAU,OAAA,IAAW,EAAE,CAAA,CAAE,CAAC,KAAK,EAAC;AAC1E,EAAA,IAAI,SAAA,KAAc,MAAA,IAAa,KAAA,KAAU,MAAA,EAAW;AAClD,IAAA,OAAO,UAAU,QAAQ,CAAA;AAAA,EAC3B;AACA,EAAA,MAAM,OAAO,aAAA,CAAc,QAAA,CAAS,MAAM,CAAC,SAAA,EAAW,SAAS,CAAC,CAAA;AAChE,EAAA,OAAO,iBAAiB,KAAA,EAAO,EAAE,GAAG,QAAA,EAAU,IAAA,IAAQ,OAAO,CAAA;AAC/D;AAEA,SAAS,gBAAA,CAAiB,WAA4B,OAAA,EAAiC;AACrF,EAAA,IAAI,SAAA,CAAU,OAAO,oBAAA,EAAsB;AACzC,IAAA,OAAO,IAAA;AAAA,EACT;AACA,EAAA,MAAM,UAAA,GAAa,SAAA,CAAU,MAAA,KAAW,MAAA,IAAa,UAAU,OAAA,KAAY,MAAA;AAC3E,EAAA,OAAO,cAAc,OAAA,CAAQ,OAAA,CAAQ,KAAA,CAAM,GAAA,CAAI,IAAI,wBAAwB,CAAA;AAC7E;AAQO,SAAS,aAAA,CACd,SAAA,EACA,QAAA,EACA,OAAA,EACQ;AACR,EAAA,IAAI,gBAAA,CAAiB,SAAA,EAAW,OAAO,CAAA,EAAG;AACxC,IAAA,OAAO,oBAAA,CAAqB,SAAA,EAAW,QAAA,EAAU,OAAO,CAAA;AAAA,EAC1D;AACA,EAAA,OAAO,SAAA,CAAU,SACb,eAAA,CAAgB,SAAA,CAAU,QAAQ,QAAA,EAAU,OAAO,CAAA,GACnD,SAAA,CAAU,QAAQ,CAAA;AACxB;;"}
@@ -5,8 +5,10 @@ const propertyName = require('../../../domain/ir/property-name.cjs');
5
5
  const jsonPointer = require('../../../domain/openapi/json-pointer.cjs');
6
6
  const parameterObject = require('../../../domain/openapi/parameter-object.cjs');
7
7
  const outputFixes = require('../../../domain/output-fixes.cjs');
8
+ const declaredValueTypes = require('../declared-value-types.cjs');
8
9
  const schemaComment = require('../schema-comment.cjs');
9
10
  const explodedQuery = require('./exploded-query.cjs');
11
+ const explodedQueryValues = require('./exploded-query-values.cjs');
10
12
  const parameter = require('./parameter.cjs');
11
13
  const parameterEntries = require('./parameter-entries.cjs');
12
14
  const referencedParameter = require('./referenced-parameter.cjs');
@@ -67,9 +69,25 @@ function querystringMember(entries, location, context) {
67
69
  function isExplodedEntry(entry, context) {
68
70
  return context.options.fixes.has(outputFixes.FIX.EXPLODED_QUERY_OBJECTS) && explodedQuery.isExplodedQueryObject(entry.resolved, context.refs);
69
71
  }
70
- function explodedPart(entry, location, context) {
71
- const type = entryType(entry, location, context);
72
- return entry.resolved.required ? type : constructors.irReference("Partial", [type]);
72
+ function explodedObjectType({ entry, type }, hasOtherKeys, context) {
73
+ if (!hasOtherKeys) {
74
+ return type;
75
+ }
76
+ const declared = explodedQueryValues.declaredObjectType(entry, context);
77
+ return declared !== null && explodedQueryValues.hasIndexSignature(declared) ? declared : type;
78
+ }
79
+ function explodedParts(exploded, members, context) {
80
+ const hasOtherKeys = members.length > 0 || exploded.length > 1;
81
+ const types = exploded.map((part) => explodedObjectType(part, hasOtherKeys, context));
82
+ const others = (index) => [
83
+ ...members.length > 0 ? [constructors.irObject(members)] : [],
84
+ ...types.filter((_type, other) => other !== index)
85
+ ];
86
+ return types.map((type, index) => {
87
+ const values = others(index).flatMap((other) => declaredValueTypes.declaredValueTypes(other, context.footer));
88
+ const widened = explodedQueryValues.withIndexValues(type, values);
89
+ return exploded[index]?.entry.resolved.required ? widened : constructors.irReference("Partial", [widened]);
90
+ });
73
91
  }
74
92
  function locationParts(entries, location, context) {
75
93
  const members = [];
@@ -77,7 +95,7 @@ function locationParts(entries, location, context) {
77
95
  let isOptional = true;
78
96
  for (const entry of entries) {
79
97
  if (isExplodedEntry(entry, context)) {
80
- exploded.push(explodedPart(entry, location, context));
98
+ exploded.push({ entry, type: entryType(entry, location, context) });
81
99
  isOptional &&= !entry.resolved.required;
82
100
  continue;
83
101
  }
@@ -85,7 +103,7 @@ function locationParts(entries, location, context) {
85
103
  members.push(member);
86
104
  isOptional &&= member.isOptional;
87
105
  }
88
- return { members, exploded, isOptional };
106
+ return { members, exploded: explodedParts(exploded, members, context), isOptional };
89
107
  }
90
108
  function locationType({ members, exploded }) {
91
109
  const types = [...members.length > 0 ? [constructors.irObject(members)] : [], ...exploded];