@skmtc/core 0.45.0 → 0.47.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 (187) hide show
  1. package/esm/anchors/attribute.js +3 -2
  2. package/esm/context/CoreContext.d.ts +1 -1
  3. package/esm/context/CoreContext.js +1 -1
  4. package/esm/context/GenerateContext.d.ts +13 -10
  5. package/esm/context/GenerateContext.js +36 -25
  6. package/esm/context/ParseContext.d.ts +3 -0
  7. package/esm/context/ParseContext.js +151 -39
  8. package/esm/context/generateTypes.d.ts +7 -6
  9. package/esm/dsl/GeneratorKeys.d.ts +21 -15
  10. package/esm/dsl/GeneratorKeys.js +16 -11
  11. package/esm/dsl/Inserted.d.ts +1 -1
  12. package/esm/dsl/Inserted.js +1 -1
  13. package/esm/dsl/model/ModelDriver.d.ts +6 -5
  14. package/esm/dsl/model/ModelDriver.js +22 -20
  15. package/esm/dsl/model/toModelEntry.d.ts +18 -18
  16. package/esm/dsl/model/toModelEntry.js +9 -9
  17. package/esm/dsl/model/toModelProjectionBase.d.ts +17 -16
  18. package/esm/dsl/model/toModelProjectionBase.js +12 -8
  19. package/esm/dsl/model/types.d.ts +26 -17
  20. package/esm/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
  21. package/esm/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
  22. package/esm/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
  23. package/esm/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
  24. package/esm/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
  25. package/esm/dsl/webhook/toWebhookProjectionBase.js +2 -2
  26. package/esm/helpers/collateExamples.js +35 -17
  27. package/esm/helpers/refFns.d.ts +108 -43
  28. package/esm/helpers/refFns.js +166 -57
  29. package/esm/mod.d.ts +1 -0
  30. package/esm/mod.js +1 -0
  31. package/esm/oas/document/Document.d.ts +6 -0
  32. package/esm/oas/document/Document.js +44 -2
  33. package/esm/oas/intersection/Intersection.d.ts +122 -0
  34. package/esm/oas/intersection/Intersection.js +266 -0
  35. package/esm/oas/mediaType/jsonMediaType.d.ts +1 -1
  36. package/esm/oas/mediaType/jsonMediaType.js +3 -3
  37. package/esm/oas/ref/DanglingRefError.d.ts +5 -2
  38. package/esm/oas/ref/DanglingRefError.js +4 -3
  39. package/esm/oas/ref/Ref.d.ts +23 -12
  40. package/esm/oas/ref/Ref.js +68 -72
  41. package/esm/oas/requestBody/RequestBody.d.ts +1 -1
  42. package/esm/oas/requestBody/RequestBody.js +1 -1
  43. package/esm/oas/response/Response.d.ts +1 -1
  44. package/esm/oas/response/Response.js +1 -1
  45. package/esm/oas/schema/Schema.d.ts +4 -2
  46. package/esm/oas/schema/siblings.d.ts +10 -2
  47. package/esm/oas/schema/siblings.js +87 -22
  48. package/esm/oas/schemaPath/traverseSchema.d.ts +2 -0
  49. package/esm/oas/schemaPath/traverseSchema.js +51 -5
  50. package/esm/parse/allOfSystem.d.ts +3 -0
  51. package/esm/parse/allOfSystem.js +2 -1
  52. package/esm/parse/keptIntersection.d.ts +53 -0
  53. package/esm/parse/keptIntersection.js +155 -0
  54. package/esm/parse/keptRefs.d.ts +23 -0
  55. package/esm/parse/keptRefs.js +59 -0
  56. package/esm/parse/toCyclicRefs.d.ts +8 -0
  57. package/esm/parse/toCyclicRefs.js +126 -0
  58. package/esm/parse/toDeclaredTypes.d.ts +20 -0
  59. package/esm/parse/toDeclaredTypes.js +43 -0
  60. package/esm/parse/v3-0/_merge-all-of/merge-intersection.js +8 -4
  61. package/esm/parse/v3-0/_merge-all-of/merge-union.js +7 -1
  62. package/esm/parse/v3-0/_merge-all-of/merge.js +13 -0
  63. package/esm/parse/v3-0/_merge-all-of/types.d.ts +3 -0
  64. package/esm/parse/v3-0/intersection/toIntersection.d.ts +12 -0
  65. package/esm/parse/v3-0/intersection/toIntersection.js +61 -0
  66. package/esm/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
  67. package/esm/parse/v3-0/ref/toRefTargetV3.js +70 -0
  68. package/esm/parse/v3-0/schema/toSchemasV3.js +13 -1
  69. package/esm/parse/v3-1/_merge-all-of/merge-intersection.js +8 -4
  70. package/esm/parse/v3-1/_merge-all-of/merge-union.js +7 -1
  71. package/esm/parse/v3-1/_merge-all-of/merge.js +13 -0
  72. package/esm/parse/v3-1/_merge-all-of/types.d.ts +3 -0
  73. package/esm/parse/v3-1/intersection/toIntersection.d.ts +12 -0
  74. package/esm/parse/v3-1/intersection/toIntersection.js +61 -0
  75. package/esm/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
  76. package/esm/parse/v3-1/ref/toRefTargetV3.js +70 -0
  77. package/esm/parse/v3-1/schema/toSchemasV3.js +15 -2
  78. package/esm/parse/v3-2/_merge-all-of/merge-intersection.js +8 -4
  79. package/esm/parse/v3-2/_merge-all-of/merge-union.js +7 -1
  80. package/esm/parse/v3-2/_merge-all-of/merge.js +13 -0
  81. package/esm/parse/v3-2/_merge-all-of/types.d.ts +3 -0
  82. package/esm/parse/v3-2/intersection/toIntersection.d.ts +12 -0
  83. package/esm/parse/v3-2/intersection/toIntersection.js +61 -0
  84. package/esm/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
  85. package/esm/parse/v3-2/ref/toRefTargetV3.js +70 -0
  86. package/esm/parse/v3-2/schema/toSchemasV3.js +15 -2
  87. package/esm/types/GeneratorType.d.ts +1 -1
  88. package/esm/types/ProjectionOptions.d.ts +1 -1
  89. package/esm/types/ProjectionOptions.js +1 -1
  90. package/esm/types/RefName.d.ts +3 -3
  91. package/esm/types/Settings.d.ts +9 -0
  92. package/esm/types/Settings.js +2 -1
  93. package/esm/types/TypeSystem.d.ts +20 -5
  94. package/package.json +1 -1
  95. package/script/anchors/attribute.js +3 -2
  96. package/script/context/CoreContext.d.ts +1 -1
  97. package/script/context/CoreContext.js +1 -1
  98. package/script/context/GenerateContext.d.ts +13 -10
  99. package/script/context/GenerateContext.js +36 -25
  100. package/script/context/ParseContext.d.ts +3 -0
  101. package/script/context/ParseContext.js +150 -38
  102. package/script/context/generateTypes.d.ts +7 -6
  103. package/script/dsl/GeneratorKeys.d.ts +21 -15
  104. package/script/dsl/GeneratorKeys.js +16 -11
  105. package/script/dsl/Inserted.d.ts +1 -1
  106. package/script/dsl/Inserted.js +1 -1
  107. package/script/dsl/model/ModelDriver.d.ts +6 -5
  108. package/script/dsl/model/ModelDriver.js +22 -20
  109. package/script/dsl/model/toModelEntry.d.ts +18 -18
  110. package/script/dsl/model/toModelEntry.js +9 -9
  111. package/script/dsl/model/toModelProjectionBase.d.ts +17 -16
  112. package/script/dsl/model/toModelProjectionBase.js +12 -8
  113. package/script/dsl/model/types.d.ts +26 -17
  114. package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
  115. package/script/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
  116. package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
  117. package/script/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
  118. package/script/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
  119. package/script/dsl/webhook/toWebhookProjectionBase.js +2 -2
  120. package/script/helpers/collateExamples.js +35 -17
  121. package/script/helpers/refFns.d.ts +108 -43
  122. package/script/helpers/refFns.js +180 -59
  123. package/script/mod.d.ts +1 -0
  124. package/script/mod.js +1 -0
  125. package/script/oas/document/Document.d.ts +6 -0
  126. package/script/oas/document/Document.js +44 -2
  127. package/script/oas/intersection/Intersection.d.ts +122 -0
  128. package/script/oas/intersection/Intersection.js +270 -0
  129. package/script/oas/mediaType/jsonMediaType.d.ts +1 -1
  130. package/script/oas/mediaType/jsonMediaType.js +3 -3
  131. package/script/oas/ref/DanglingRefError.d.ts +5 -2
  132. package/script/oas/ref/DanglingRefError.js +4 -3
  133. package/script/oas/ref/Ref.d.ts +23 -12
  134. package/script/oas/ref/Ref.js +67 -71
  135. package/script/oas/requestBody/RequestBody.d.ts +1 -1
  136. package/script/oas/requestBody/RequestBody.js +1 -1
  137. package/script/oas/response/Response.d.ts +1 -1
  138. package/script/oas/response/Response.js +1 -1
  139. package/script/oas/schema/Schema.d.ts +4 -2
  140. package/script/oas/schema/siblings.d.ts +10 -2
  141. package/script/oas/schema/siblings.js +89 -23
  142. package/script/oas/schemaPath/traverseSchema.d.ts +2 -0
  143. package/script/oas/schemaPath/traverseSchema.js +50 -4
  144. package/script/parse/allOfSystem.d.ts +3 -0
  145. package/script/parse/allOfSystem.js +2 -1
  146. package/script/parse/keptIntersection.d.ts +53 -0
  147. package/script/parse/keptIntersection.js +164 -0
  148. package/script/parse/keptRefs.d.ts +23 -0
  149. package/script/parse/keptRefs.js +63 -0
  150. package/script/parse/toCyclicRefs.d.ts +8 -0
  151. package/script/parse/toCyclicRefs.js +130 -0
  152. package/script/parse/toDeclaredTypes.d.ts +20 -0
  153. package/script/parse/toDeclaredTypes.js +48 -0
  154. package/script/parse/v3-0/_merge-all-of/merge-intersection.js +8 -4
  155. package/script/parse/v3-0/_merge-all-of/merge-union.js +7 -1
  156. package/script/parse/v3-0/_merge-all-of/merge.js +13 -0
  157. package/script/parse/v3-0/_merge-all-of/types.d.ts +3 -0
  158. package/script/parse/v3-0/intersection/toIntersection.d.ts +12 -0
  159. package/script/parse/v3-0/intersection/toIntersection.js +65 -0
  160. package/script/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
  161. package/script/parse/v3-0/ref/toRefTargetV3.js +74 -0
  162. package/script/parse/v3-0/schema/toSchemasV3.js +13 -1
  163. package/script/parse/v3-1/_merge-all-of/merge-intersection.js +8 -4
  164. package/script/parse/v3-1/_merge-all-of/merge-union.js +7 -1
  165. package/script/parse/v3-1/_merge-all-of/merge.js +13 -0
  166. package/script/parse/v3-1/_merge-all-of/types.d.ts +3 -0
  167. package/script/parse/v3-1/intersection/toIntersection.d.ts +12 -0
  168. package/script/parse/v3-1/intersection/toIntersection.js +65 -0
  169. package/script/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
  170. package/script/parse/v3-1/ref/toRefTargetV3.js +74 -0
  171. package/script/parse/v3-1/schema/toSchemasV3.js +15 -2
  172. package/script/parse/v3-2/_merge-all-of/merge-intersection.js +8 -4
  173. package/script/parse/v3-2/_merge-all-of/merge-union.js +7 -1
  174. package/script/parse/v3-2/_merge-all-of/merge.js +13 -0
  175. package/script/parse/v3-2/_merge-all-of/types.d.ts +3 -0
  176. package/script/parse/v3-2/intersection/toIntersection.d.ts +12 -0
  177. package/script/parse/v3-2/intersection/toIntersection.js +65 -0
  178. package/script/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
  179. package/script/parse/v3-2/ref/toRefTargetV3.js +74 -0
  180. package/script/parse/v3-2/schema/toSchemasV3.js +15 -2
  181. package/script/types/GeneratorType.d.ts +1 -1
  182. package/script/types/ProjectionOptions.d.ts +1 -1
  183. package/script/types/ProjectionOptions.js +1 -1
  184. package/script/types/RefName.d.ts +3 -3
  185. package/script/types/Settings.d.ts +9 -0
  186. package/script/types/Settings.js +2 -1
  187. package/script/types/TypeSystem.d.ts +20 -5
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toIntersection = void 0;
4
+ const Intersection_js_1 = require("../../../oas/intersection/Intersection.js");
5
+ const refFns_js_1 = require("../../../helpers/refFns.js");
6
+ const anyOfSystem_js_1 = require("../../anyOfSystem.js");
7
+ const keptIntersection_js_1 = require("../../keptIntersection.js");
8
+ const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
9
+ const toUnknown_js_1 = require("../unknown/toUnknown.js");
10
+ const toSpecificationExtensionsV3_js_1 = require("../specificationExtensions/toSpecificationExtensionsV3.js");
11
+ const parseNullable_js_1 = require("../_helpers/parseNullable.js");
12
+ const parseExample_js_1 = require("../_helpers/parseExample.js");
13
+ const parseDefault_js_1 = require("../_helpers/parseDefault.js");
14
+ const toExternalDocs_js_1 = require("../externalDocs/toExternalDocs.js");
15
+ const toIntersection = ({ value, members, stackTrail, context }) => {
16
+ const { nullable, value: valueWithoutNullable } = (0, parseNullable_js_1.parseNullable)({ value, context, stackTrail });
17
+ const { title, description, externalDocs, readOnly, writeOnly, deprecated, example: unparsedExample, default: unparsedDefaultValue, ...skipped } = valueWithoutNullable;
18
+ const example = (0, parseExample_js_1.parseExample)({
19
+ value: unparsedExample,
20
+ context,
21
+ parent: value,
22
+ nullable,
23
+ check: isPresent,
24
+ toMessage: item => `Removed invalid example. Expected a non-null value, got: ${item}`,
25
+ stackTrail
26
+ });
27
+ const defaultValue = (0, parseDefault_js_1.parseDefault)({
28
+ value: unparsedDefaultValue,
29
+ context,
30
+ parent: value,
31
+ nullable,
32
+ check: isPresent,
33
+ toMessage: item => `Removed invalid default. Expected a non-null value, got: ${item}`,
34
+ stackTrail
35
+ });
36
+ const extensionFields = (0, toSpecificationExtensionsV3_js_1.toSpecificationExtensionsV3)({
37
+ skipped,
38
+ parent: value,
39
+ context,
40
+ stackTrail,
41
+ parentType: 'schema:allOf'
42
+ });
43
+ // A member with no shape of its own (`{ description }`) is any value: the
44
+ // parser must not guess a type from its `example`.
45
+ const membersParsed = members.map(keptIntersection_js_1.withKeywordType).map((member, index) => stackTrail.trace(`${index}`, st => (0, refFns_js_1.isRef)(member) || (0, anyOfSystem_js_1.hasShapeKeyword)(member) || 'anyOf' in member || 'not' in member
46
+ ? (0, toSchemasV3_js_1.toSchemaV3)({ schema: member, stackTrail: st, context })
47
+ : (0, toUnknown_js_1.toUnknown)({ value: member, stackTrail: st, context })));
48
+ return context.withStackTrail(stackTrail, () => new Intersection_js_1.OasIntersection({
49
+ title,
50
+ description,
51
+ externalDocs: stackTrail.trace('externalDocs', st => (0, toExternalDocs_js_1.toExternalDocs)({ externalDocs, stackTrail: st, context })),
52
+ nullable,
53
+ readOnly,
54
+ writeOnly,
55
+ deprecated,
56
+ default: defaultValue,
57
+ members: membersParsed,
58
+ example,
59
+ extensionFields
60
+ }, context));
61
+ };
62
+ exports.toIntersection = toIntersection;
63
+ // A value matches every member, so without resolving them the most we can
64
+ // check is that a present default/example is not `null` on a non-nullable schema.
65
+ const isPresent = (value) => value !== null && value !== undefined;
@@ -0,0 +1,23 @@
1
+ import type { ParseContextType } from '../../../context/parseTypes.js';
2
+ import type { StackTrail } from '../../../context/StackTrail.js';
3
+ import type { ComponentsEntry } from '../../../oas/components/Components.js';
4
+ import type { OasRefData } from '../../../oas/ref/ref-types.js';
5
+ /** What {@link toRefTargetV3} parses. */
6
+ export type ToRefTargetArgs = {
7
+ /** The kind of component the ref is written for. */
8
+ refType: OasRefData['refType'];
9
+ /** The last segment of the target's pointer, unescaped: the key it parses under. */
10
+ name: string;
11
+ /** The raw value at the pointer. */
12
+ value: Record<string, unknown>;
13
+ /** The trail of the target's parent, so the target parses at its own position. */
14
+ stackTrail: StackTrail;
15
+ context: ParseContextType;
16
+ };
17
+ /**
18
+ * Parses the target of a ref that does not point at a component
19
+ * (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
20
+ * at its own position, with the parser that components of its kind use. Gives
21
+ * `undefined` when the target does not parse (the parser has logged why).
22
+ */
23
+ export declare const toRefTargetV3: ({ refType, name, value, stackTrail, context }: ToRefTargetArgs) => ComponentsEntry | undefined;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toRefTargetV3 = void 0;
4
+ const isPlainObject_js_1 = require("../../isPlainObject.js");
5
+ const toSchemasV3_js_1 = require("../schema/toSchemasV3.js");
6
+ const toParameterV3_js_1 = require("../parameter/toParameterV3.js");
7
+ const toResponseV3_js_1 = require("../response/toResponseV3.js");
8
+ const toRequestBodiesV3_js_1 = require("../requestBody/toRequestBodiesV3.js");
9
+ const toHeadersV3_js_1 = require("../header/toHeadersV3.js");
10
+ const toLinksV3_js_1 = require("../link/toLinksV3.js");
11
+ const toExamplesV3_js_1 = require("../example/toExamplesV3.js");
12
+ const toSecuritySchemes_js_1 = require("../securitySchemes/toSecuritySchemes.js");
13
+ const tryParseAt_js_1 = require("../../../context/tryParseAt.js");
14
+ /**
15
+ * The raw value read as the OpenAPI type its parser takes, as the components
16
+ * parser reads `documentObject.components`: the parser checks what it reads.
17
+ */
18
+ const isRawEntry = (value) => (0, isPlainObject_js_1.isPlainObject)(value);
19
+ /**
20
+ * Parses the target of a ref that does not point at a component
21
+ * (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
22
+ * at its own position, with the parser that components of its kind use. Gives
23
+ * `undefined` when the target does not parse (the parser has logged why).
24
+ */
25
+ const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
26
+ switch (refType) {
27
+ case 'schema':
28
+ return isRawEntry(value)
29
+ ? (0, toSchemasV3_js_1.toOptionalSchemasV3)({ schemas: { [name]: value }, stackTrail, context })?.[name]
30
+ : undefined;
31
+ case 'parameter':
32
+ return isRawEntry(value)
33
+ ? (0, toParameterV3_js_1.toOptionalParametersV3)({ parameters: { [name]: value }, stackTrail, context })?.[name]
34
+ : undefined;
35
+ case 'response':
36
+ return isRawEntry(value)
37
+ ? (0, toResponseV3_js_1.toOptionalResponsesV3)({ responses: { [name]: value }, stackTrail, context })?.[name]
38
+ : undefined;
39
+ case 'requestBody':
40
+ return isRawEntry(value)
41
+ ? (0, toRequestBodiesV3_js_1.toRequestBodiesV3)({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
42
+ : undefined;
43
+ case 'header':
44
+ return isRawEntry(value)
45
+ ? (0, toHeadersV3_js_1.toComponentHeadersV3)({ headers: { [name]: value }, stackTrail, context })?.[name]
46
+ : undefined;
47
+ case 'link':
48
+ return isRawEntry(value)
49
+ ? (0, toLinksV3_js_1.toLinksV3)({ links: { [name]: value }, stackTrail, context })?.[name]
50
+ : undefined;
51
+ case 'example':
52
+ // No components parser reads a single example by key, so the target
53
+ // is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
54
+ return isRawEntry(value)
55
+ ? (0, tryParseAt_js_1.tryParseAt)({
56
+ stackTrail,
57
+ key: name,
58
+ context,
59
+ type: 'INVALID_EXAMPLE',
60
+ parent: value,
61
+ fn: st => (0, toExamplesV3_js_1.toExampleV3)({ example: value, stackTrail: st, context })
62
+ })
63
+ : undefined;
64
+ case 'securityScheme':
65
+ return isRawEntry(value)
66
+ ? (0, toSecuritySchemes_js_1.toSecuritySchemesV3)({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
67
+ : undefined;
68
+ default: {
69
+ const _exhaustive = refType;
70
+ throw new Error(`Unhandled ref type: ${_exhaustive}`);
71
+ }
72
+ }
73
+ };
74
+ exports.toRefTargetV3 = toRefTargetV3;
@@ -13,6 +13,8 @@ const toBoolean_js_1 = require("../boolean/toBoolean.js");
13
13
  const toString_js_1 = require("../string/toString.js");
14
14
  const toUnknown_js_1 = require("../unknown/toUnknown.js");
15
15
  const toUnion_js_1 = require("../union/toUnion.js");
16
+ const toIntersection_js_1 = require("../intersection/toIntersection.js");
17
+ const keptIntersection_js_1 = require("../../keptIntersection.js");
16
18
  const refFns_js_2 = require("../../../helpers/refFns.js");
17
19
  const toSiblingKeywords_js_1 = require("../../toSiblingKeywords.js");
18
20
  const allOfSystem_js_1 = require("../../allOfSystem.js");
@@ -137,8 +139,9 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
137
139
  });
138
140
  }
139
141
  const members = Array.isArray(allOf) ? allOf : [];
142
+ const bareRef = context.keptRefs?.copy(schema, { $ref }) ?? { $ref };
140
143
  return Object.keys(keywords).length > 0
141
- ? (0, exports.toSchemaV3)({ schema: { ...keywords, allOf: [{ $ref }, ...members] }, stackTrail, context })
144
+ ? (0, exports.toSchemaV3)({ schema: { ...keywords, allOf: [bareRef, ...members] }, stackTrail, context })
142
145
  : (0, toRefV31_js_1.toRefV31)({ ref: schema, refType: 'schema', stackTrail, context });
143
146
  }
144
147
  // OpenAPI `not` has no faithful TypeScript representation: a generated type
@@ -240,7 +243,17 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
240
243
  });
241
244
  (0, allOfSystem_js_1.logAllOfContradictions)({ system, stackTrail, parent: schema, context });
242
245
  (0, anyOfSystem_js_1.logMergedUnknownAnyOf)({ system, stackTrail, parent: schema, context });
243
- return (0, exports.toSchemaV3)({ schema: merged, stackTrail: st, context });
246
+ const parts = system.keptRefs && (0, keptIntersection_js_1.toIntersectionParts)(merged, system.keptRefs);
247
+ if (parts === undefined) {
248
+ return (0, exports.toSchemaV3)({ schema: merged, stackTrail: st, context });
249
+ }
250
+ const { own, members: kept } = (0, keptIntersection_js_1.toSiteIntersection)(parts);
251
+ const [only] = kept;
252
+ if (kept.length > 1 || only === undefined) {
253
+ return (0, toIntersection_js_1.toIntersection)({ value: own, members: kept, stackTrail: st, context });
254
+ }
255
+ // An intersection of one ref is that ref with the keywords beside it.
256
+ return (0, exports.toSchemaV3)({ schema: (0, isEmpty_js_1.isEmpty)(own) ? only : { ...own, allOf: [only] }, stackTrail: st, context });
244
257
  });
245
258
  }
246
259
  // A `oneOf`/`anyOf` of only null members reads as nullable, not as an
@@ -43,7 +43,7 @@ import type { ModelEntry } from '../dsl/model/toModelEntry.js';
43
43
  *
44
44
  * const modelEntry = toModelEntry({
45
45
  * id: 'typescript-models',
46
- * transform: ({ context, refName }) => {}
46
+ * transform: ({ context, ref }) => {}
47
47
  * });
48
48
  * // modelEntry.type === 'model'
49
49
  * ```
@@ -2,7 +2,7 @@
2
2
  * @fileoverview Caller options for projections.
3
3
  *
4
4
  * Options are typed data the CALLING generator passes when it inserts a
5
- * peer: `context.insertModel(Peer, refName, { options })`. Enrichments are
5
+ * peer: `context.insertModel(Peer, ref, { options })`. Enrichments are
6
6
  * the user's per-subject configuration and a variant selects one of them;
7
7
  * options belong to the caller.
8
8
  *
@@ -3,7 +3,7 @@
3
3
  * @fileoverview Caller options for projections.
4
4
  *
5
5
  * Options are typed data the CALLING generator passes when it inserts a
6
- * peer: `context.insertModel(Peer, refName, { options })`. Enrichments are
6
+ * peer: `context.insertModel(Peer, ref, { options })`. Enrichments are
7
7
  * the user's per-subject configuration and a variant selects one of them;
8
8
  * options belong to the caller.
9
9
  *
@@ -99,14 +99,14 @@ import type { Brand } from './Brand.js';
99
99
  * @example In generator contexts
100
100
  * ```typescript
101
101
  * class ModelGenerator extends ModelProjectionBase {
102
- * constructor(args: { refName: RefName; ... }) {
102
+ * constructor(args: { ref: RefParts; ... }) {
103
103
  * super(args);
104
- * // this.refName is guaranteed to be a valid schema reference
104
+ * // this.ref.refName is the name of the model's ref
105
105
  * }
106
106
  *
107
107
  * toDefinition(): Definition {
108
108
  * // RefName ensures we're working with valid schema identifiers
109
- * const schemaName = this.refName; // Type: RefName
109
+ * const schemaName = this.ref.refName; // Type: RefName
110
110
  * return new Definition({
111
111
  * identifier: createType(schemaName),
112
112
  * // ...
@@ -470,6 +470,15 @@ export type SystemSettings = {
470
470
  * default, `[]`, lists none.
471
471
  */
472
472
  danglingRefs?: DanglingRefKind[];
473
+ /**
474
+ * The `$ref`s that stay refs where core would merge their target in: the
475
+ * members of an `allOf`, and the members of a `oneOf` or `anyOf` with a
476
+ * keyword beside it that merges into each member. The schema is then an
477
+ * `OasIntersection` of the refs and one schema that the other members merge
478
+ * into. `cycles` (the default): a `$ref` whose target leads back to the
479
+ * schema that holds it. `all`: each one. `merge`: none.
480
+ */
481
+ intersections?: 'merge' | 'cycles' | 'all';
473
482
  };
474
483
  export type ClientSettings = {
475
484
  /** Base output path for generated files */
@@ -228,7 +228,8 @@ exports.systemSettings = v.object({
228
228
  responseContradictions: v.optional(v.picklist(['strict', 'unknown'])),
229
229
  not: v.optional(v.picklist(['strict', 'unknown'])),
230
230
  anyOf: v.optional(v.picklist(['union', 'unknown'])),
231
- danglingRefs: v.optional(v.array(v.picklist(exports.danglingRefKinds)))
231
+ danglingRefs: v.optional(v.array(v.picklist(exports.danglingRefKinds))),
232
+ intersections: v.optional(v.picklist(['merge', 'cycles', 'all']))
232
233
  });
233
234
  exports.clientSettings = v.object({
234
235
  basePath: v.optional(v.pipe(v.string(), v.check(basePath => !(0, normalizeWorkspacePath_js_1.isAbsolutePath)(basePath), 'basePath must be relative to the SKMTC root (the directory containing .skmtc/); ' +
@@ -7,7 +7,7 @@ import type { GenerateContextType } from '../context/generateTypes.js';
7
7
  import type { CustomValue } from '../dsl/CustomValue.js';
8
8
  import type { OasVoid } from '../oas/void/Void.js';
9
9
  import type { GeneratorKey } from '../dsl/GeneratorKeys.js';
10
- import type { RefName } from './RefName.js';
10
+ import type { RefParts } from '../helpers/refFns.js';
11
11
  /**
12
12
  * Union type representing all possible type system values in the SKMTC code generation system.
13
13
  *
@@ -19,7 +19,7 @@ import type { RefName } from './RefName.js';
19
19
  * ## Type Categories
20
20
  *
21
21
  * - **Primitive Types**: `string`, `number`, `integer`, `boolean`, `null`
22
- * - **Complex Types**: `array`, `object`, `union`
22
+ * - **Complex Types**: `array`, `object`, `union`, `intersection`
23
23
  * - **Special Types**: `void`, `never`, `unknown`, `custom`
24
24
  * - **Reference Types**: `ref` for schema references
25
25
  *
@@ -63,7 +63,7 @@ import type { RefName } from './RefName.js';
63
63
  * }
64
64
  * ```
65
65
  */
66
- export type TypeSystemValue = TypeSystemArray | TypeSystemObject | TypeSystemUnion | TypeSystemString | TypeSystemNumber | TypeSystemInteger | TypeSystemBoolean | TypeSystemUnknown | TypeSystemVoid | TypeSystemNever | TypeSystemRef | TypeSystemNull | TypeSystemCustom;
66
+ export type TypeSystemValue = TypeSystemArray | TypeSystemObject | TypeSystemUnion | TypeSystemIntersection | TypeSystemString | TypeSystemNumber | TypeSystemInteger | TypeSystemBoolean | TypeSystemUnknown | TypeSystemVoid | TypeSystemNever | TypeSystemRef | TypeSystemNull | TypeSystemCustom;
67
67
  /**
68
68
  * Type system representation of a reference to another schema.
69
69
  *
@@ -360,6 +360,17 @@ export type TypeSystemUnion = {
360
360
  /** Optional generator-specific key for tracking */
361
361
  generatorKey?: GeneratorKey;
362
362
  };
363
+ /** Type system representation of an intersection: a value that is of every member's type. */
364
+ export type TypeSystemIntersection = {
365
+ /** Discriminator for the intersection type */
366
+ type: 'intersection';
367
+ /** The types a value has all of */
368
+ members: TypeSystemValue[];
369
+ /** Type modifiers (optional, nullable, etc.) */
370
+ modifiers: Modifiers;
371
+ /** Optional generator-specific key for tracking */
372
+ generatorKey?: GeneratorKey;
373
+ };
363
374
  /**
364
375
  * Type system representation of object types.
365
376
  *
@@ -464,6 +475,10 @@ export type SchemaToTypeSystemMap = {
464
475
  source: OasSchema;
465
476
  output: TypeSystemUnion;
466
477
  };
478
+ intersection: {
479
+ source: OasSchema;
480
+ output: TypeSystemIntersection;
481
+ };
467
482
  custom: {
468
483
  source: CustomValue;
469
484
  output: TypeSystemCustom;
@@ -539,8 +554,8 @@ export type TypeSystemArgs<Schema extends SchemaType> = {
539
554
  destinationPath: string;
540
555
  /** The schema to transform */
541
556
  schema: Schema;
542
- /** Optional root reference name for schema references */
543
- rootRef?: RefName;
557
+ /** The ref of the model whose value tree holds the schema */
558
+ rootRef?: RefParts;
544
559
  /** Whether the schema field is required */
545
560
  required: boolean | undefined;
546
561
  };