openapi-typesafe 1.0.0-rc.0 → 1.0.0-rc.2

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 (513) hide show
  1. package/README.md +12 -5
  2. package/dist/adapters/redocly-loader/configured-headers.cjs +32 -0
  3. package/dist/adapters/redocly-loader/configured-headers.cjs.map +1 -0
  4. package/dist/adapters/redocly-loader/configured-headers.mjs +30 -0
  5. package/dist/adapters/redocly-loader/configured-headers.mjs.map +1 -0
  6. package/dist/adapters/redocly-loader/redocly-config-source.cjs +21 -2
  7. package/dist/adapters/redocly-loader/redocly-config-source.cjs.map +1 -1
  8. package/dist/adapters/redocly-loader/redocly-config-source.mjs +22 -3
  9. package/dist/adapters/redocly-loader/redocly-config-source.mjs.map +1 -1
  10. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs +34 -11
  11. package/dist/adapters/redocly-loader/redocly-schema-loader.cjs.map +1 -1
  12. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs +33 -10
  13. package/dist/adapters/redocly-loader/redocly-schema-loader.mjs.map +1 -1
  14. package/dist/adapters/redocly-loader/ref-access.cjs +37 -4
  15. package/dist/adapters/redocly-loader/ref-access.cjs.map +1 -1
  16. package/dist/adapters/redocly-loader/ref-access.mjs +37 -4
  17. package/dist/adapters/redocly-loader/ref-access.mjs.map +1 -1
  18. package/dist/adapters/redocly-loader/ref-resolution-check.cjs +191 -0
  19. package/dist/adapters/redocly-loader/ref-resolution-check.cjs.map +1 -0
  20. package/dist/adapters/redocly-loader/ref-resolution-check.mjs +189 -0
  21. package/dist/adapters/redocly-loader/ref-resolution-check.mjs.map +1 -0
  22. package/dist/adapters/redocly-loader/ref-resolution-steps.cjs +73 -0
  23. package/dist/adapters/redocly-loader/ref-resolution-steps.cjs.map +1 -0
  24. package/dist/adapters/redocly-loader/ref-resolution-steps.mjs +60 -0
  25. package/dist/adapters/redocly-loader/ref-resolution-steps.mjs.map +1 -0
  26. package/dist/adapters/redocly-loader/remote-fetch.cjs +41 -14
  27. package/dist/adapters/redocly-loader/remote-fetch.cjs.map +1 -1
  28. package/dist/adapters/redocly-loader/remote-fetch.mjs +40 -14
  29. package/dist/adapters/redocly-loader/remote-fetch.mjs.map +1 -1
  30. package/dist/adapters/redocly-loader/schema-load-errors.cjs +23 -5
  31. package/dist/adapters/redocly-loader/schema-load-errors.cjs.map +1 -1
  32. package/dist/adapters/redocly-loader/schema-load-errors.mjs +23 -5
  33. package/dist/adapters/redocly-loader/schema-load-errors.mjs.map +1 -1
  34. package/dist/adapters/redocly-loader/unsupported-keys.cjs +9 -1
  35. package/dist/adapters/redocly-loader/unsupported-keys.cjs.map +1 -1
  36. package/dist/adapters/redocly-loader/unsupported-keys.mjs +9 -1
  37. package/dist/adapters/redocly-loader/unsupported-keys.mjs.map +1 -1
  38. package/dist/adapters/terminal-logger/terminal-logger.cjs +6 -4
  39. package/dist/adapters/terminal-logger/terminal-logger.cjs.map +1 -1
  40. package/dist/adapters/terminal-logger/terminal-logger.mjs +6 -4
  41. package/dist/adapters/terminal-logger/terminal-logger.mjs.map +1 -1
  42. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs +5 -1
  43. package/dist/adapters/type-ast-bridge/ir-to-typescript.cjs.map +1 -1
  44. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs +5 -1
  45. package/dist/adapters/type-ast-bridge/ir-to-typescript.mjs.map +1 -1
  46. package/dist/adapters/type-ast-bridge/print-typescript.cjs.map +1 -1
  47. package/dist/adapters/type-ast-bridge/print-typescript.mjs.map +1 -1
  48. package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs +15 -9
  49. package/dist/adapters/type-ast-bridge/typescript-to-ir.cjs.map +1 -1
  50. package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs +15 -9
  51. package/dist/adapters/type-ast-bridge/typescript-to-ir.mjs.map +1 -1
  52. package/dist/api/default-ports.cjs +9 -0
  53. package/dist/api/default-ports.cjs.map +1 -1
  54. package/dist/api/default-ports.mjs +8 -1
  55. package/dist/api/default-ports.mjs.map +1 -1
  56. package/dist/api/discriminator-conflict-warnings.cjs +25 -0
  57. package/dist/api/discriminator-conflict-warnings.cjs.map +1 -0
  58. package/dist/api/discriminator-conflict-warnings.mjs +23 -0
  59. package/dist/api/discriminator-conflict-warnings.mjs.map +1 -0
  60. package/dist/api/discriminator-enum-names.cjs +19 -0
  61. package/dist/api/discriminator-enum-names.cjs.map +1 -0
  62. package/dist/api/discriminator-enum-names.mjs +17 -0
  63. package/dist/api/discriminator-enum-names.mjs.map +1 -0
  64. package/dist/api/discriminator-enum-parent.cjs +59 -0
  65. package/dist/api/discriminator-enum-parent.cjs.map +1 -0
  66. package/dist/api/discriminator-enum-parent.mjs +57 -0
  67. package/dist/api/discriminator-enum-parent.mjs.map +1 -0
  68. package/dist/api/discriminator-enum.cjs +25 -0
  69. package/dist/api/discriminator-enum.cjs.map +1 -1
  70. package/dist/api/discriminator-enum.mjs +25 -1
  71. package/dist/api/discriminator-enum.mjs.map +1 -1
  72. package/dist/api/discriminator-other-owners.cjs +67 -0
  73. package/dist/api/discriminator-other-owners.cjs.map +1 -0
  74. package/dist/api/discriminator-other-owners.mjs +64 -0
  75. package/dist/api/discriminator-other-owners.mjs.map +1 -0
  76. package/dist/api/discriminator-patch.cjs +92 -0
  77. package/dist/api/discriminator-patch.cjs.map +1 -0
  78. package/dist/api/discriminator-patch.mjs +86 -0
  79. package/dist/api/discriminator-patch.mjs.map +1 -0
  80. package/dist/api/discriminator-scan.cjs +50 -65
  81. package/dist/api/discriminator-scan.cjs.map +1 -1
  82. package/dist/api/discriminator-scan.mjs +44 -59
  83. package/dist/api/discriminator-scan.mjs.map +1 -1
  84. package/dist/api/document-refs.cjs +15 -12
  85. package/dist/api/document-refs.cjs.map +1 -1
  86. package/dist/api/document-refs.mjs +15 -12
  87. package/dist/api/document-refs.mjs.map +1 -1
  88. package/dist/api/document-run.cjs +21 -4
  89. package/dist/api/document-run.cjs.map +1 -1
  90. package/dist/api/document-run.mjs +22 -5
  91. package/dist/api/document-run.mjs.map +1 -1
  92. package/dist/api/enum-values-warnings.cjs +16 -0
  93. package/dist/api/enum-values-warnings.cjs.map +1 -0
  94. package/dist/api/enum-values-warnings.mjs +14 -0
  95. package/dist/api/enum-values-warnings.mjs.map +1 -0
  96. package/dist/api/footer-sink.cjs +25 -2
  97. package/dist/api/footer-sink.cjs.map +1 -1
  98. package/dist/api/footer-sink.mjs +25 -2
  99. package/dist/api/footer-sink.mjs.map +1 -1
  100. package/dist/api/legacy-callback-warning.cjs +4 -1
  101. package/dist/api/legacy-callback-warning.cjs.map +1 -1
  102. package/dist/api/legacy-callback-warning.mjs +4 -1
  103. package/dist/api/legacy-callback-warning.mjs.map +1 -1
  104. package/dist/api/legacy-ts-helpers.cjs.map +1 -1
  105. package/dist/api/legacy-ts-helpers.mjs.map +1 -1
  106. package/dist/api/legacy-utils.cjs.map +1 -1
  107. package/dist/api/legacy-utils.mjs.map +1 -1
  108. package/dist/api/openapi-ts.cjs +2 -1
  109. package/dist/api/openapi-ts.cjs.map +1 -1
  110. package/dist/api/openapi-ts.mjs +3 -2
  111. package/dist/api/openapi-ts.mjs.map +1 -1
  112. package/dist/api/path-template-warnings.cjs +21 -0
  113. package/dist/api/path-template-warnings.cjs.map +1 -0
  114. package/dist/api/path-template-warnings.mjs +19 -0
  115. package/dist/api/path-template-warnings.mjs.map +1 -0
  116. package/dist/api/transform-context.cjs +4 -2
  117. package/dist/api/transform-context.cjs.map +1 -1
  118. package/dist/api/transform-context.mjs +4 -2
  119. package/dist/api/transform-context.mjs.map +1 -1
  120. package/dist/api/transform-schema.cjs +52 -3
  121. package/dist/api/transform-schema.cjs.map +1 -1
  122. package/dist/api/transform-schema.mjs +53 -4
  123. package/dist/api/transform-schema.mjs.map +1 -1
  124. package/dist/api/unsupported-feature-warnings.cjs +6 -1
  125. package/dist/api/unsupported-feature-warnings.cjs.map +1 -1
  126. package/dist/api/unsupported-feature-warnings.mjs +6 -1
  127. package/dist/api/unsupported-feature-warnings.mjs.map +1 -1
  128. package/dist/application/print/type-printer.cjs +7 -1
  129. package/dist/application/print/type-printer.cjs.map +1 -1
  130. package/dist/application/print/type-printer.mjs +7 -1
  131. package/dist/application/print/type-printer.mjs.map +1 -1
  132. package/dist/application/transform/document/assignability.cjs +144 -0
  133. package/dist/application/transform/document/assignability.cjs.map +1 -0
  134. package/dist/application/transform/document/assignability.mjs +138 -0
  135. package/dist/application/transform/document/assignability.mjs.map +1 -0
  136. package/dist/application/transform/document/components.cjs +2 -2
  137. package/dist/application/transform/document/components.cjs.map +1 -1
  138. package/dist/application/transform/document/components.mjs +4 -4
  139. package/dist/application/transform/document/components.mjs.map +1 -1
  140. package/dist/application/transform/document/declared-types.cjs +66 -0
  141. package/dist/application/transform/document/declared-types.cjs.map +1 -0
  142. package/dist/application/transform/document/declared-types.mjs +63 -0
  143. package/dist/application/transform/document/declared-types.mjs.map +1 -0
  144. package/dist/application/transform/document/document.cjs +32 -9
  145. package/dist/application/transform/document/document.cjs.map +1 -1
  146. package/dist/application/transform/document/document.mjs +34 -11
  147. package/dist/application/transform/document/document.mjs.map +1 -1
  148. package/dist/application/transform/document/exploded-query.cjs +46 -0
  149. package/dist/application/transform/document/exploded-query.cjs.map +1 -0
  150. package/dist/application/transform/document/exploded-query.mjs +43 -0
  151. package/dist/application/transform/document/exploded-query.mjs.map +1 -0
  152. package/dist/application/transform/document/global-type-references.cjs +63 -0
  153. package/dist/application/transform/document/global-type-references.cjs.map +1 -0
  154. package/dist/application/transform/document/global-type-references.mjs +61 -0
  155. package/dist/application/transform/document/global-type-references.mjs.map +1 -0
  156. package/dist/application/transform/document/list-assignability.cjs +54 -0
  157. package/dist/application/transform/document/list-assignability.cjs.map +1 -0
  158. package/dist/application/transform/document/list-assignability.mjs +52 -0
  159. package/dist/application/transform/document/list-assignability.mjs.map +1 -0
  160. package/dist/application/transform/document/parameters.cjs +41 -9
  161. package/dist/application/transform/document/parameters.cjs.map +1 -1
  162. package/dist/application/transform/document/parameters.mjs +42 -10
  163. package/dist/application/transform/document/parameters.mjs.map +1 -1
  164. package/dist/application/transform/document/path-key-overlaps.cjs +83 -33
  165. package/dist/application/transform/document/path-key-overlaps.cjs.map +1 -1
  166. package/dist/application/transform/document/path-key-overlaps.mjs +83 -33
  167. package/dist/application/transform/document/path-key-overlaps.mjs.map +1 -1
  168. package/dist/application/transform/document/path-template-replace.cjs +48 -0
  169. package/dist/application/transform/document/path-template-replace.cjs.map +1 -0
  170. package/dist/application/transform/document/path-template-replace.mjs +45 -0
  171. package/dist/application/transform/document/path-template-replace.mjs.map +1 -0
  172. package/dist/application/transform/document/paths.cjs +55 -29
  173. package/dist/application/transform/document/paths.cjs.map +1 -1
  174. package/dist/application/transform/document/paths.mjs +54 -30
  175. package/dist/application/transform/document/paths.mjs.map +1 -1
  176. package/dist/application/transform/document/root-type-aliases.cjs +15 -14
  177. package/dist/application/transform/document/root-type-aliases.cjs.map +1 -1
  178. package/dist/application/transform/document/root-type-aliases.mjs +15 -13
  179. package/dist/application/transform/document/root-type-aliases.mjs.map +1 -1
  180. package/dist/application/transform/document/template-key-match.cjs +128 -0
  181. package/dist/application/transform/document/template-key-match.cjs.map +1 -0
  182. package/dist/application/transform/document/template-key-match.mjs +125 -0
  183. package/dist/application/transform/document/template-key-match.mjs.map +1 -0
  184. package/dist/application/transform/document/type-assignability.cjs +192 -0
  185. package/dist/application/transform/document/type-assignability.cjs.map +1 -0
  186. package/dist/application/transform/document/type-assignability.mjs +190 -0
  187. package/dist/application/transform/document/type-assignability.mjs.map +1 -0
  188. package/dist/application/transform/document/type-key.cjs +70 -0
  189. package/dist/application/transform/document/type-key.cjs.map +1 -0
  190. package/dist/application/transform/document/type-key.mjs +68 -0
  191. package/dist/application/transform/document/type-key.mjs.map +1 -0
  192. package/dist/application/transform/document/type-resolution.cjs +131 -0
  193. package/dist/application/transform/document/type-resolution.cjs.map +1 -0
  194. package/dist/application/transform/document/type-resolution.mjs +125 -0
  195. package/dist/application/transform/document/type-resolution.mjs.map +1 -0
  196. package/dist/application/transform/footer/document-footer.cjs +66 -4
  197. package/dist/application/transform/footer/document-footer.cjs.map +1 -1
  198. package/dist/application/transform/footer/document-footer.mjs +67 -5
  199. package/dist/application/transform/footer/document-footer.mjs.map +1 -1
  200. package/dist/application/transform/footer/enum-naming.cjs +17 -0
  201. package/dist/application/transform/footer/enum-naming.cjs.map +1 -1
  202. package/dist/application/transform/footer/enum-naming.mjs +17 -1
  203. package/dist/application/transform/footer/enum-naming.mjs.map +1 -1
  204. package/dist/application/transform/footer/enum-values-check.cjs +129 -0
  205. package/dist/application/transform/footer/enum-values-check.cjs.map +1 -0
  206. package/dist/application/transform/footer/enum-values-check.mjs +127 -0
  207. package/dist/application/transform/footer/enum-values-check.mjs.map +1 -0
  208. package/dist/application/transform/footer/evaluation.cjs +42 -0
  209. package/dist/application/transform/footer/evaluation.cjs.map +1 -0
  210. package/dist/application/transform/footer/evaluation.mjs +33 -0
  211. package/dist/application/transform/footer/evaluation.mjs.map +1 -0
  212. package/dist/application/transform/footer/shared-enum-names.cjs +60 -0
  213. package/dist/application/transform/footer/shared-enum-names.cjs.map +1 -0
  214. package/dist/application/transform/footer/shared-enum-names.mjs +57 -0
  215. package/dist/application/transform/footer/shared-enum-names.mjs.map +1 -0
  216. package/dist/application/transform/footer/type-evaluation.cjs +138 -0
  217. package/dist/application/transform/footer/type-evaluation.cjs.map +1 -0
  218. package/dist/application/transform/footer/type-evaluation.mjs +136 -0
  219. package/dist/application/transform/footer/type-evaluation.mjs.map +1 -0
  220. package/dist/application/transform/footer/type-indexing.cjs +107 -0
  221. package/dist/application/transform/footer/type-indexing.cjs.map +1 -0
  222. package/dist/application/transform/footer/type-indexing.mjs +105 -0
  223. package/dist/application/transform/footer/type-indexing.mjs.map +1 -0
  224. package/dist/application/transform/footer/type-rules.cjs +172 -0
  225. package/dist/application/transform/footer/type-rules.cjs.map +1 -0
  226. package/dist/application/transform/footer/type-rules.mjs +166 -0
  227. package/dist/application/transform/footer/type-rules.mjs.map +1 -0
  228. package/dist/application/transform/ref-pointer/generated-location.cjs +138 -0
  229. package/dist/application/transform/ref-pointer/generated-location.cjs.map +1 -0
  230. package/dist/application/transform/ref-pointer/generated-location.mjs +136 -0
  231. package/dist/application/transform/ref-pointer/generated-location.mjs.map +1 -0
  232. package/dist/application/transform/ref-pointer/generated-shape.cjs +171 -0
  233. package/dist/application/transform/ref-pointer/generated-shape.cjs.map +1 -0
  234. package/dist/application/transform/ref-pointer/generated-shape.mjs +162 -0
  235. package/dist/application/transform/ref-pointer/generated-shape.mjs.map +1 -0
  236. package/dist/application/transform/ref-pointer/inline-cycles.cjs +44 -0
  237. package/dist/application/transform/ref-pointer/inline-cycles.cjs.map +1 -0
  238. package/dist/application/transform/ref-pointer/inline-cycles.mjs +42 -0
  239. package/dist/application/transform/ref-pointer/inline-cycles.mjs.map +1 -0
  240. package/dist/application/transform/ref-pointer/original-index.cjs +62 -0
  241. package/dist/application/transform/ref-pointer/original-index.cjs.map +1 -0
  242. package/dist/application/transform/ref-pointer/original-index.mjs +60 -0
  243. package/dist/application/transform/ref-pointer/original-index.mjs.map +1 -0
  244. package/dist/application/transform/ref-pointer/pointer-type.cjs +60 -0
  245. package/dist/application/transform/ref-pointer/pointer-type.cjs.map +1 -0
  246. package/dist/application/transform/ref-pointer/pointer-type.mjs +57 -0
  247. package/dist/application/transform/ref-pointer/pointer-type.mjs.map +1 -0
  248. package/dist/application/transform/ref-pointer/pointer-walk.cjs +66 -0
  249. package/dist/application/transform/ref-pointer/pointer-walk.cjs.map +1 -0
  250. package/dist/application/transform/ref-pointer/pointer-walk.mjs +56 -0
  251. package/dist/application/transform/ref-pointer/pointer-walk.mjs.map +1 -0
  252. package/dist/application/transform/ref-pointer/typed-walk.cjs +124 -0
  253. package/dist/application/transform/ref-pointer/typed-walk.cjs.map +1 -0
  254. package/dist/application/transform/ref-pointer/typed-walk.mjs +122 -0
  255. package/dist/application/transform/ref-pointer/typed-walk.mjs.map +1 -0
  256. package/dist/application/transform/ref-type.cjs +7 -2
  257. package/dist/application/transform/ref-type.cjs.map +1 -1
  258. package/dist/application/transform/ref-type.mjs +3 -2
  259. package/dist/application/transform/ref-type.mjs.map +1 -1
  260. package/dist/application/transform/schema/access-flags.cjs +38 -0
  261. package/dist/application/transform/schema/access-flags.cjs.map +1 -0
  262. package/dist/application/transform/schema/access-flags.mjs +36 -0
  263. package/dist/application/transform/schema/access-flags.mjs.map +1 -0
  264. package/dist/application/transform/schema/array-type.cjs +32 -1
  265. package/dist/application/transform/schema/array-type.cjs.map +1 -1
  266. package/dist/application/transform/schema/array-type.mjs +33 -2
  267. package/dist/application/transform/schema/array-type.mjs.map +1 -1
  268. package/dist/application/transform/schema/composition-type.cjs +50 -15
  269. package/dist/application/transform/schema/composition-type.cjs.map +1 -1
  270. package/dist/application/transform/schema/composition-type.mjs +50 -15
  271. package/dist/application/transform/schema/composition-type.mjs.map +1 -1
  272. package/dist/application/transform/schema/core-type.cjs +3 -1
  273. package/dist/application/transform/schema/core-type.cjs.map +1 -1
  274. package/dist/application/transform/schema/core-type.mjs +3 -1
  275. package/dist/application/transform/schema/core-type.mjs.map +1 -1
  276. package/dist/application/transform/schema/discriminated-union.cjs +30 -0
  277. package/dist/application/transform/schema/discriminated-union.cjs.map +1 -0
  278. package/dist/application/transform/schema/discriminated-union.mjs +27 -0
  279. package/dist/application/transform/schema/discriminated-union.mjs.map +1 -0
  280. package/dist/application/transform/schema/discriminator-property.cjs +3 -2
  281. package/dist/application/transform/schema/discriminator-property.cjs.map +1 -1
  282. package/dist/application/transform/schema/discriminator-property.mjs +3 -2
  283. package/dist/application/transform/schema/discriminator-property.mjs.map +1 -1
  284. package/dist/application/transform/schema/enum-rule.cjs +66 -10
  285. package/dist/application/transform/schema/enum-rule.cjs.map +1 -1
  286. package/dist/application/transform/schema/enum-rule.mjs +67 -12
  287. package/dist/application/transform/schema/enum-rule.mjs.map +1 -1
  288. package/dist/application/transform/schema/inherited-discriminator.cjs +29 -0
  289. package/dist/application/transform/schema/inherited-discriminator.cjs.map +1 -0
  290. package/dist/application/transform/schema/inherited-discriminator.mjs +26 -0
  291. package/dist/application/transform/schema/inherited-discriminator.mjs.map +1 -0
  292. package/dist/application/transform/schema/object-type.cjs +38 -25
  293. package/dist/application/transform/schema/object-type.cjs.map +1 -1
  294. package/dist/application/transform/schema/object-type.mjs +39 -27
  295. package/dist/application/transform/schema/object-type.mjs.map +1 -1
  296. package/dist/application/transform/schema/required-variants.cjs +45 -0
  297. package/dist/application/transform/schema/required-variants.cjs.map +1 -0
  298. package/dist/application/transform/schema/required-variants.mjs +42 -0
  299. package/dist/application/transform/schema/required-variants.mjs.map +1 -0
  300. package/dist/application/transform/schema/schema-transform.cjs +2 -2
  301. package/dist/application/transform/schema/schema-transform.cjs.map +1 -1
  302. package/dist/application/transform/schema/schema-transform.mjs +2 -2
  303. package/dist/application/transform/schema/schema-transform.mjs.map +1 -1
  304. package/dist/application/transform/schema-comment.cjs +51 -5
  305. package/dist/application/transform/schema-comment.cjs.map +1 -1
  306. package/dist/application/transform/schema-comment.mjs +50 -6
  307. package/dist/application/transform/schema-comment.mjs.map +1 -1
  308. package/dist/application/transform/type-combinators.mjs +1 -1
  309. package/dist/cli/api-settings.cjs +78 -0
  310. package/dist/cli/api-settings.cjs.map +1 -0
  311. package/dist/cli/api-settings.mjs +73 -0
  312. package/dist/cli/api-settings.mjs.map +1 -0
  313. package/dist/cli/cli-arguments.cjs +12 -3
  314. package/dist/cli/cli-arguments.cjs.map +1 -1
  315. package/dist/cli/cli-arguments.mjs +12 -4
  316. package/dist/cli/cli-arguments.mjs.map +1 -1
  317. package/dist/cli/cli-errors.cjs +3 -2
  318. package/dist/cli/cli-errors.cjs.map +1 -1
  319. package/dist/cli/cli-errors.mjs +3 -2
  320. package/dist/cli/cli-errors.mjs.map +1 -1
  321. package/dist/cli/cli-output.cjs +8 -3
  322. package/dist/cli/cli-output.cjs.map +1 -1
  323. package/dist/cli/cli-output.mjs +9 -4
  324. package/dist/cli/cli-output.mjs.map +1 -1
  325. package/dist/cli/help-text.cjs +3 -3
  326. package/dist/cli/help-text.cjs.map +1 -1
  327. package/dist/cli/help-text.mjs +3 -3
  328. package/dist/cli/help-text.mjs.map +1 -1
  329. package/dist/cli/main.cjs +5 -0
  330. package/dist/cli/main.cjs.map +1 -1
  331. package/dist/cli/main.mjs +5 -0
  332. package/dist/cli/main.mjs.map +1 -1
  333. package/dist/cli/redocly-apis.cjs +15 -7
  334. package/dist/cli/redocly-apis.cjs.map +1 -1
  335. package/dist/cli/redocly-apis.mjs +15 -7
  336. package/dist/cli/redocly-apis.mjs.map +1 -1
  337. package/dist/cli/ref-limits.cjs +1 -1
  338. package/dist/cli/ref-limits.cjs.map +1 -1
  339. package/dist/cli/ref-limits.mjs +2 -2
  340. package/dist/cli/ref-limits.mjs.map +1 -1
  341. package/dist/cli/run-cli.cjs +20 -3
  342. package/dist/cli/run-cli.cjs.map +1 -1
  343. package/dist/cli/run-cli.mjs +21 -4
  344. package/dist/cli/run-cli.mjs.map +1 -1
  345. package/dist/domain/errors.cjs +6 -1
  346. package/dist/domain/errors.cjs.map +1 -1
  347. package/dist/domain/errors.mjs +6 -1
  348. package/dist/domain/errors.mjs.map +1 -1
  349. package/dist/domain/ir/constructors.cjs +7 -1
  350. package/dist/domain/ir/constructors.cjs.map +1 -1
  351. package/dist/domain/ir/constructors.mjs +6 -2
  352. package/dist/domain/ir/constructors.mjs.map +1 -1
  353. package/dist/domain/openapi/admitted-values.cjs +75 -0
  354. package/dist/domain/openapi/admitted-values.cjs.map +1 -0
  355. package/dist/domain/openapi/admitted-values.mjs +72 -0
  356. package/dist/domain/openapi/admitted-values.mjs.map +1 -0
  357. package/dist/domain/openapi/discriminated-union.cjs +68 -0
  358. package/dist/domain/openapi/discriminated-union.cjs.map +1 -0
  359. package/dist/domain/openapi/discriminated-union.mjs +62 -0
  360. package/dist/domain/openapi/discriminated-union.mjs.map +1 -0
  361. package/dist/domain/openapi/discriminator-conflicts.cjs +143 -0
  362. package/dist/domain/openapi/discriminator-conflicts.cjs.map +1 -0
  363. package/dist/domain/openapi/discriminator-conflicts.mjs +141 -0
  364. package/dist/domain/openapi/discriminator-conflicts.mjs.map +1 -0
  365. package/dist/domain/openapi/parameter-object.cjs.map +1 -1
  366. package/dist/domain/openapi/parameter-object.mjs.map +1 -1
  367. package/dist/domain/openapi/path-templates.cjs +23 -0
  368. package/dist/domain/openapi/path-templates.cjs.map +1 -0
  369. package/dist/domain/openapi/path-templates.mjs +21 -0
  370. package/dist/domain/openapi/path-templates.mjs.map +1 -0
  371. package/dist/domain/output-fixes.cjs +36 -1
  372. package/dist/domain/output-fixes.cjs.map +1 -1
  373. package/dist/domain/output-fixes.mjs +36 -1
  374. package/dist/domain/output-fixes.mjs.map +1 -1
  375. package/dist/domain/url-credentials.cjs +10 -0
  376. package/dist/domain/url-credentials.cjs.map +1 -0
  377. package/dist/domain/url-credentials.mjs +8 -0
  378. package/dist/domain/url-credentials.mjs.map +1 -0
  379. package/dist/domain/warnings.cjs +23 -0
  380. package/dist/domain/warnings.cjs.map +1 -0
  381. package/dist/domain/warnings.mjs +20 -0
  382. package/dist/domain/warnings.mjs.map +1 -0
  383. package/dist/index.cjs +2 -0
  384. package/dist/index.cjs.map +1 -1
  385. package/dist/index.d.cts +1182 -46
  386. package/dist/index.d.mts +1182 -46
  387. package/dist/index.d.ts +1182 -46
  388. package/dist/index.mjs +1 -0
  389. package/dist/index.mjs.map +1 -1
  390. package/dist/transform/components-object.cjs +2 -1
  391. package/dist/transform/components-object.cjs.map +1 -1
  392. package/dist/transform/components-object.mjs +2 -1
  393. package/dist/transform/components-object.mjs.map +1 -1
  394. package/dist/transform/path-item-object.cjs.map +1 -1
  395. package/dist/transform/path-item-object.mjs.map +1 -1
  396. package/package.json +6 -5
  397. package/src/adapters/redocly-loader/configured-headers.ts +65 -0
  398. package/src/adapters/redocly-loader/redocly-config-source.ts +41 -6
  399. package/src/adapters/redocly-loader/redocly-schema-loader.ts +44 -13
  400. package/src/adapters/redocly-loader/ref-access.ts +60 -5
  401. package/src/adapters/redocly-loader/ref-resolution-check.ts +257 -0
  402. package/src/adapters/redocly-loader/ref-resolution-steps.ts +113 -0
  403. package/src/adapters/redocly-loader/remote-fetch.ts +77 -21
  404. package/src/adapters/redocly-loader/schema-load-errors.ts +33 -11
  405. package/src/adapters/redocly-loader/unsupported-keys.ts +17 -2
  406. package/src/adapters/terminal-logger/terminal-logger.ts +9 -5
  407. package/src/adapters/type-ast-bridge/ir-to-typescript.ts +5 -1
  408. package/src/adapters/type-ast-bridge/print-typescript.ts +3 -1
  409. package/src/adapters/type-ast-bridge/typescript-to-ir.ts +26 -12
  410. package/src/adapters/type-ast-bridge/typescript-types.ts +57 -5
  411. package/src/api/default-ports.ts +16 -0
  412. package/src/api/discriminator-conflict-warnings.ts +43 -0
  413. package/src/api/discriminator-enum-names.ts +26 -0
  414. package/src/api/discriminator-enum-parent.ts +129 -0
  415. package/src/api/discriminator-enum.ts +39 -0
  416. package/src/api/discriminator-other-owners.ts +97 -0
  417. package/src/api/discriminator-patch.ts +152 -0
  418. package/src/api/discriminator-scan.ts +78 -90
  419. package/src/api/document-refs.ts +19 -15
  420. package/src/api/document-run.ts +32 -11
  421. package/src/api/enum-values-warnings.ts +21 -0
  422. package/src/api/footer-sink.ts +34 -2
  423. package/src/api/legacy-callback-warning.ts +7 -3
  424. package/src/api/legacy-ts-helpers.ts +7 -5
  425. package/src/api/legacy-utils.ts +1 -1
  426. package/src/api/openapi-ts.ts +2 -0
  427. package/src/api/path-template-warnings.ts +27 -0
  428. package/src/api/run-context.ts +34 -0
  429. package/src/api/transform-context.ts +17 -9
  430. package/src/api/transform-schema.ts +90 -5
  431. package/src/api/unsupported-feature-warnings.ts +8 -1
  432. package/src/application/ports/redocly-config-source.ts +5 -1
  433. package/src/application/print/type-printer.ts +8 -1
  434. package/src/application/transform/document/assignability.ts +203 -0
  435. package/src/application/transform/document/components.ts +6 -6
  436. package/src/application/transform/document/declared-types.ts +93 -0
  437. package/src/application/transform/document/document.ts +71 -13
  438. package/src/application/transform/document/exploded-query.ts +91 -0
  439. package/src/application/transform/document/global-type-references.ts +78 -0
  440. package/src/application/transform/document/list-assignability.ts +87 -0
  441. package/src/application/transform/document/parameters.ts +78 -12
  442. package/src/application/transform/document/path-key-overlaps.ts +148 -59
  443. package/src/application/transform/document/path-template-replace.ts +90 -0
  444. package/src/application/transform/document/paths.ts +101 -38
  445. package/src/application/transform/document/root-type-aliases.ts +29 -28
  446. package/src/application/transform/document/template-key-match.ts +183 -0
  447. package/src/application/transform/document/type-assignability.ts +268 -0
  448. package/src/application/transform/document/type-key.ts +80 -0
  449. package/src/application/transform/document/type-resolution.ts +163 -0
  450. package/src/application/transform/footer/document-footer.ts +91 -6
  451. package/src/application/transform/footer/enum-naming.ts +29 -0
  452. package/src/application/transform/footer/enum-values-check.ts +171 -0
  453. package/src/application/transform/footer/evaluation.ts +57 -0
  454. package/src/application/transform/footer/shared-enum-names.ts +86 -0
  455. package/src/application/transform/footer/type-evaluation.ts +167 -0
  456. package/src/application/transform/footer/type-indexing.ts +152 -0
  457. package/src/application/transform/footer/type-rules.ts +269 -0
  458. package/src/application/transform/ref-pointer/generated-location.ts +211 -0
  459. package/src/application/transform/ref-pointer/generated-shape.ts +275 -0
  460. package/src/application/transform/ref-pointer/inline-cycles.ts +56 -0
  461. package/src/application/transform/ref-pointer/original-index.ts +95 -0
  462. package/src/application/transform/ref-pointer/pointer-type.ts +92 -0
  463. package/src/application/transform/ref-pointer/pointer-walk.ts +96 -0
  464. package/src/application/transform/ref-pointer/typed-walk.ts +192 -0
  465. package/src/application/transform/ref-type.ts +11 -6
  466. package/src/application/transform/schema/access-flags.ts +63 -0
  467. package/src/application/transform/schema/array-type.ts +66 -5
  468. package/src/application/transform/schema/composition-type.ts +96 -24
  469. package/src/application/transform/schema/core-type.ts +8 -4
  470. package/src/application/transform/schema/discriminated-union.ts +58 -0
  471. package/src/application/transform/schema/discriminator-property.ts +8 -3
  472. package/src/application/transform/schema/enum-rule.ts +136 -13
  473. package/src/application/transform/schema/inherited-discriminator.ts +54 -0
  474. package/src/application/transform/schema/object-type.ts +51 -33
  475. package/src/application/transform/schema/required-variants.ts +88 -0
  476. package/src/application/transform/schema/schema-context.ts +26 -0
  477. package/src/application/transform/schema/schema-transform.ts +2 -2
  478. package/src/application/transform/schema-comment.ts +84 -4
  479. package/src/cli/api-settings.ts +109 -0
  480. package/src/cli/cli-arguments.ts +18 -5
  481. package/src/cli/cli-dependencies.ts +5 -0
  482. package/src/cli/cli-errors.ts +4 -2
  483. package/src/cli/cli-output.ts +18 -4
  484. package/src/cli/help-text.ts +4 -4
  485. package/src/cli/main.ts +6 -0
  486. package/src/cli/redocly-apis.ts +21 -11
  487. package/src/cli/ref-limits.ts +2 -2
  488. package/src/cli/run-cli.ts +25 -4
  489. package/src/domain/errors.ts +10 -2
  490. package/src/domain/ir/constructors.ts +9 -1
  491. package/src/domain/ir/nodes.ts +11 -7
  492. package/src/domain/openapi/admitted-values.ts +113 -0
  493. package/src/domain/openapi/discriminated-union.ts +109 -0
  494. package/src/domain/openapi/discriminator-conflicts.ts +251 -0
  495. package/src/domain/openapi/parameter-object.ts +4 -0
  496. package/src/domain/openapi/path-templates.ts +32 -0
  497. package/src/domain/openapi/schema-object.ts +2 -0
  498. package/src/domain/output-fixes.ts +43 -2
  499. package/src/domain/url-credentials.ts +18 -0
  500. package/src/domain/warnings.ts +28 -0
  501. package/src/index.ts +1 -0
  502. package/src/transform/components-object.ts +3 -1
  503. package/src/transform/path-item-object.ts +6 -2
  504. package/src/types/generator-options.ts +12 -21
  505. package/src/types/openapi-common.ts +1 -0
  506. package/src/types/openapi-request.ts +3 -0
  507. package/src/types/openapi-schema.ts +2 -0
  508. package/src/types/openapi-security.ts +1 -0
  509. package/dist/application/transform/document/path-item-conflicts.cjs +0 -51
  510. package/dist/application/transform/document/path-item-conflicts.cjs.map +0 -1
  511. package/dist/application/transform/document/path-item-conflicts.mjs +0 -49
  512. package/dist/application/transform/document/path-item-conflicts.mjs.map +0 -1
  513. package/src/application/transform/document/path-item-conflicts.ts +0 -79
@@ -1,5 +1,6 @@
1
1
  import type ts from "typescript";
2
2
  import { assertNever } from "../../domain/assert-never.js";
3
+ import { DEFAULT_STRING_ENCODING } from "../../domain/ir/constructors.js";
3
4
  import type {
4
5
  IrComment,
5
6
  IrKeyword,
@@ -74,6 +75,9 @@ function toStringLiteralType(
74
75
 
75
76
  function toTupleElement(ts: TypeScriptModule, element: IrTupleElement): ts.TypeNode {
76
77
  const type = toTypeNode(ts, element.type);
78
+ if (element.isOptional) {
79
+ return ts.factory.createOptionalTypeNode(type);
80
+ }
77
81
  return element.isRest ? ts.factory.createRestTypeNode(type) : type;
78
82
  }
79
83
 
@@ -87,7 +91,7 @@ function toLeafTypeNode(ts: TypeScriptModule, type: LeafType): ts.TypeNode {
87
91
  case "keyword":
88
92
  return toKeywordType(ts, type.keyword);
89
93
  case "stringLiteral":
90
- return toStringLiteralType(ts, type.value, type.encoding);
94
+ return toStringLiteralType(ts, type.value, type.encoding ?? DEFAULT_STRING_ENCODING);
91
95
  case "numberLiteral":
92
96
  return ts.factory.createLiteralTypeNode(toNumberExpression(ts, type.value));
93
97
  case "booleanLiteral":
@@ -1,11 +1,13 @@
1
1
  import type ts from "typescript";
2
2
  import type { TypeScriptModule } from "./load-typescript.js";
3
+ import type { ts as CompilerTypes } from "./typescript-types.js";
3
4
 
4
5
  /** Options of `astToString` for the TypeScript printer, as in the original. */
5
6
  export interface AstToStringOptions {
6
7
  fileName?: string;
7
8
  sourceText?: string;
8
- formatOptions?: ts.PrinterOptions;
9
+ /** The installed compiler's printer options (ADR-032: named without `ts.PrinterOptions`). */
10
+ formatOptions?: CompilerTypes.PrinterOptions;
9
11
  }
10
12
 
11
13
  /** Print TypeScript nodes as the original `astToString` did. */
@@ -6,6 +6,7 @@ import type {
6
6
  IrMember,
7
7
  IrPropertyName,
8
8
  IrPropertySignature,
9
+ IrTupleElement,
9
10
  IrType,
10
11
  } from "../../domain/ir/nodes.js";
11
12
  import type { TypeScriptModule } from "./load-typescript.js";
@@ -83,20 +84,31 @@ function fromReference(ts: TypeScriptModule, node: ts.TypeReferenceNode): IrType
83
84
  return { kind: "reference", name: ts.idText(node.typeName), typeArguments };
84
85
  }
85
86
 
87
+ function fromTupleElement(
88
+ ts: TypeScriptModule,
89
+ element: ts.TypeNode,
90
+ convert: (node: ts.TypeNode) => IrType,
91
+ ): IrTupleElement {
92
+ if (ts.isRestTypeNode(element)) {
93
+ return { type: convert(element.type), isRest: true, isOptional: false };
94
+ }
95
+ if (ts.isOptionalTypeNode(element)) {
96
+ // The `?` is the parent of the type: it decides which parentheses the factory put in.
97
+ return { type: fromTypeNode(ts, element.type, element), isRest: false, isOptional: true };
98
+ }
99
+ return { type: convert(element), isRest: false, isOptional: false };
100
+ }
101
+
102
+ /** A tuple of plain, rest and optional elements; one with named members stays text. */
86
103
  function fromTuple(ts: TypeScriptModule, node: ts.TupleTypeNode): IrType | null {
87
- const isPlain = node.elements.every(
88
- (element) => !ts.isNamedTupleMember(element) && !ts.isOptionalTypeNode(element),
89
- );
90
- if (!isPlain) {
104
+ if (node.elements.some((element) => ts.isNamedTupleMember(element))) {
91
105
  return null;
92
106
  }
93
107
  const convert = childrenOf(ts, node);
94
- const elements = node.elements.map((element) =>
95
- ts.isRestTypeNode(element)
96
- ? { type: convert(element.type), isRest: true }
97
- : { type: convert(element), isRest: false },
98
- );
99
- return { kind: "tuple", elements };
108
+ return {
109
+ kind: "tuple",
110
+ elements: node.elements.map((element) => fromTupleElement(ts, element, convert)),
111
+ };
100
112
  }
101
113
 
102
114
  /**
@@ -237,8 +249,9 @@ function fromStructure(ts: TypeScriptModule, node: ts.TypeNode): IrType | null {
237
249
 
238
250
  /**
239
251
  * Whether the factory's parenthesizer put these parentheses in (same rules as the IR printer):
240
- * unions, intersections and `readonly` types as array elements, indexed objects and `readonly`
241
- * operands; unions and intersections as members of other unions or intersections.
252
+ * unions, intersections and `readonly` types as array elements, indexed objects, optional tuple
253
+ * elements and `readonly` operands; unions and intersections as members of other unions or
254
+ * intersections.
242
255
  */
243
256
  function isFactoryParenthesis(
244
257
  ts: TypeScriptModule,
@@ -252,6 +265,7 @@ function isFactoryParenthesis(
252
265
  const isPostfixOrReadonlyParent =
253
266
  ts.isArrayTypeNode(parent) ||
254
267
  ts.isIndexedAccessTypeNode(parent) ||
268
+ ts.isOptionalTypeNode(parent) ||
255
269
  ts.isTypeOperatorNode(parent);
256
270
  if (isPostfixOrReadonlyParent) {
257
271
  return isComposite || ts.isTypeOperatorNode(inner);
@@ -1,8 +1,60 @@
1
- import type ts from "typescript";
1
+ import type * as TypeScript from "typescript";
2
2
 
3
3
  /**
4
- * The TypeScript compiler's types for code outside the bridge (ADR-004, decision 4). Type-only:
5
- * it is erased at build time, so importing it never loads TypeScript. Only the bridge imports
6
- * `typescript` itself (enforced by dependency-cruiser).
4
+ * The TypeScript compiler's node types for code outside the bridge and for the public
5
+ * declarations (ADR-004, decision 4; ADR-032). Type-only: importing it never loads TypeScript.
6
+ *
7
+ * Each type is read from the compiler API of the `typescript` package the consumer has installed
8
+ * (`factory`, `createPrinter`), not named as `ts.Node`. TypeScript 5.x and 6.x have that API, so
9
+ * the types are the compiler's own. TypeScript 7's `typescript` package exports only `version`;
10
+ * `ts.Node` there is error TS2694 in a consumer that checks declarations (`skipLibCheck: false`).
7
11
  */
8
- export type { ts };
12
+
13
+ type Api = typeof TypeScript;
14
+ type Factory = Api extends { readonly factory: infer F } ? F : undefined;
15
+
16
+ /**
17
+ * A compiler type when the installed `typescript` has no compiler API (TypeScript 7). It is `any`
18
+ * because that is what these types already were for such a consumer with `skipLibCheck: true`
19
+ * (an unresolved type in a declaration file is `any`), so callbacks that build or read nodes of
20
+ * `@typescript/typescript6` keep compiling (ADR-032). The cost, as before: a union with a node
21
+ * type, such as the result of `transform`, accepts any value there.
22
+ */
23
+ // biome-ignore lint/suspicious/noExplicitAny: unresolved compiler types were `any` (ADR-032)
24
+ type WithoutCompilerApi = any;
25
+
26
+ /** The node type that `factory[Name]` returns, or `WithoutCompilerApi`. */
27
+ type Created<Name extends string> = Factory extends {
28
+ readonly [Key in Name]: (...args: never[]) => infer Result;
29
+ }
30
+ ? Result
31
+ : WithoutCompilerApi;
32
+
33
+ type ModifierList = Created<"createModifiersFromModifierFlags">;
34
+
35
+ /** The compiler node types the package names; see the module comment. */
36
+ export declare namespace ts {
37
+ type Node = Api extends { isTypeNode(node: infer N): boolean } ? N : WithoutCompilerApi;
38
+ type TypeNode = Factory extends { createArrayTypeNode(elementType: infer T): unknown }
39
+ ? T
40
+ : WithoutCompilerApi;
41
+ type QuestionToken = Factory extends {
42
+ createPropertySignature(modifiers: never, name: never, token: infer Q, type: never): unknown;
43
+ }
44
+ ? NonNullable<Q>
45
+ : WithoutCompilerApi;
46
+ type Modifier = ModifierList extends readonly (infer M)[] | undefined ? M : WithoutCompilerApi;
47
+ type PrinterOptions = Api extends { createPrinter(options?: infer O, ...rest: never[]): unknown }
48
+ ? NonNullable<O>
49
+ : WithoutCompilerApi;
50
+ type PropertySignature = Created<"createPropertySignature">;
51
+ type LiteralTypeNode = Created<"createLiteralTypeNode">;
52
+ type TypeLiteralNode = Created<"createTypeLiteralNode">;
53
+ type InterfaceDeclaration = Created<"createInterfaceDeclaration">;
54
+ type EnumDeclaration = Created<"createEnumDeclaration">;
55
+ type EnumMember = Created<"createEnumMember">;
56
+ type VariableStatement = Created<"createVariableStatement">;
57
+ type Identifier = Created<"createIdentifier">;
58
+ type NumericLiteral = Created<"createNumericLiteral">;
59
+ type StringLiteral = Created<"createStringLiteral">;
60
+ }
@@ -1,6 +1,7 @@
1
1
  import { performance } from "node:perf_hooks";
2
2
  import { createConfig, type Config as RedoclyConfig } from "@redocly/openapi-core";
3
3
  import supportsColor from "supports-color";
4
+ import type { RemoteDocumentLimits } from "../adapters/redocly-loader/remote-fetch.js";
4
5
  import { createTerminalLogger } from "../adapters/terminal-logger/terminal-logger.js";
5
6
  import type { Logger } from "../application/ports/logger.js";
6
7
 
@@ -32,6 +33,21 @@ export function defaultLogger(silent: boolean): Logger {
32
33
  */
33
34
  export const REMOTE_REF_TIMEOUT_MS = 60_000;
34
35
 
36
+ /**
37
+ * Bounds on the remote documents of one run (ADR-033). Large split documents have a few thousand
38
+ * files, so 10,000 leaves room and still ends an endless fan-out. 16 parallel fetches keep a
39
+ * multi-file document fast without exhausting local ports.
40
+ */
41
+ export const DEFAULT_REMOTE_DOCUMENT_LIMITS: RemoteDocumentLimits = {
42
+ maxDocuments: 10_000,
43
+ maxParallelFetches: 16,
44
+ };
45
+
46
+ /** The working directory of the process: the default `cwd` of an inline source. */
47
+ export function processCwd(): string {
48
+ return process.cwd();
49
+ }
50
+
35
51
  /** A monotonic clock in milliseconds, for debug durations. */
36
52
  export function monotonicNow(): number {
37
53
  return performance.now();
@@ -0,0 +1,43 @@
1
+ import type { Logger } from "../application/ports/logger.js";
2
+ import {
3
+ type DiscriminatorValueConflict,
4
+ findDiscriminatorValueConflicts,
5
+ } from "../domain/openapi/discriminator-conflicts.js";
6
+ import { OutputFix } from "../domain/output-fixes.js";
7
+ import { WARNING_CODES, warningText } from "../domain/warnings.js";
8
+
9
+ const DOCS_BASE_URL = "https://github.com/openapi-typesafe/openapi-typesafe/blob/main/docs";
10
+ const DOCS_URL = `${DOCS_BASE_URL}/advanced.md#discriminator-values`;
11
+
12
+ function listed(values: readonly unknown[]): string {
13
+ return values.map((value) => JSON.stringify(value)).join(", ");
14
+ }
15
+
16
+ function warningOf(conflict: DiscriminatorValueConflict): string {
17
+ const { member, owner, propertyName, values, allowed, isImplicit } = conflict;
18
+ const rule = isImplicit
19
+ ? "A Discriminator Object without a mapping entry for a schema gives it its schema name as " +
20
+ `the value; add a mapping entry such as ${JSON.stringify(allowed[0])}: "${member}".`
21
+ : "The Discriminator Object maps these values to the schema; map the values it allows.";
22
+ return (
23
+ `${member}: the discriminator "${propertyName}" of ${owner} gives this schema the value ` +
24
+ `${listed(values)}, which its "${propertyName}" property does not allow ` +
25
+ `(${listed(allowed)}), so no value of the schema matches the discriminator. ${rule} ` +
26
+ `See ${DOCS_URL}`
27
+ );
28
+ }
29
+
30
+ /**
31
+ * Warn once per discriminator member whose value its own property does not allow. The members
32
+ * depend on the run's fixes (`allof-discriminated-union`).
33
+ */
34
+ export function warnDiscriminatorValueConflicts(
35
+ document: unknown,
36
+ fixes: readonly OutputFix[],
37
+ logger: Logger,
38
+ ): void {
39
+ const isUnionReused = fixes.includes(OutputFix.ALLOF_DISCRIMINATED_UNION);
40
+ for (const conflict of findDiscriminatorValueConflicts(document, { isUnionReused })) {
41
+ logger.warn(warningText(warningOf(conflict), WARNING_CODES.DISCRIMINATOR_VALUE_NOT_ALLOWED));
42
+ }
43
+ }
@@ -0,0 +1,26 @@
1
+ import type { SharedEnumNames } from "../application/transform/footer/shared-enum-names.js";
2
+ import type { EnumDeclarationRequest } from "../application/transform/schema/schema-context.js";
3
+
4
+ /**
5
+ * `--dedupe-enums` names a shared enum after the first schema that declares it. With
6
+ * `discriminator-values` and `--enum`, a member's value refers to the owner's enum, which is then
7
+ * declared when the member is typed, maybe before that first schema; the shared enum would take
8
+ * the owner's name. A first pass records the names of the declaring schemas only, so the second
9
+ * pass names each shared enum as the document order does (`OtherKind`, not `PetPetType`).
10
+ */
11
+ export class FirstSchemaNameRecorder implements SharedEnumNames {
12
+ private readonly names = new Map<string, string>();
13
+
14
+ nameOf(key: string, name: string, request: EnumDeclarationRequest): string {
15
+ if (!request.isOwnerReference && !this.names.has(key)) {
16
+ this.names.set(key, name);
17
+ }
18
+ return name;
19
+ }
20
+
21
+ /** The recorded name of each shared enum, for the second pass. */
22
+ chosenNames(): SharedEnumNames {
23
+ const chosen = new Map(this.names);
24
+ return { nameOf: (key, name) => chosen.get(key) ?? name };
25
+ }
26
+ }
@@ -0,0 +1,129 @@
1
+ import { createRef, parseRefPointer } from "../domain/openapi/json-pointer.js";
2
+ import type { SchemaObject } from "../types.js";
3
+ import type { EnumPatch } from "./discriminator-enum.js";
4
+
5
+ /**
6
+ * The `discriminator-values` fix (#1700). With `--enum`, the enum the scan adds to a member
7
+ * (`petType: "Cat"`) is declared as an enum of its own (`CatPetType`), which is not assignable to
8
+ * the parent's enum (`PetType`). The parent's enum is found here, so the member's property can be
9
+ * typed with its members (`PetType.Cat`).
10
+ */
11
+
12
+ /** The parent's enum schema and the location it is typed at, which gives the enum its name. */
13
+ export interface EnumParent {
14
+ readonly schema: SchemaObject;
15
+ readonly path: string;
16
+ }
17
+
18
+ type ResolveSchemaRef = (ref: string) => unknown;
19
+
20
+ /** A declared property schema and the location the transformer types it at. */
21
+ interface DeclaredProperty {
22
+ readonly property: unknown;
23
+ readonly path: string;
24
+ }
25
+
26
+ const PROPERTIES_KEYWORD = "properties";
27
+ /** `components`, `schemas` and the schema name: the segments before the schema's own keywords. */
28
+ const ROOT_SEGMENTS = 3;
29
+
30
+ /** The location a `$ref` is typed at: object properties are nested without `properties`. */
31
+ function typedAt(ref: string): string {
32
+ const segments = parseRefPointer(ref);
33
+ const nested = segments.slice(ROOT_SEGMENTS).filter((segment) => segment !== PROPERTIES_KEYWORD);
34
+ return createRef([...segments.slice(0, ROOT_SEGMENTS), ...nested]);
35
+ }
36
+
37
+ function isSchemaObject(value: unknown): value is SchemaObject {
38
+ return typeof value === "object" && value !== null && !Array.isArray(value);
39
+ }
40
+
41
+ /** The property `name` of a schema object typed at `ref`. */
42
+ function ownProperty(item: SchemaObject, ref: string, name: string): DeclaredProperty | undefined {
43
+ const property = ("properties" in item ? item.properties : undefined)?.[name];
44
+ return property === undefined ? undefined : { property, path: createRef([ref, name]) };
45
+ }
46
+
47
+ /** The property `name` of the schema at `ref`, its own or from an `allOf` item, depth first. */
48
+ function declaredProperty(
49
+ ref: string,
50
+ name: string,
51
+ resolve: ResolveSchemaRef,
52
+ visited: Set<string>,
53
+ ): DeclaredProperty | undefined {
54
+ const schema = resolve(ref);
55
+ if (visited.has(ref) || !isSchemaObject(schema)) {
56
+ return undefined;
57
+ }
58
+ visited.add(ref);
59
+ // An inline `allOf` item is typed at its parent's location, so both share the path.
60
+ for (const item of [schema, ...(schema.allOf ?? [])]) {
61
+ if (!isSchemaObject(item)) {
62
+ continue;
63
+ }
64
+ const found =
65
+ "$ref" in item
66
+ ? declaredProperty(item.$ref as string, name, resolve, visited)
67
+ : ownProperty(item, ref, name);
68
+ if (found !== undefined) {
69
+ return found;
70
+ }
71
+ }
72
+ return undefined;
73
+ }
74
+
75
+ /**
76
+ * A discriminator and the `$ref` of the schema that declares its property; `ref` is the member
77
+ * whose value the discriminator gives, where there is one.
78
+ */
79
+ export type DiscriminatorOwner = Pick<EnumPatch, "discriminator" | "discriminatorRef"> &
80
+ Partial<Pick<EnumPatch, "ref">>;
81
+
82
+ /**
83
+ * The property `name` that the member at `ref` inherits through its `allOf` `$ref`s. Its own
84
+ * keywords and inline items are left out: the scan writes the added value there.
85
+ */
86
+ function inheritedProperty(
87
+ ref: string,
88
+ name: string,
89
+ resolve: ResolveSchemaRef,
90
+ ): DeclaredProperty | undefined {
91
+ const schema = resolve(ref);
92
+ const visited = new Set([ref]);
93
+ for (const item of isSchemaObject(schema) ? (schema.allOf ?? []) : []) {
94
+ const found =
95
+ isSchemaObject(item) && "$ref" in item
96
+ ? declaredProperty(item.$ref as string, name, resolve, visited)
97
+ : undefined;
98
+ if (found !== undefined) {
99
+ return found;
100
+ }
101
+ }
102
+ return undefined;
103
+ }
104
+
105
+ /**
106
+ * The enum of the property that the discriminator owner declares, if it is one. An owner that
107
+ * declares no such property (a `oneOf` with a mapping) leaves the member's type to the property
108
+ * the member inherits, so that property's enum is the one.
109
+ */
110
+ export function enumParentOf(
111
+ patch: DiscriminatorOwner,
112
+ resolve: ResolveSchemaRef,
113
+ ): EnumParent | undefined {
114
+ const name = patch.discriminator.propertyName;
115
+ const declared =
116
+ declaredProperty(patch.discriminatorRef, name, resolve, new Set()) ??
117
+ (patch.ref === undefined ? undefined : inheritedProperty(patch.ref, name, resolve));
118
+ if (declared === undefined || !isSchemaObject(declared.property)) {
119
+ return undefined;
120
+ }
121
+ const ref = (declared.property as { readonly $ref?: unknown }).$ref;
122
+ const parent =
123
+ typeof ref === "string"
124
+ ? { schema: resolve(ref), path: typedAt(ref) }
125
+ : { schema: declared.property, path: declared.path };
126
+ return isSchemaObject(parent.schema) && Array.isArray(parent.schema.enum)
127
+ ? { schema: parent.schema, path: parent.path }
128
+ : undefined;
129
+ }
@@ -61,6 +61,45 @@ function isObjectSchema(schema: unknown): schema is SchemaObject & ObjectSubtype
61
61
  );
62
62
  }
63
63
 
64
+ /** The values a property schema allows, from `const` or `enum`; null when it lists none. */
65
+ function listedValues(property: unknown): readonly unknown[] | null {
66
+ if (typeof property !== "object" || property === null) {
67
+ return null;
68
+ }
69
+ const { const: constant, enum: values } = property as SchemaObject;
70
+ if (constant !== undefined) {
71
+ return [constant];
72
+ }
73
+ return Array.isArray(values) ? values : null;
74
+ }
75
+
76
+ /** Whether one schema object requires the property and allows exactly the values. */
77
+ function requiresValues(schema: unknown, name: string, values: readonly string[]): boolean {
78
+ if (typeof schema !== "object" || schema === null || "$ref" in schema) {
79
+ return false;
80
+ }
81
+ const { required, properties } = schema as SchemaObject & ObjectSubtype;
82
+ const listed = listedValues(properties?.[name]);
83
+ return (
84
+ Boolean(required?.includes(name)) &&
85
+ listed !== null &&
86
+ listed.length === values.length &&
87
+ values.every((value) => listed.includes(value))
88
+ );
89
+ }
90
+
91
+ /**
92
+ * Whether `schema`, or an inline `allOf` item of it, already requires the discriminator property
93
+ * with exactly the patch's values (the `discriminator-values` fix). Then a patch would
94
+ * only repeat it (#2124).
95
+ */
96
+ export function declaresValues(schema: SchemaObject | undefined, patch: EnumPatch): boolean {
97
+ const name = patch.discriminator.propertyName;
98
+ return [schema, ...(schema?.allOf ?? [])].some((item) =>
99
+ requiresValues(item, name, patch.values),
100
+ );
101
+ }
102
+
64
103
  /**
65
104
  * Add or replace the enum property in `schema`, an `allOf` or object schema. Returns the added
66
105
  * enum schema, or null for another kind of schema, which is left as it is.
@@ -0,0 +1,97 @@
1
+ import type { DiscriminatorObject, ReferenceObject, SchemaObject } from "../types.js";
2
+ import type { EnumPatch } from "./discriminator-enum.js";
3
+ import { enumKey, patchDiscriminatorEnum, type ScanState } from "./discriminator-patch.js";
4
+ import { resolveDocumentRef } from "./document-refs.js";
5
+
6
+ /**
7
+ * The `discriminator-values` fix: a schema inherits one discriminator per property. A schema that
8
+ * owns a discriminator keeps its own (#2200), so the scan does not record the one it inherits for
9
+ * another property (`Content` owns `subtype` and `allOf`s `Element`, which owns `contentType`).
10
+ * Its members (`Video`) still get a value of that property, found here from the owners above.
11
+ */
12
+
13
+ /** A discriminator and the schema that defines it. */
14
+ interface OtherOwner {
15
+ readonly discriminator: DiscriminatorObject;
16
+ readonly ownerRef: string;
17
+ }
18
+
19
+ /** The `$ref`s of a schema's `allOf` items. */
20
+ function allOfRefs(state: ScanState, ref: string): string[] {
21
+ const { silent, logger } = state;
22
+ const schema = resolveDocumentRef<SchemaObject>(state.schema, ref, { silent, logger });
23
+ const items = (schema?.allOf ?? []) as (SchemaObject | ReferenceObject)[];
24
+ return items.flatMap((item) =>
25
+ "$ref" in item && typeof item.$ref === "string" ? [item.$ref] : [],
26
+ );
27
+ }
28
+
29
+ /**
30
+ * The owners' discriminators that the schema at `parentRef` and its `allOf` parents define, the
31
+ * nearest one per property, except the property of `parentRef`'s own discriminator.
32
+ */
33
+ function otherOwners(state: ScanState, parentRef: string): OtherOwner[] {
34
+ const own = state.objects[parentRef]?.propertyName;
35
+ const found = new Map<string, OtherOwner>();
36
+ const visited = new Set<string>();
37
+ const queue = [parentRef];
38
+ for (let ref = queue.shift(); ref !== undefined; ref = queue.shift()) {
39
+ if (visited.has(ref)) {
40
+ continue;
41
+ }
42
+ visited.add(ref);
43
+ const discriminator = state.owners.has(ref) ? state.objects[ref] : undefined;
44
+ const name = discriminator?.propertyName;
45
+ if (discriminator && name !== undefined && name !== own && !found.has(name)) {
46
+ found.set(name, { discriminator, ownerRef: ref });
47
+ }
48
+ queue.push(...allOfRefs(state, ref));
49
+ }
50
+ return [...found.values()];
51
+ }
52
+
53
+ /**
54
+ * The child redefines this property, so its `allOf` items omit it: a parent may have a value of
55
+ * its own, as `Content` has when `Element`'s mapping names it.
56
+ */
57
+ function recordOtherProperty(state: ScanState, ref: string, propertyName: string): void {
58
+ const names = state.otherProperties[ref] ?? [];
59
+ if (!names.includes(propertyName)) {
60
+ names.push(propertyName);
61
+ }
62
+ state.otherProperties[ref] = names;
63
+ }
64
+
65
+ /**
66
+ * The child at `ref` of the schema at `parentRef` gets a value of each other property: a mapped
67
+ * one at once, else its schema name after both passes, where no mapping gives one. The schema's
68
+ * own discriminator property is still added, so these patches do not mark it handled.
69
+ */
70
+ export function inheritOtherOwners(state: ScanState, parentRef: string, ref: string): void {
71
+ const childProperty = state.objects[ref]?.propertyName;
72
+ for (const { discriminator, ownerRef } of otherOwners(state, parentRef)) {
73
+ if (discriminator.propertyName === childProperty) {
74
+ continue;
75
+ }
76
+ recordOtherProperty(state, ref, discriminator.propertyName);
77
+ const mapped = Object.entries(discriminator.mapping ?? {})
78
+ .filter(([, target]) => target === ref)
79
+ .map(([value]) => value);
80
+ const name = ref.slice(ref.lastIndexOf("/") + 1);
81
+ const patch: EnumPatch = { ref, values: mapped, discriminator, discriminatorRef: ownerRef };
82
+ if (mapped.length > 0) {
83
+ patchDiscriminatorEnum(state, patch);
84
+ } else {
85
+ state.otherInferredPatches.push({ ...patch, values: [name] });
86
+ }
87
+ }
88
+ }
89
+
90
+ /** The deferred schema-name values of other properties; see `inheritOtherOwners`. */
91
+ export function applyOtherInferredPatches(state: ScanState, mapped: ReadonlySet<string>): void {
92
+ for (const patch of state.otherInferredPatches) {
93
+ if (!mapped.has(enumKey(patch))) {
94
+ patchDiscriminatorEnum(state, patch);
95
+ }
96
+ }
97
+ }