@skmtc/core 0.39.0 → 0.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (373) hide show
  1. package/esm/context/CoreContext.js +22 -8
  2. package/esm/context/GenerateContext.d.ts +6 -5
  3. package/esm/context/GenerateContext.js +112 -38
  4. package/esm/context/ParseContext.d.ts +18 -1
  5. package/esm/context/ParseContext.js +102 -3
  6. package/esm/context/generateTypes.d.ts +33 -4
  7. package/esm/context/generateTypes.js +4 -0
  8. package/esm/context/toGenerationFailure.d.ts +21 -0
  9. package/esm/context/toGenerationFailure.js +38 -0
  10. package/esm/context/tryParseAt.d.ts +4 -1
  11. package/esm/context/tryParseAt.js +10 -3
  12. package/esm/dsl/CustomValue.d.ts +4 -0
  13. package/esm/dsl/CustomValue.js +8 -0
  14. package/esm/dsl/Definition.d.ts +10 -0
  15. package/esm/dsl/Definition.js +14 -0
  16. package/esm/dsl/PendingDefinition.d.ts +47 -0
  17. package/esm/dsl/PendingDefinition.js +83 -0
  18. package/esm/dsl/model/ModelDriver.d.ts +55 -1
  19. package/esm/dsl/model/ModelDriver.js +228 -51
  20. package/esm/dsl/model/toModelEntry.d.ts +1 -1
  21. package/esm/dsl/model/toModelEntry.js +1 -1
  22. package/esm/dsl/model/types.d.ts +1 -1
  23. package/esm/dsl/operation/gql/GqlOperationDriver.js +1 -4
  24. package/esm/dsl/webhook/WebhookDriver.js +1 -4
  25. package/esm/enrichments/parseEnrichmentUmbrella.d.ts +5 -6
  26. package/esm/enrichments/parseEnrichmentUmbrella.js +23 -8
  27. package/esm/enrichments/parseEnrichmentValue.d.ts +17 -0
  28. package/esm/enrichments/parseEnrichmentValue.js +32 -0
  29. package/esm/enrichments/readEnrichments.d.ts +5 -5
  30. package/esm/enrichments/readEnrichments.js +17 -7
  31. package/esm/helpers/collateExamples.js +15 -5
  32. package/esm/helpers/refFns.d.ts +6 -2
  33. package/esm/helpers/refFns.js +24 -7
  34. package/esm/mod.d.ts +2 -0
  35. package/esm/mod.js +2 -0
  36. package/esm/oas/array/Array.d.ts +19 -0
  37. package/esm/oas/array/Array.js +47 -0
  38. package/esm/oas/boolean/Boolean.d.ts +19 -0
  39. package/esm/oas/boolean/Boolean.js +51 -8
  40. package/esm/oas/example/Example.d.ts +4 -0
  41. package/esm/oas/example/Example.js +8 -0
  42. package/esm/oas/header/Header.d.ts +4 -0
  43. package/esm/oas/header/Header.js +8 -0
  44. package/esm/oas/integer/Integer.d.ts +19 -0
  45. package/esm/oas/integer/Integer.js +49 -0
  46. package/esm/oas/link/Link.d.ts +4 -0
  47. package/esm/oas/link/Link.js +8 -0
  48. package/esm/oas/number/Number.d.ts +19 -0
  49. package/esm/oas/number/Number.js +49 -0
  50. package/esm/oas/object/Object.d.ts +19 -0
  51. package/esm/oas/object/Object.js +68 -18
  52. package/esm/oas/operation/Operation.d.ts +8 -1
  53. package/esm/oas/operation/Operation.js +18 -5
  54. package/esm/oas/operation/toEffectiveParameters.d.ts +24 -0
  55. package/esm/oas/operation/toEffectiveParameters.js +42 -0
  56. package/esm/oas/parameter/Parameter.d.ts +4 -0
  57. package/esm/oas/parameter/Parameter.js +8 -0
  58. package/esm/oas/ref/DanglingRefError.d.ts +22 -0
  59. package/esm/oas/ref/DanglingRefError.js +33 -0
  60. package/esm/oas/ref/Ref.d.ts +152 -25
  61. package/esm/oas/ref/Ref.js +414 -26
  62. package/esm/oas/requestBody/RequestBody.d.ts +4 -0
  63. package/esm/oas/requestBody/RequestBody.js +8 -0
  64. package/esm/oas/response/Response.d.ts +4 -0
  65. package/esm/oas/response/Response.js +8 -0
  66. package/esm/oas/schema/siblings.d.ts +127 -0
  67. package/esm/oas/schema/siblings.js +250 -0
  68. package/esm/oas/securitySchemes/SecurityScheme.d.ts +16 -0
  69. package/esm/oas/securitySchemes/SecurityScheme.js +32 -0
  70. package/esm/oas/string/String.d.ts +19 -0
  71. package/esm/oas/string/String.js +47 -0
  72. package/esm/oas/union/Union.d.ts +32 -0
  73. package/esm/oas/union/Union.js +111 -0
  74. package/esm/oas/unknown/Unknown.d.ts +18 -0
  75. package/esm/oas/unknown/Unknown.js +38 -0
  76. package/esm/oas/void/Void.d.ts +4 -0
  77. package/esm/oas/void/Void.js +8 -0
  78. package/esm/oas/webhook/Webhook.d.ts +2 -2
  79. package/esm/oas/webhook/Webhook.js +4 -5
  80. package/esm/parse/allOfSystem.d.ts +32 -0
  81. package/esm/parse/allOfSystem.js +30 -0
  82. package/esm/parse/anyOfSystem.d.ts +68 -0
  83. package/esm/parse/anyOfSystem.js +107 -0
  84. package/esm/parse/securityRequirements.d.ts +6 -0
  85. package/esm/parse/securityRequirements.js +8 -0
  86. package/esm/parse/toSiblingKeywords.d.ts +28 -0
  87. package/esm/parse/toSiblingKeywords.js +109 -0
  88. package/esm/parse/v3-0/_merge-all-of/decompose-union.d.ts +8 -0
  89. package/esm/parse/v3-0/_merge-all-of/decompose-union.js +9 -1
  90. package/esm/parse/v3-0/_merge-all-of/generic-merge.d.ts +2 -3
  91. package/esm/parse/v3-0/_merge-all-of/generic-merge.js +2 -2
  92. package/esm/parse/v3-0/_merge-all-of/merge-array-constraints.d.ts +2 -2
  93. package/esm/parse/v3-0/_merge-all-of/merge-array-constraints.js +5 -5
  94. package/esm/parse/v3-0/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  95. package/esm/parse/v3-0/_merge-all-of/merge-boolean-constraints.js +2 -2
  96. package/esm/parse/v3-0/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  97. package/esm/parse/v3-0/_merge-all-of/merge-integer-constraints.js +2 -2
  98. package/esm/parse/v3-0/_merge-all-of/merge-intersection.d.ts +3 -2
  99. package/esm/parse/v3-0/_merge-all-of/merge-intersection.js +2 -2
  100. package/esm/parse/v3-0/_merge-all-of/merge-number-constraints.d.ts +2 -2
  101. package/esm/parse/v3-0/_merge-all-of/merge-number-constraints.js +2 -2
  102. package/esm/parse/v3-0/_merge-all-of/merge-object-constraints.d.ts +2 -2
  103. package/esm/parse/v3-0/_merge-all-of/merge-object-constraints.js +3 -3
  104. package/esm/parse/v3-0/_merge-all-of/merge-properties.d.ts +2 -2
  105. package/esm/parse/v3-0/_merge-all-of/merge-properties.js +2 -2
  106. package/esm/parse/v3-0/_merge-all-of/merge-string-constraints.d.ts +2 -2
  107. package/esm/parse/v3-0/_merge-all-of/merge-string-constraints.js +3 -3
  108. package/esm/parse/v3-0/_merge-all-of/merge-union.d.ts +10 -3
  109. package/esm/parse/v3-0/_merge-all-of/merge-union.js +50 -12
  110. package/esm/parse/v3-0/_merge-all-of/merge.d.ts +2 -2
  111. package/esm/parse/v3-0/_merge-all-of/merge.js +78 -27
  112. package/esm/parse/v3-0/_merge-all-of/nullable-merge.d.ts +4 -0
  113. package/esm/parse/v3-0/_merge-all-of/nullable-merge.js +9 -7
  114. package/esm/parse/v3-0/_merge-all-of/types.d.ts +33 -0
  115. package/esm/parse/v3-0/mediaType/toMediaTypeItemV3.js +4 -3
  116. package/esm/parse/v3-0/parameter/toParameterV3.js +4 -3
  117. package/esm/parse/v3-0/ref/toRefV31.d.ts +7 -1
  118. package/esm/parse/v3-0/ref/toRefV31.js +6 -3
  119. package/esm/parse/v3-0/schema/toSchemasV3.js +107 -15
  120. package/esm/parse/v3-1/_merge-all-of/decompose-union.d.ts +7 -1
  121. package/esm/parse/v3-1/_merge-all-of/decompose-union.js +8 -2
  122. package/esm/parse/v3-1/_merge-all-of/generic-merge.d.ts +2 -3
  123. package/esm/parse/v3-1/_merge-all-of/generic-merge.js +2 -2
  124. package/esm/parse/v3-1/_merge-all-of/merge-array-constraints.d.ts +3 -2
  125. package/esm/parse/v3-1/_merge-all-of/merge-array-constraints.js +5 -5
  126. package/esm/parse/v3-1/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  127. package/esm/parse/v3-1/_merge-all-of/merge-boolean-constraints.js +2 -2
  128. package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  129. package/esm/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -2
  130. package/esm/parse/v3-1/_merge-all-of/merge-intersection.d.ts +3 -2
  131. package/esm/parse/v3-1/_merge-all-of/merge-intersection.js +2 -2
  132. package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.d.ts +2 -2
  133. package/esm/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -2
  134. package/esm/parse/v3-1/_merge-all-of/merge-object-constraints.d.ts +2 -2
  135. package/esm/parse/v3-1/_merge-all-of/merge-object-constraints.js +3 -3
  136. package/esm/parse/v3-1/_merge-all-of/merge-properties.d.ts +2 -2
  137. package/esm/parse/v3-1/_merge-all-of/merge-properties.js +2 -2
  138. package/esm/parse/v3-1/_merge-all-of/merge-string-constraints.d.ts +2 -2
  139. package/esm/parse/v3-1/_merge-all-of/merge-string-constraints.js +3 -3
  140. package/esm/parse/v3-1/_merge-all-of/merge-union.d.ts +10 -3
  141. package/esm/parse/v3-1/_merge-all-of/merge-union.js +54 -15
  142. package/esm/parse/v3-1/_merge-all-of/merge.d.ts +3 -2
  143. package/esm/parse/v3-1/_merge-all-of/merge.js +88 -29
  144. package/esm/parse/v3-1/_merge-all-of/nullable-merge.d.ts +4 -0
  145. package/esm/parse/v3-1/_merge-all-of/nullable-merge.js +9 -7
  146. package/esm/parse/v3-1/_merge-all-of/types.d.ts +37 -0
  147. package/esm/parse/v3-1/mediaType/toMediaTypeItemV3.js +4 -3
  148. package/esm/parse/v3-1/parameter/toParameterV3.js +4 -3
  149. package/esm/parse/v3-1/ref/toRefV31.d.ts +7 -1
  150. package/esm/parse/v3-1/ref/toRefV31.js +6 -3
  151. package/esm/parse/v3-1/schema/toSchemasV3.js +111 -16
  152. package/esm/parse/v3-2/_merge-all-of/decompose-union.d.ts +7 -1
  153. package/esm/parse/v3-2/_merge-all-of/decompose-union.js +8 -2
  154. package/esm/parse/v3-2/_merge-all-of/generic-merge.d.ts +2 -3
  155. package/esm/parse/v3-2/_merge-all-of/generic-merge.js +2 -2
  156. package/esm/parse/v3-2/_merge-all-of/merge-array-constraints.d.ts +3 -2
  157. package/esm/parse/v3-2/_merge-all-of/merge-array-constraints.js +5 -5
  158. package/esm/parse/v3-2/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  159. package/esm/parse/v3-2/_merge-all-of/merge-boolean-constraints.js +2 -2
  160. package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  161. package/esm/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -2
  162. package/esm/parse/v3-2/_merge-all-of/merge-intersection.d.ts +3 -2
  163. package/esm/parse/v3-2/_merge-all-of/merge-intersection.js +2 -2
  164. package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.d.ts +2 -2
  165. package/esm/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -2
  166. package/esm/parse/v3-2/_merge-all-of/merge-object-constraints.d.ts +2 -2
  167. package/esm/parse/v3-2/_merge-all-of/merge-object-constraints.js +3 -3
  168. package/esm/parse/v3-2/_merge-all-of/merge-properties.d.ts +2 -2
  169. package/esm/parse/v3-2/_merge-all-of/merge-properties.js +2 -2
  170. package/esm/parse/v3-2/_merge-all-of/merge-string-constraints.d.ts +2 -2
  171. package/esm/parse/v3-2/_merge-all-of/merge-string-constraints.js +3 -3
  172. package/esm/parse/v3-2/_merge-all-of/merge-union.d.ts +10 -3
  173. package/esm/parse/v3-2/_merge-all-of/merge-union.js +54 -15
  174. package/esm/parse/v3-2/_merge-all-of/merge.d.ts +3 -2
  175. package/esm/parse/v3-2/_merge-all-of/merge.js +88 -29
  176. package/esm/parse/v3-2/_merge-all-of/nullable-merge.d.ts +4 -0
  177. package/esm/parse/v3-2/_merge-all-of/nullable-merge.js +9 -7
  178. package/esm/parse/v3-2/_merge-all-of/types.d.ts +37 -0
  179. package/esm/parse/v3-2/mediaType/toMediaTypeItemV3.js +4 -3
  180. package/esm/parse/v3-2/parameter/toParameterV3.js +4 -3
  181. package/esm/parse/v3-2/ref/toRefV31.d.ts +7 -1
  182. package/esm/parse/v3-2/ref/toRefV31.js +6 -3
  183. package/esm/parse/v3-2/schema/toSchemasV3.js +111 -16
  184. package/esm/types/OasBase.d.ts +1 -1
  185. package/esm/types/Settings.d.ts +44 -0
  186. package/esm/types/Settings.js +9 -0
  187. package/package.json +5 -1
  188. package/script/context/CoreContext.js +22 -8
  189. package/script/context/GenerateContext.d.ts +6 -5
  190. package/script/context/GenerateContext.js +112 -38
  191. package/script/context/ParseContext.d.ts +18 -1
  192. package/script/context/ParseContext.js +102 -3
  193. package/script/context/generateTypes.d.ts +33 -4
  194. package/script/context/generateTypes.js +4 -0
  195. package/script/context/toGenerationFailure.d.ts +21 -0
  196. package/script/context/toGenerationFailure.js +43 -0
  197. package/script/context/tryParseAt.d.ts +4 -1
  198. package/script/context/tryParseAt.js +10 -3
  199. package/script/dsl/CustomValue.d.ts +4 -0
  200. package/script/dsl/CustomValue.js +8 -0
  201. package/script/dsl/Definition.d.ts +10 -0
  202. package/script/dsl/Definition.js +14 -0
  203. package/script/dsl/PendingDefinition.d.ts +47 -0
  204. package/script/dsl/PendingDefinition.js +87 -0
  205. package/script/dsl/model/ModelDriver.d.ts +55 -1
  206. package/script/dsl/model/ModelDriver.js +231 -52
  207. package/script/dsl/model/toModelEntry.d.ts +1 -1
  208. package/script/dsl/model/toModelEntry.js +1 -1
  209. package/script/dsl/model/types.d.ts +1 -1
  210. package/script/dsl/operation/gql/GqlOperationDriver.js +1 -4
  211. package/script/dsl/webhook/WebhookDriver.js +1 -4
  212. package/script/enrichments/parseEnrichmentUmbrella.d.ts +5 -6
  213. package/script/enrichments/parseEnrichmentUmbrella.js +23 -41
  214. package/script/enrichments/parseEnrichmentValue.d.ts +17 -0
  215. package/script/enrichments/parseEnrichmentValue.js +69 -0
  216. package/script/enrichments/readEnrichments.d.ts +5 -5
  217. package/script/enrichments/readEnrichments.js +17 -40
  218. package/script/helpers/collateExamples.js +15 -5
  219. package/script/helpers/refFns.d.ts +6 -2
  220. package/script/helpers/refFns.js +24 -7
  221. package/script/mod.d.ts +2 -0
  222. package/script/mod.js +2 -0
  223. package/script/oas/array/Array.d.ts +19 -0
  224. package/script/oas/array/Array.js +47 -0
  225. package/script/oas/boolean/Boolean.d.ts +19 -0
  226. package/script/oas/boolean/Boolean.js +51 -8
  227. package/script/oas/example/Example.d.ts +4 -0
  228. package/script/oas/example/Example.js +8 -0
  229. package/script/oas/header/Header.d.ts +4 -0
  230. package/script/oas/header/Header.js +8 -0
  231. package/script/oas/integer/Integer.d.ts +19 -0
  232. package/script/oas/integer/Integer.js +49 -0
  233. package/script/oas/link/Link.d.ts +4 -0
  234. package/script/oas/link/Link.js +8 -0
  235. package/script/oas/number/Number.d.ts +19 -0
  236. package/script/oas/number/Number.js +49 -0
  237. package/script/oas/object/Object.d.ts +19 -0
  238. package/script/oas/object/Object.js +68 -18
  239. package/script/oas/operation/Operation.d.ts +8 -1
  240. package/script/oas/operation/Operation.js +18 -5
  241. package/script/oas/operation/toEffectiveParameters.d.ts +24 -0
  242. package/script/oas/operation/toEffectiveParameters.js +47 -0
  243. package/script/oas/parameter/Parameter.d.ts +4 -0
  244. package/script/oas/parameter/Parameter.js +8 -0
  245. package/script/oas/ref/DanglingRefError.d.ts +22 -0
  246. package/script/oas/ref/DanglingRefError.js +37 -0
  247. package/script/oas/ref/Ref.d.ts +152 -25
  248. package/script/oas/ref/Ref.js +414 -26
  249. package/script/oas/requestBody/RequestBody.d.ts +4 -0
  250. package/script/oas/requestBody/RequestBody.js +8 -0
  251. package/script/oas/response/Response.d.ts +4 -0
  252. package/script/oas/response/Response.js +8 -0
  253. package/script/oas/schema/siblings.d.ts +127 -0
  254. package/script/oas/schema/siblings.js +305 -0
  255. package/script/oas/securitySchemes/SecurityScheme.d.ts +16 -0
  256. package/script/oas/securitySchemes/SecurityScheme.js +32 -0
  257. package/script/oas/string/String.d.ts +19 -0
  258. package/script/oas/string/String.js +47 -0
  259. package/script/oas/union/Union.d.ts +32 -0
  260. package/script/oas/union/Union.js +111 -0
  261. package/script/oas/unknown/Unknown.d.ts +18 -0
  262. package/script/oas/unknown/Unknown.js +38 -0
  263. package/script/oas/void/Void.d.ts +4 -0
  264. package/script/oas/void/Void.js +8 -0
  265. package/script/oas/webhook/Webhook.d.ts +2 -2
  266. package/script/oas/webhook/Webhook.js +4 -5
  267. package/script/parse/allOfSystem.d.ts +32 -0
  268. package/script/parse/allOfSystem.js +35 -0
  269. package/script/parse/anyOfSystem.d.ts +68 -0
  270. package/script/parse/anyOfSystem.js +116 -0
  271. package/script/parse/securityRequirements.d.ts +6 -0
  272. package/script/parse/securityRequirements.js +8 -0
  273. package/script/parse/toSiblingKeywords.d.ts +28 -0
  274. package/script/parse/toSiblingKeywords.js +146 -0
  275. package/script/parse/v3-0/_merge-all-of/decompose-union.d.ts +8 -0
  276. package/script/parse/v3-0/_merge-all-of/decompose-union.js +11 -2
  277. package/script/parse/v3-0/_merge-all-of/generic-merge.d.ts +2 -3
  278. package/script/parse/v3-0/_merge-all-of/generic-merge.js +2 -2
  279. package/script/parse/v3-0/_merge-all-of/merge-array-constraints.d.ts +2 -2
  280. package/script/parse/v3-0/_merge-all-of/merge-array-constraints.js +5 -5
  281. package/script/parse/v3-0/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  282. package/script/parse/v3-0/_merge-all-of/merge-boolean-constraints.js +2 -2
  283. package/script/parse/v3-0/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  284. package/script/parse/v3-0/_merge-all-of/merge-integer-constraints.js +2 -2
  285. package/script/parse/v3-0/_merge-all-of/merge-intersection.d.ts +3 -2
  286. package/script/parse/v3-0/_merge-all-of/merge-intersection.js +2 -2
  287. package/script/parse/v3-0/_merge-all-of/merge-number-constraints.d.ts +2 -2
  288. package/script/parse/v3-0/_merge-all-of/merge-number-constraints.js +2 -2
  289. package/script/parse/v3-0/_merge-all-of/merge-object-constraints.d.ts +2 -2
  290. package/script/parse/v3-0/_merge-all-of/merge-object-constraints.js +3 -3
  291. package/script/parse/v3-0/_merge-all-of/merge-properties.d.ts +2 -2
  292. package/script/parse/v3-0/_merge-all-of/merge-properties.js +2 -2
  293. package/script/parse/v3-0/_merge-all-of/merge-string-constraints.d.ts +2 -2
  294. package/script/parse/v3-0/_merge-all-of/merge-string-constraints.js +3 -3
  295. package/script/parse/v3-0/_merge-all-of/merge-union.d.ts +10 -3
  296. package/script/parse/v3-0/_merge-all-of/merge-union.js +52 -13
  297. package/script/parse/v3-0/_merge-all-of/merge.d.ts +2 -2
  298. package/script/parse/v3-0/_merge-all-of/merge.js +77 -26
  299. package/script/parse/v3-0/_merge-all-of/nullable-merge.d.ts +4 -0
  300. package/script/parse/v3-0/_merge-all-of/nullable-merge.js +9 -7
  301. package/script/parse/v3-0/_merge-all-of/types.d.ts +33 -0
  302. package/script/parse/v3-0/mediaType/toMediaTypeItemV3.js +4 -3
  303. package/script/parse/v3-0/parameter/toParameterV3.js +4 -3
  304. package/script/parse/v3-0/ref/toRefV31.d.ts +7 -1
  305. package/script/parse/v3-0/ref/toRefV31.js +6 -3
  306. package/script/parse/v3-0/schema/toSchemasV3.js +107 -15
  307. package/script/parse/v3-1/_merge-all-of/decompose-union.d.ts +7 -1
  308. package/script/parse/v3-1/_merge-all-of/decompose-union.js +8 -2
  309. package/script/parse/v3-1/_merge-all-of/generic-merge.d.ts +2 -3
  310. package/script/parse/v3-1/_merge-all-of/generic-merge.js +2 -2
  311. package/script/parse/v3-1/_merge-all-of/merge-array-constraints.d.ts +3 -2
  312. package/script/parse/v3-1/_merge-all-of/merge-array-constraints.js +5 -5
  313. package/script/parse/v3-1/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  314. package/script/parse/v3-1/_merge-all-of/merge-boolean-constraints.js +2 -2
  315. package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  316. package/script/parse/v3-1/_merge-all-of/merge-integer-constraints.js +2 -2
  317. package/script/parse/v3-1/_merge-all-of/merge-intersection.d.ts +3 -2
  318. package/script/parse/v3-1/_merge-all-of/merge-intersection.js +2 -2
  319. package/script/parse/v3-1/_merge-all-of/merge-number-constraints.d.ts +2 -2
  320. package/script/parse/v3-1/_merge-all-of/merge-number-constraints.js +2 -2
  321. package/script/parse/v3-1/_merge-all-of/merge-object-constraints.d.ts +2 -2
  322. package/script/parse/v3-1/_merge-all-of/merge-object-constraints.js +3 -3
  323. package/script/parse/v3-1/_merge-all-of/merge-properties.d.ts +2 -2
  324. package/script/parse/v3-1/_merge-all-of/merge-properties.js +2 -2
  325. package/script/parse/v3-1/_merge-all-of/merge-string-constraints.d.ts +2 -2
  326. package/script/parse/v3-1/_merge-all-of/merge-string-constraints.js +3 -3
  327. package/script/parse/v3-1/_merge-all-of/merge-union.d.ts +10 -3
  328. package/script/parse/v3-1/_merge-all-of/merge-union.js +56 -16
  329. package/script/parse/v3-1/_merge-all-of/merge.d.ts +3 -2
  330. package/script/parse/v3-1/_merge-all-of/merge.js +87 -28
  331. package/script/parse/v3-1/_merge-all-of/nullable-merge.d.ts +4 -0
  332. package/script/parse/v3-1/_merge-all-of/nullable-merge.js +9 -7
  333. package/script/parse/v3-1/_merge-all-of/types.d.ts +37 -0
  334. package/script/parse/v3-1/mediaType/toMediaTypeItemV3.js +4 -3
  335. package/script/parse/v3-1/parameter/toParameterV3.js +4 -3
  336. package/script/parse/v3-1/ref/toRefV31.d.ts +7 -1
  337. package/script/parse/v3-1/ref/toRefV31.js +6 -3
  338. package/script/parse/v3-1/schema/toSchemasV3.js +111 -16
  339. package/script/parse/v3-2/_merge-all-of/decompose-union.d.ts +7 -1
  340. package/script/parse/v3-2/_merge-all-of/decompose-union.js +8 -2
  341. package/script/parse/v3-2/_merge-all-of/generic-merge.d.ts +2 -3
  342. package/script/parse/v3-2/_merge-all-of/generic-merge.js +2 -2
  343. package/script/parse/v3-2/_merge-all-of/merge-array-constraints.d.ts +3 -2
  344. package/script/parse/v3-2/_merge-all-of/merge-array-constraints.js +5 -5
  345. package/script/parse/v3-2/_merge-all-of/merge-boolean-constraints.d.ts +2 -2
  346. package/script/parse/v3-2/_merge-all-of/merge-boolean-constraints.js +2 -2
  347. package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.d.ts +2 -2
  348. package/script/parse/v3-2/_merge-all-of/merge-integer-constraints.js +2 -2
  349. package/script/parse/v3-2/_merge-all-of/merge-intersection.d.ts +3 -2
  350. package/script/parse/v3-2/_merge-all-of/merge-intersection.js +2 -2
  351. package/script/parse/v3-2/_merge-all-of/merge-number-constraints.d.ts +2 -2
  352. package/script/parse/v3-2/_merge-all-of/merge-number-constraints.js +2 -2
  353. package/script/parse/v3-2/_merge-all-of/merge-object-constraints.d.ts +2 -2
  354. package/script/parse/v3-2/_merge-all-of/merge-object-constraints.js +3 -3
  355. package/script/parse/v3-2/_merge-all-of/merge-properties.d.ts +2 -2
  356. package/script/parse/v3-2/_merge-all-of/merge-properties.js +2 -2
  357. package/script/parse/v3-2/_merge-all-of/merge-string-constraints.d.ts +2 -2
  358. package/script/parse/v3-2/_merge-all-of/merge-string-constraints.js +3 -3
  359. package/script/parse/v3-2/_merge-all-of/merge-union.d.ts +10 -3
  360. package/script/parse/v3-2/_merge-all-of/merge-union.js +56 -16
  361. package/script/parse/v3-2/_merge-all-of/merge.d.ts +3 -2
  362. package/script/parse/v3-2/_merge-all-of/merge.js +87 -28
  363. package/script/parse/v3-2/_merge-all-of/nullable-merge.d.ts +4 -0
  364. package/script/parse/v3-2/_merge-all-of/nullable-merge.js +9 -7
  365. package/script/parse/v3-2/_merge-all-of/types.d.ts +37 -0
  366. package/script/parse/v3-2/mediaType/toMediaTypeItemV3.js +4 -3
  367. package/script/parse/v3-2/parameter/toParameterV3.js +4 -3
  368. package/script/parse/v3-2/ref/toRefV31.d.ts +7 -1
  369. package/script/parse/v3-2/ref/toRefV31.js +6 -3
  370. package/script/parse/v3-2/schema/toSchemasV3.js +111 -16
  371. package/script/types/OasBase.d.ts +1 -1
  372. package/script/types/Settings.d.ts +44 -0
  373. package/script/types/Settings.js +10 -1
@@ -14,12 +14,13 @@ import { mergeBooleanConstraints } from './merge-boolean-constraints.js';
14
14
  import { genericMerge } from './generic-merge.js';
15
15
  import { checkAtLeastOneTypeMatch } from './check-at-least-one-type-match.js';
16
16
  import { mergeIntersection } from './merge-intersection.js';
17
- import { mergeCrossProduct } from './merge-union.js';
17
+ import { mergeCrossProduct, toOwnSystem } from './merge-union.js';
18
18
  import { isEmpty } from '../../../helpers/isEmpty.js';
19
19
  import { isNullOnly, mergeNullOnly } from './nullable-merge.js';
20
- export const mergeSchemasOrRefs = (first, second, getRef) => {
20
+ import { withoutUnknownAnyOf } from '../../anyOfSystem.js';
21
+ export const mergeSchemasOrRefs = ({ first, second, getRef, system }) => {
21
22
  if (containsRef(first, second)) {
22
- return mergeWithRef(first, second, getRef);
23
+ return mergeWithRef({ first, second, getRef, system });
23
24
  }
24
25
  if (isRef(first)) {
25
26
  throw new Error('Ref in first');
@@ -27,18 +28,30 @@ export const mergeSchemasOrRefs = (first, second, getRef) => {
27
28
  if (isRef(second)) {
28
29
  throw new Error('Ref in second');
29
30
  }
31
+ // Under `system.anyOf: unknown` an `anyOf` of two or more members is any
32
+ // value, so it adds nothing to the merge: its members are left out, and the
33
+ // keywords next to it merge as usual.
34
+ const firstKeywords = withoutUnknownAnyOf({ schema: first, setting: system.anyOf, getRef });
35
+ const secondKeywords = withoutUnknownAnyOf({ schema: second, setting: system.anyOf, getRef });
36
+ if (firstKeywords !== first || secondKeywords !== second) {
37
+ system.unknown?.add('anyOf');
38
+ return mergeSchemasOrRefs({ first: firstKeywords, second: secondKeywords, getRef, system });
39
+ }
30
40
  if (containsAllOf(first) || containsAllOf(second)) {
31
- const mergedFirst = containsAllOf(first) ? mergeIntersection({ schema: first, getRef }) : first;
41
+ // Each member's own `allOf` merges under the `client.json` setting, also in
42
+ // the strict first pass over a cross product's pairs.
43
+ const ownSystem = toOwnSystem(system);
44
+ const mergedFirst = containsAllOf(first) ? mergeIntersection({ schema: first, getRef, system: ownSystem }) : first;
32
45
  const mergedSecond = containsAllOf(second)
33
- ? mergeIntersection({ schema: second, getRef })
46
+ ? mergeIntersection({ schema: second, getRef, system: ownSystem })
34
47
  : second;
35
- return mergeSchemasOrRefs(mergedFirst, mergedSecond, getRef);
48
+ return mergeSchemasOrRefs({ first: mergedFirst, second: mergedSecond, getRef, system });
36
49
  }
37
50
  if (containsOneOf(first, second)) {
38
- return mergeCrossProduct({ first, second, getRef, groupType: 'oneOf' });
51
+ return mergeCrossProduct({ first, second, getRef, system, groupType: 'oneOf' });
39
52
  }
40
53
  if (containsAnyOf(first, second)) {
41
- return mergeCrossProduct({ first, second, getRef, groupType: 'anyOf' });
54
+ return mergeCrossProduct({ first, second, getRef, system, groupType: 'anyOf' });
42
55
  }
43
56
  if (isNullOnly(first)) {
44
57
  return mergeNullOnly(second);
@@ -46,7 +59,7 @@ export const mergeSchemasOrRefs = (first, second, getRef) => {
46
59
  if (isNullOnly(second)) {
47
60
  return mergeNullOnly(first);
48
61
  }
49
- return mergeSchemas(first, second, getRef);
62
+ return mergeSchemas({ first, second, getRef, system });
50
63
  };
51
64
  const containsAllOf = (schema) => {
52
65
  if (schema.allOf) {
@@ -90,48 +103,83 @@ const containsOneOf = (first, second) => {
90
103
  const containsRef = (first, second) => {
91
104
  return isRef(first) || isRef(second);
92
105
  };
93
- const mergeSchemas = (first, second, getRef) => {
106
+ /** Whether one member says `number` and the other `integer`. */
107
+ const isNumberAndInteger = (first, second) => (first.type === 'number' && second.type === 'integer') || (first.type === 'integer' && second.type === 'number');
108
+ const mergeSchemas = ({ first, second, getRef, system }) => {
109
+ // Every integer is a number, so a `number` merged with an `integer` is an
110
+ // `integer` with the constraints of both. Nothing contradicts.
111
+ if (isNumberAndInteger(first, second)) {
112
+ return mergeSchemas({ first: { ...first, type: 'integer' }, second: { ...second, type: 'integer' }, getRef, system });
113
+ }
114
+ if (system.allOf === 'latestWins') {
115
+ // The later member wins a contradiction: a type it disagrees with makes
116
+ // it the whole schema, and any other keyword it disagrees with is left
117
+ // out of the earlier member before they merge.
118
+ if (first.type && second.type && first.type !== second.type) {
119
+ system.replaced.add('type');
120
+ return second;
121
+ }
122
+ const earlier = withoutContradictions({ first, second, replaced: system.replaced });
123
+ return mergeChecked({ first: earlier, second, getRef, system });
124
+ }
125
+ return mergeChecked({ first, second, getRef, system });
126
+ };
127
+ const CONTRADICTIONS = [
128
+ { check: checkReadOnlyWriteOnlyConflicts, keywords: ['readOnly', 'writeOnly'] },
129
+ { check: checkFormatConflicts, keywords: ['format'] },
130
+ { check: checkEnumConflicts, keywords: ['enum'] },
131
+ { check: checkNumberConstraintsConflicts, keywords: ['minimum', 'maximum', 'exclusiveMinimum', 'exclusiveMaximum'] },
132
+ { check: checkArrayItemTypeConflicts, keywords: ['items'] }
133
+ ];
134
+ /** `first` without the keywords that contradict `second`, each named in `replaced`. */
135
+ const withoutContradictions = ({ first, second, replaced }) => CONTRADICTIONS.reduce((earlier, { check, keywords }) => {
94
136
  try {
95
- checkTypeConflicts(first, second);
137
+ check(earlier, second);
138
+ return earlier;
96
139
  }
97
- catch (e) {
98
- throw e;
140
+ catch {
141
+ const entries = Object.entries(earlier);
142
+ entries.filter(([key, value]) => keywords.includes(key) && value !== undefined).forEach(([key]) => replaced.add(key));
143
+ return Object.fromEntries(entries.filter(([key]) => !keywords.includes(key)));
99
144
  }
145
+ }, first);
146
+ const mergeChecked = ({ first, second, getRef, system }) => {
147
+ checkTypeConflicts(first, second);
100
148
  checkReadOnlyWriteOnlyConflicts(first, second);
101
149
  checkFormatConflicts(first, second);
102
150
  checkEnumConflicts(first, second);
103
151
  checkNumberConstraintsConflicts(first, second);
104
152
  checkArrayItemTypeConflicts(first, second);
105
- if (first.not || second.not) {
153
+ if ((first.not || second.not) && system.not !== 'unknown') {
106
154
  throw new Error('Merging schemas with "not" keyword is not supported');
107
155
  }
108
- return typedMerge(first, second, getRef);
156
+ return typedMerge({ first, second, getRef, system });
109
157
  };
110
- const typedMerge = (first, second, getRef) => {
158
+ const typedMerge = ({ first, second, getRef, system }) => {
111
159
  if (!first.type && !second.type) {
112
- return genericMerge(first, second, getRef);
160
+ return genericMerge({ first, second, getRef, system });
113
161
  }
114
162
  if (checkAtLeastOneTypeMatch(first, second, 'object')) {
115
- return mergeObjectConstraints(first, second, getRef);
163
+ return mergeObjectConstraints({ first, second, getRef, system });
116
164
  }
117
165
  if (checkAtLeastOneTypeMatch(first, second, 'array')) {
118
- return mergeArrayConstraints(first, second, getRef);
166
+ return mergeArrayConstraints({ first, second, getRef, system });
119
167
  }
120
168
  if (checkAtLeastOneTypeMatch(first, second, 'string')) {
121
- return mergeStringConstraints(first, second, getRef);
169
+ return mergeStringConstraints({ first, second, getRef, system });
122
170
  }
123
171
  if (checkAtLeastOneTypeMatch(first, second, 'number')) {
124
- return mergeNumberConstraints(first, second, getRef);
172
+ return mergeNumberConstraints({ first, second, getRef, system });
125
173
  }
126
174
  if (checkAtLeastOneTypeMatch(first, second, 'integer')) {
127
- return mergeIntegerConstraints(first, second, getRef);
175
+ return mergeIntegerConstraints({ first, second, getRef, system });
128
176
  }
129
177
  if (checkAtLeastOneTypeMatch(first, second, 'boolean')) {
130
- return mergeBooleanConstraints(first, second, getRef);
178
+ return mergeBooleanConstraints({ first, second, getRef, system });
131
179
  }
132
180
  throw new Error(`Cannot merge schemas with type "${first.type}" with type "${second.type}"`);
133
181
  };
134
- const mergeWithRef = (first, second, getRef) => {
182
+ const mergeWithRef = ({ first, second, getRef, system }) => {
135
183
  if (isRef(first) && isRef(second)) {
136
184
  if (first.$ref === second.$ref) {
137
185
  return {
@@ -140,15 +188,18 @@ const mergeWithRef = (first, second, getRef) => {
140
188
  };
141
189
  }
142
190
  else {
143
- return mergeSchemas(getRef(first), getRef(second), getRef);
191
+ return mergeSchemasOrRefs({ first: getRef(first), second: getRef(second), getRef, system });
144
192
  }
145
193
  }
194
+ // A target followed through its reference merges as any schema does: a
195
+ // `oneOf` or `anyOf` in either one is crossed with the other, not kept
196
+ // beside the merged properties.
146
197
  if (isRef(first) && !isRef(second)) {
147
- const merged = isEmpty(second) ? first : mergeSchemas(getRef(first), second, getRef);
198
+ const merged = isEmpty(second) ? first : mergeSchemasOrRefs({ first: getRef(first), second, getRef, system });
148
199
  return merged;
149
200
  }
150
201
  if (!isRef(first) && isRef(second)) {
151
- const merged = isEmpty(first) ? second : mergeSchemas(first, getRef(second), getRef);
202
+ const merged = isEmpty(first) ? second : mergeSchemasOrRefs({ first, second: getRef(second), getRef, system });
152
203
  return merged;
153
204
  }
154
205
  throw new Error('Invalid input');
@@ -1,3 +1,7 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
+ /**
3
+ * `schema`, nullable: a copy, as `schema` may be a component that other
4
+ * references share (a target followed through its reference).
5
+ */
2
6
  export declare const mergeNullOnly: (schema: OpenAPIV3.SchemaObject) => OpenAPIV3.SchemaObject;
3
7
  export declare const isNullOnly: (schema: OpenAPIV3.SchemaObject) => boolean;
@@ -1,11 +1,13 @@
1
1
  import { isEmpty } from '../../../helpers/isEmpty.js';
2
- export const mergeNullOnly = (schema) => {
3
- if (schema.enum && !schema.enum.includes(null)) {
4
- schema.enum.push(null);
5
- }
6
- schema.nullable = true;
7
- return schema;
8
- };
2
+ /**
3
+ * `schema`, nullable: a copy, as `schema` may be a component that other
4
+ * references share (a target followed through its reference).
5
+ */
6
+ export const mergeNullOnly = (schema) => ({
7
+ ...schema,
8
+ ...(schema.enum && !schema.enum.includes(null) ? { enum: [...schema.enum, null] } : {}),
9
+ nullable: true
10
+ });
9
11
  export const isNullOnly = (schema) => {
10
12
  const { type: _type, nullable, enum: enumValues, ...rest } = schema;
11
13
  return (Boolean(nullable) && enumValues?.length === 1 && enumValues[0] === null && isEmpty(rest ?? {}));
@@ -1,6 +1,28 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
2
  import * as v from 'valibot';
3
3
  export type GetRefFn = (ref: OpenAPIV3.ReferenceObject) => OpenAPIV3.SchemaObject;
4
+ /**
5
+ * The `system` settings as the merge reads them (`client.json#settings.system`),
6
+ * and the keywords a later `allOf` member replaced under `latestWins`, so
7
+ * the parser can name them in one warning for the schema.
8
+ */
9
+ export type MergeSystem = {
10
+ /** `strict`: a contradiction between members fails the merge. `latestWins`: the later member's keyword wins. */
11
+ allOf: 'strict' | 'latestWins';
12
+ /** `unknown`: a member with `not` merges, its `not` carried as written. Left out: `strict`, which refuses it. */
13
+ not?: 'strict' | 'unknown';
14
+ /**
15
+ * `client.json` `system.allOf`, kept while the first pass over a cross
16
+ * product's pairs sets `allOf` to `strict`. A member's own `allOf` merges
17
+ * under this setting in every pass. Left out: `allOf` is the setting.
18
+ */
19
+ setting?: 'strict' | 'latestWins';
20
+ replaced: Set<string>;
21
+ /** `unknown`: an `anyOf` of two or more members is any value, so it adds nothing to the merge. Left out: `union`. */
22
+ anyOf?: 'union' | 'unknown';
23
+ /** The keywords the merge read as any value: `anyOf` under `system.anyOf: unknown`. */
24
+ unknown?: Set<string>;
25
+ };
4
26
  export type OneOfObject = {
5
27
  oneOf?: (OpenAPIV3.ReferenceObject | OpenAPIV3.SchemaObject)[];
6
28
  } & OpenAPIV3.SchemaObject;
@@ -10,5 +32,16 @@ export type AnyOfObject = {
10
32
  export type SchemaObject = OpenAPIV3.SchemaObject;
11
33
  export type ReferenceObject = OpenAPIV3.ReferenceObject;
12
34
  export type SchemaOrReference = SchemaObject | ReferenceObject;
35
+ /** Two schemas to merge, how to follow a reference, and the `system` settings: what each merge step takes. */
36
+ export type MergeArgs<Schema = SchemaOrReference> = {
37
+ first: Schema;
38
+ second: Schema;
39
+ getRef: GetRefFn;
40
+ system: MergeSystem;
41
+ };
42
+ /** {@link MergeArgs}, and the valibot schema `default`, `enum` and `example` values must pass. */
43
+ export type GenericMergeArgs<T> = MergeArgs<SchemaObject> & {
44
+ typeCheck?: v.GenericSchema<T>;
45
+ };
13
46
  export type ArraySchemaObject = OpenAPIV3.ArraySchemaObject;
14
47
  export declare const IntegerSchema: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, "The number must be an integer.">]>;
@@ -117,13 +117,14 @@ export const toMediaTypeItemV3 = ({ mediaTypeItem, mediaType, stackTrail, contex
117
117
  mediaType,
118
118
  encoding,
119
119
  schema: stackTrail.trace('schema', st => toOptionalSchemaV3({ schema, stackTrail: st, context })),
120
- examples: stackTrail.trace('examples', st => toExamplesV3({
120
+ // toExamplesV3 traces `examples` (or `example`) itself.
121
+ examples: toExamplesV3({
121
122
  example,
122
123
  examples,
123
124
  exampleKey: mediaType,
124
- stackTrail: st,
125
+ stackTrail,
125
126
  context
126
- })),
127
+ }),
127
128
  extensionFields
128
129
  };
129
130
  return context.withStackTrail(stackTrail, () => new OasMediaType(fields, context));
@@ -101,13 +101,14 @@ const toParameterV3 = ({ parameter, stackTrail, context }) => {
101
101
  allowEmptyValue,
102
102
  allowReserved,
103
103
  schema: stackTrail.trace('schema', st => toOptionalSchemaV3({ schema, stackTrail: st, context })),
104
- examples: stackTrail.trace('examples', st => toExamplesV3({
104
+ // toExamplesV3 traces `examples` (or `example`) itself.
105
+ examples: toExamplesV3({
105
106
  examples,
106
107
  example,
107
108
  exampleKey: `${name}-${parsedLocation}`,
108
- stackTrail: st,
109
+ stackTrail,
109
110
  context
110
- })),
111
+ }),
111
112
  content: stackTrail.trace('content', st => toOptionalMediaTypeItemsV3({ content, stackTrail: st, context })),
112
113
  extensionFields
113
114
  };
@@ -1,4 +1,5 @@
1
1
  import type { OpenAPIV3_1 } from 'openapi-types';
2
+ import type { SiblingKeywords } from '../../../oas/schema/siblings.js';
2
3
  import type { OasRefData } from '../../../oas/ref/ref-types.js';
3
4
  import type { ParseContextType } from '../../../context/parseTypes.js';
4
5
  import { OasRef } from '../../../oas/ref/Ref.js';
@@ -14,6 +15,11 @@ type ToRefV31Args<T extends OasRefData['refType']> = {
14
15
  * reference; omitted everywhere else (a plain `$ref` is non-nullable).
15
16
  */
16
17
  nullable?: boolean;
18
+ /** Use-site `readOnly` and `writeOnly` (see `RefFields.readOnly`): from a one-member `allOf`. */
19
+ readOnly?: boolean;
20
+ writeOnly?: boolean;
21
+ /** The other keywords next to the reference in a one-member `allOf`, for `RefFields` (see `SiblingKeywords`). */
22
+ siblings?: SiblingKeywords;
17
23
  };
18
- export declare const toRefV31: <T extends OasRefData["refType"]>({ ref, refType, stackTrail, context, nullable }: ToRefV31Args<T>) => OasRef<T>;
24
+ export declare const toRefV31: <T extends OasRefData["refType"]>({ ref, refType, stackTrail, context, nullable, readOnly, writeOnly, siblings }: ToRefV31Args<T>) => OasRef<T>;
19
25
  export {};
@@ -1,10 +1,13 @@
1
1
  import { OasRef } from '../../../oas/ref/Ref.js';
2
2
  import { isEmpty } from '../../../helpers/isEmpty.js';
3
- export const toRefV31 = ({ ref, refType, stackTrail, context, nullable }) => {
3
+ export const toRefV31 = ({ ref, refType, stackTrail, context, nullable, readOnly, writeOnly, siblings }) => {
4
4
  const { $ref, ...skipped } = ref;
5
5
  if (!isEmpty(skipped)) {
6
6
  context.logSkippedFields({ skipped, parent: ref, parentType: 'ref', stackTrail });
7
7
  }
8
- context.registerRef(stackTrail.clone(), $ref);
9
- return context.withStackTrail(stackTrail, () => new OasRef({ refType, $ref, nullable }, context));
8
+ const oasRef = context.withStackTrail(stackTrail, () => new OasRef({ ...siblings, refType, $ref, nullable, readOnly, writeOnly }, context));
9
+ // The parse context checks each ref once the document is parsed, and
10
+ // removes what holds a ref that names nothing (`system.danglingRefs`).
11
+ context.registerOasRef(stackTrail.clone(), oasRef);
12
+ return oasRef;
10
13
  };
@@ -1,5 +1,7 @@
1
1
  import { toRefV31 } from '../ref/toRefV31.js';
2
2
  import { isRef } from '../../../helpers/refFns.js';
3
+ import { isEmpty } from '../../../helpers/isEmpty.js';
4
+ import { OasUnknown } from '../../../oas/unknown/Unknown.js';
3
5
  import { toArray } from '../array/toArray.js';
4
6
  import { toObject } from '../object/toObject.js';
5
7
  import { toInteger } from '../integer/toInteger.js';
@@ -9,9 +11,28 @@ import { toString } from '../string/toString.js';
9
11
  import { toUnknown } from '../unknown/toUnknown.js';
10
12
  import { toUnion } from '../union/toUnion.js';
11
13
  import { toGetRef } from '../../../helpers/refFns.js';
14
+ import { toSiblingKeywords } from '../../toSiblingKeywords.js';
15
+ import { logAllOfContradictions, toAllOfSystem } from '../../allOfSystem.js';
16
+ import { hasShapeKeyword, isUnknownAnyOf, logMergedUnknownAnyOf, logUnknownAnyOf, withoutUnknownAnyOf } from '../../anyOfSystem.js';
17
+ import { toAdditionalPropertiesV3 } from '../object/toAdditionalPropertiesV3.js';
12
18
  import { mergeIntersection } from '../_merge-all-of/merge-intersection.js';
13
19
  import { mergeUnion } from '../_merge-all-of/merge-union.js';
20
+ import { isNullOnly } from '../_merge-all-of/nullable-merge.js';
14
21
  import { tryParseAt } from '../../../context/tryParseAt.js';
22
+ /**
23
+ * `schema` without the members of its `oneOf` or `anyOf` that are 3.0's way to
24
+ * write null (`{ nullable: true, enum: [null] }`, which Cloudflare writes
25
+ * with `type: object` too), and nullable when it had one, as the 3.1 parser
26
+ * folds `{ type: 'null' }` (`partitionNullMember`). A union of null only is
27
+ * left as it is.
28
+ */
29
+ const withoutNullMembers = (schema, groupType) => {
30
+ const members = schema[groupType] ?? [];
31
+ const nonNull = members.filter(member => isRef(member) || !isNullOnly(member));
32
+ return nonNull.length === 0 || nonNull.length === members.length
33
+ ? schema
34
+ : { ...schema, [groupType]: nonNull, nullable: true };
35
+ };
15
36
  export const toSchemasV3 = ({ schemas, stackTrail, context }) => {
16
37
  const output = {};
17
38
  const entries = Object.entries(schemas);
@@ -75,11 +96,28 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
75
96
  }
76
97
  // OpenAPI `not` has no faithful TypeScript representation: a generated type
77
98
  // that ignored it would *widen* the contract (accepting shapes the schema
78
- // forbids). Refuse the schema rather than emit a type that lies. The throw
79
- // is isolated by `tryParseAt` into an `INVALID_SCHEMA` issue, and consumers
80
- // of this schema are pruned via `removeErroredItems` (INVALID_DEPENDENCY_REF).
99
+ // forbids). Under `client.json` `system.not: strict` (the default) the schema
100
+ // is refused rather than emit a type that lies. The throw is isolated by
101
+ // `tryParseAt` into an `INVALID_SCHEMA` issue, and consumers of this schema
102
+ // are pruned via `removeErroredItems` (INVALID_DEPENDENCY_REF).
103
+ //
104
+ // Under `system.not: unknown` the schema parses with its other keywords, and
105
+ // its `not` is kept as an `OasUnknown` that core does not read: a generator
106
+ // can see that the document says "not something".
81
107
  if ('not' in schema) {
82
- throw new Error('Schema uses unsupported "not" keyword');
108
+ // A test's mock context may have no `system`.
109
+ if (context.system?.not !== 'unknown') {
110
+ throw new Error('Schema uses unsupported "not" keyword');
111
+ }
112
+ const { not: _not, ...keywords } = schema;
113
+ const parsed = toSchemaV3({ schema: keywords, stackTrail, context });
114
+ // Only a one-member `allOf` of a `$ref` parses to a reference, and a
115
+ // reference has no field for a `not`. Fail rather than lose it.
116
+ if (parsed.isRef()) {
117
+ throw new Error('Schema uses "not" next to a one-member allOf reference, which cannot keep it');
118
+ }
119
+ parsed.not = stackTrail.trace('not', notTrail => context.withStackTrail(notTrail, () => new OasUnknown({}, context)));
120
+ return parsed;
83
121
  }
84
122
  if ('allOf' in schema && Array.isArray(schema.allOf)) {
85
123
  return stackTrail.trace('allOf', st => {
@@ -95,14 +133,40 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
95
133
  const members = allOf ?? [];
96
134
  if (members.length === 1) {
97
135
  const [member] = members;
98
- if (isRef(member) && value.nullable) {
99
- return toRefV31({
100
- ref: member,
101
- refType: 'schema',
102
- nullable: true,
103
- stackTrail: st,
104
- context
105
- });
136
+ // Keywords next to the one member say how this site uses the
137
+ // reference, which stays lazy, so a self-reference still ends:
138
+ // `nullable`, `readOnly` and `writeOnly` ride it as use-site flags,
139
+ // and the others are read without the target's type (`siblings`).
140
+ // `resolve()` applies them to a copy of the target at generate time;
141
+ // the ones its type cannot take are left out there. The shared model
142
+ // never changes.
143
+ if (isRef(member)) {
144
+ const { nullable, readOnly, writeOnly, ...keywords } = value;
145
+ const siblings = isEmpty(keywords)
146
+ ? undefined
147
+ : toSiblingKeywords({
148
+ keywords,
149
+ properties: stackTrail.trace('properties', propertiesTrail => toOptionalSchemasV3({ schemas: keywords.properties, stackTrail: propertiesTrail, context })),
150
+ additionalProperties: stackTrail.trace('additionalProperties', additionalTrail => toAdditionalPropertiesV3({
151
+ additionalProperties: keywords.additionalProperties,
152
+ stackTrail: additionalTrail,
153
+ context
154
+ })),
155
+ stackTrail,
156
+ context
157
+ });
158
+ if (nullable || readOnly || writeOnly || siblings) {
159
+ return toRefV31({
160
+ ref: member,
161
+ refType: 'schema',
162
+ nullable: nullable || undefined,
163
+ readOnly: readOnly || undefined,
164
+ writeOnly: writeOnly || undefined,
165
+ siblings,
166
+ stackTrail: st,
167
+ context
168
+ });
169
+ }
106
170
  }
107
171
  return toSchemaV3({
108
172
  schema: collapseSingleMember(value, member),
@@ -110,20 +174,29 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
110
174
  context
111
175
  });
112
176
  }
177
+ const system = toAllOfSystem(context);
113
178
  const merged = mergeIntersection({
114
179
  schema,
115
- getRef: toGetRef(context.documentObject)
180
+ getRef: toGetRef(context.documentObject),
181
+ system
116
182
  });
183
+ logAllOfContradictions({ system, stackTrail, parent: schema, context });
184
+ logMergedUnknownAnyOf({ system, stackTrail, parent: schema, context });
117
185
  return toSchemaV3({ schema: merged, stackTrail: st, context });
118
186
  });
119
187
  }
120
188
  if ('oneOf' in schema && Array.isArray(schema.oneOf)) {
121
189
  return stackTrail.trace('oneOf', st => {
190
+ const system = toAllOfSystem(context);
122
191
  const merged = mergeUnion({
123
- schema,
192
+ // A null member makes the union nullable: `oneOf: [$ref, null]` is a nullable reference.
193
+ schema: withoutNullMembers(schema, 'oneOf'),
124
194
  getRef: toGetRef(context.documentObject),
195
+ system,
125
196
  groupType: 'oneOf'
126
197
  });
198
+ logAllOfContradictions({ system, stackTrail, parent: schema, context });
199
+ logMergedUnknownAnyOf({ system, stackTrail, parent: schema, context });
127
200
  if (!('oneOf' in merged) || !Array.isArray(merged.oneOf)) {
128
201
  throw new Error('Missing "oneOf" array');
129
202
  }
@@ -161,6 +234,21 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
161
234
  });
162
235
  }
163
236
  if ('anyOf' in schema && Array.isArray(schema.anyOf)) {
237
+ // Under `system.anyOf: unknown`, as Cloudflare's `cf` reads it, an `anyOf`
238
+ // of two or more members is any value: the schema parses with its other
239
+ // keywords, so the properties next to it stay, without the members.
240
+ if (isUnknownAnyOf({ members: schema.anyOf, setting: context.system?.anyOf, getRef: toGetRef(context.documentObject) })) {
241
+ logUnknownAnyOf({ stackTrail, parent: schema, context });
242
+ const keywords = withoutUnknownAnyOf({
243
+ schema,
244
+ setting: context.system?.anyOf,
245
+ getRef: toGetRef(context.documentObject)
246
+ });
247
+ // A `default` alone is no type: the parser would guess one from it.
248
+ return hasShapeKeyword(keywords)
249
+ ? toSchemaV3({ schema: keywords, stackTrail, context })
250
+ : toUnknown({ value: keywords, stackTrail, context });
251
+ }
164
252
  return stackTrail.trace('anyOf', st => {
165
253
  // deno-lint-ignore ban-ts-comment
166
254
  // @ts-expect-error
@@ -168,11 +256,15 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
168
256
  const { anyOf, ...value } = schema;
169
257
  return toUnion({ value, members: anyOf, parentType: 'anyOf', stackTrail: st, context });
170
258
  }
259
+ const system = toAllOfSystem(context);
171
260
  const merged = mergeUnion({
172
- schema,
261
+ schema: withoutNullMembers(schema, 'anyOf'),
173
262
  getRef: toGetRef(context.documentObject),
263
+ system,
174
264
  groupType: 'anyOf'
175
265
  });
266
+ logAllOfContradictions({ system, stackTrail, parent: schema, context });
267
+ logMergedUnknownAnyOf({ system, stackTrail, parent: schema, context });
176
268
  if (!('anyOf' in merged) || !Array.isArray(merged.anyOf)) {
177
269
  throw new Error('Missing "anyOf" array');
178
270
  }
@@ -9,6 +9,12 @@ type DecomposeUnionReturn = {
9
9
  afterExcluded: SchemaObject;
10
10
  };
11
11
  export declare const decomposeUnion: ({ schema, groupType }: DecomposeUnionArgs) => DecomposeUnionReturn;
12
- /** Is `key` a union-level key, kept on the union rather than merged into each member? */
12
+ /**
13
+ * Is `key` a union-level key, kept on the union rather than merged into each
14
+ * member? A specification extension (`x-…`) is one too: it says something
15
+ * about the union, as Fern's `x-fern-property-name` renames the property,
16
+ * and `toUnion` keeps it. Merged into each member, it was lost, and each
17
+ * `$ref` member was resolved to merge it.
18
+ */
13
19
  export declare const isUnionLevelKey: (key: string) => boolean;
14
20
  export {};
@@ -56,8 +56,14 @@ const excludedProperties = [
56
56
  'writeOnly',
57
57
  'deprecated'
58
58
  ];
59
- /** Is `key` a union-level key, kept on the union rather than merged into each member? */
60
- export const isUnionLevelKey = (key) => excludedProperties.includes(key);
59
+ /**
60
+ * Is `key` a union-level key, kept on the union rather than merged into each
61
+ * member? A specification extension (`x-…`) is one too: it says something
62
+ * about the union, as Fern's `x-fern-property-name` renames the property,
63
+ * and `toUnion` keeps it. Merged into each member, it was lost, and each
64
+ * `$ref` member was resolved to merge it.
65
+ */
66
+ export const isUnionLevelKey = (key) => excludedProperties.includes(key) || key.startsWith('x-');
61
67
  const exclude = (entries) => {
62
68
  return entries.reduce((acc, [key, value]) => {
63
69
  if (isUnionLevelKey(key)) {
@@ -1,3 +1,2 @@
1
- import type { SchemaObject, GetRefFn, NormalizeFn } from './types.js';
2
- import type * as v from 'valibot';
3
- export declare const genericMerge: <T>(first: SchemaObject, second: SchemaObject, getRef: GetRefFn, normalize: NormalizeFn, typeCheck?: v.GenericSchema<T>) => SchemaObject;
1
+ import type { SchemaObject, GenericMergeArgs } from './types.js';
2
+ export declare const genericMerge: <T>({ first, second, getRef, normalize, system, typeCheck }: GenericMergeArgs<T>) => SchemaObject;
@@ -1,11 +1,11 @@
1
1
  import { mergeEnumValues } from './merge-enum-values.js';
2
2
  import { mergeProperties } from './merge-properties.js';
3
3
  import { mergeRequired } from './merge-required.js';
4
- export const genericMerge = (first, second, getRef, normalize, typeCheck) => {
4
+ export const genericMerge = ({ first, second, getRef, normalize, system, typeCheck }) => {
5
5
  return {
6
6
  ...first,
7
7
  ...second,
8
- ...mergeProperties(first, second, getRef, normalize),
8
+ ...mergeProperties({ first, second, getRef, normalize, system }),
9
9
  ...mergeRequired(first, second),
10
10
  ...mergeEnumValues(first, second, typeCheck)
11
11
  };
@@ -1,2 +1,3 @@
1
- import type { ArraySchemaObject, GetRefFn, NormalizeFn, SchemaObject } from './types.js';
2
- export declare function mergeArrayConstraints(first: ArraySchemaObject | SchemaObject, second: ArraySchemaObject | SchemaObject, getRef: GetRefFn, normalize: NormalizeFn): SchemaObject;
1
+ import type { MergeArgs } from './types.js';
2
+ import type { ArraySchemaObject, SchemaObject } from './types.js';
3
+ export declare function mergeArrayConstraints({ first, second, getRef, normalize, system }: MergeArgs<ArraySchemaObject | SchemaObject>): SchemaObject;
@@ -2,10 +2,10 @@ import { mergeSchemasOrRefs } from './merge.js';
2
2
  import { genericMerge } from './generic-merge.js';
3
3
  import * as v from 'valibot';
4
4
  import { checkTypeConflicts } from './check-type-conflicts.js';
5
- export function mergeArrayConstraints(first, second, getRef, normalize) {
5
+ export function mergeArrayConstraints({ first, second, getRef, normalize, system }) {
6
6
  checkTypeConflicts(first, second);
7
- const merged = genericMerge(first, second, getRef, normalize, v.array(v.any()));
8
- const items = mergeItems(first, second, getRef, normalize);
7
+ const merged = genericMerge({ first, second, getRef, normalize, system, typeCheck: v.array(v.any()) });
8
+ const items = mergeItems({ first, second, getRef, normalize, system });
9
9
  // With no `items` on either side, `items` stays absent (unknown items).
10
10
  const result = items === undefined ? merged : { ...merged, type: 'array', items };
11
11
  // Merge minItems
@@ -26,9 +26,9 @@ export function mergeArrayConstraints(first, second, getRef, normalize) {
26
26
  }
27
27
  return result;
28
28
  }
29
- const mergeItems = (first, second, getRef, normalize) => {
29
+ const mergeItems = ({ first, second, getRef, normalize, system }) => {
30
30
  if ('items' in first && 'items' in second && first.items && second.items) {
31
- return mergeSchemasOrRefs(first.items, second.items, getRef, normalize);
31
+ return mergeSchemasOrRefs({ first: first.items, second: second.items, getRef, normalize, system });
32
32
  }
33
33
  if ('items' in first && first.items) {
34
34
  return first.items;
@@ -1,3 +1,3 @@
1
1
  import type { OpenAPIV3 } from 'openapi-types';
2
- import type { GetRefFn, NormalizeFn } from './types.js';
3
- export declare function mergeBooleanConstraints(first: OpenAPIV3.SchemaObject, second: OpenAPIV3.SchemaObject, getRef: GetRefFn, normalize: NormalizeFn): OpenAPIV3.SchemaObject;
2
+ import type { MergeArgs } from './types.js';
3
+ export declare function mergeBooleanConstraints({ first, second, getRef, normalize, system }: MergeArgs<OpenAPIV3.SchemaObject>): OpenAPIV3.SchemaObject;
@@ -1,7 +1,7 @@
1
1
  import { genericMerge } from './generic-merge.js';
2
2
  import * as v from 'valibot';
3
3
  import { checkTypeConflicts } from './check-type-conflicts.js';
4
- export function mergeBooleanConstraints(first, second, getRef, normalize) {
4
+ export function mergeBooleanConstraints({ first, second, getRef, normalize, system }) {
5
5
  checkTypeConflicts(first, second);
6
- return genericMerge(first, second, getRef, normalize, v.boolean());
6
+ return genericMerge({ first, second, getRef, normalize, system, typeCheck: v.boolean() });
7
7
  }