@skmtc/core 0.41.0 → 0.43.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 (55) hide show
  1. package/esm/context/ParseContext.d.ts +17 -0
  2. package/esm/context/ParseContext.js +50 -28
  3. package/esm/context/generateTypes.d.ts +10 -10
  4. package/esm/context/tryParseAt.d.ts +3 -3
  5. package/esm/context/tryParseAt.js +4 -4
  6. package/esm/helpers/refFns.d.ts +3 -1
  7. package/esm/helpers/refFns.js +5 -2
  8. package/esm/oas/operation/Operation.d.ts +19 -7
  9. package/esm/oas/operation/Operation.js +32 -13
  10. package/esm/oas/operation/toEffectiveParameters.d.ts +7 -6
  11. package/esm/oas/operation/toEffectiveParameters.js +21 -23
  12. package/esm/oas/ref/DanglingRefError.d.ts +3 -3
  13. package/esm/oas/ref/DanglingRefError.js +3 -3
  14. package/esm/oas/ref/Ref.d.ts +7 -1
  15. package/esm/oas/ref/Ref.js +8 -2
  16. package/esm/oas/union/Union.d.ts +1 -1
  17. package/esm/oas/union/Union.js +1 -1
  18. package/esm/oas/webhook/Webhook.d.ts +10 -0
  19. package/esm/oas/webhook/Webhook.js +16 -2
  20. package/esm/parse/v3-0/_merge-all-of/merge-union.js +9 -1
  21. package/esm/parse/v3-0/schema/toSchemasV3.js +6 -3
  22. package/esm/parse/v3-1/_merge-all-of/merge-union.js +16 -4
  23. package/esm/parse/v3-1/schema/toSchemasV3.js +6 -3
  24. package/esm/parse/v3-2/_merge-all-of/merge-union.js +16 -4
  25. package/esm/parse/v3-2/schema/toSchemasV3.js +6 -3
  26. package/esm/types/Settings.d.ts +19 -8
  27. package/esm/types/Settings.js +18 -1
  28. package/package.json +1 -1
  29. package/script/context/ParseContext.d.ts +17 -0
  30. package/script/context/ParseContext.js +50 -28
  31. package/script/context/generateTypes.d.ts +10 -10
  32. package/script/context/tryParseAt.d.ts +3 -3
  33. package/script/context/tryParseAt.js +4 -4
  34. package/script/helpers/refFns.d.ts +3 -1
  35. package/script/helpers/refFns.js +5 -2
  36. package/script/oas/operation/Operation.d.ts +19 -7
  37. package/script/oas/operation/Operation.js +31 -12
  38. package/script/oas/operation/toEffectiveParameters.d.ts +7 -6
  39. package/script/oas/operation/toEffectiveParameters.js +23 -25
  40. package/script/oas/ref/DanglingRefError.d.ts +3 -3
  41. package/script/oas/ref/DanglingRefError.js +3 -3
  42. package/script/oas/ref/Ref.d.ts +7 -1
  43. package/script/oas/ref/Ref.js +8 -2
  44. package/script/oas/union/Union.d.ts +1 -1
  45. package/script/oas/union/Union.js +1 -1
  46. package/script/oas/webhook/Webhook.d.ts +10 -0
  47. package/script/oas/webhook/Webhook.js +15 -1
  48. package/script/parse/v3-0/_merge-all-of/merge-union.js +9 -1
  49. package/script/parse/v3-0/schema/toSchemasV3.js +6 -3
  50. package/script/parse/v3-1/_merge-all-of/merge-union.js +16 -4
  51. package/script/parse/v3-1/schema/toSchemasV3.js +6 -3
  52. package/script/parse/v3-2/_merge-all-of/merge-union.js +16 -4
  53. package/script/parse/v3-2/schema/toSchemasV3.js +6 -3
  54. package/script/types/Settings.d.ts +19 -8
  55. package/script/types/Settings.js +19 -2
@@ -7,6 +7,7 @@ const Object_js_1 = require("../object/Object.js");
7
7
  const toPrimaryResponseCode_js_1 = require("../response/toPrimaryResponseCode.js");
8
8
  const OasBase_js_1 = require("../../types/OasBase.js");
9
9
  const toEffectiveParameters_js_1 = require("./toEffectiveParameters.js");
10
+ const DanglingRefError_js_1 = require("../ref/DanglingRefError.js");
10
11
  class OasOperation extends OasBase_js_1.OasBase {
11
12
  /**
12
13
  * Creates a new OasOperation instance from operation field data.
@@ -222,20 +223,33 @@ class OasOperation extends OasBase_js_1.OasBase {
222
223
  return (0, traverseSchema_js_1.traverseSchema)(rootSchema, rest);
223
224
  }
224
225
  /**
225
- * Resolve all parameters and optionally filter by location.
226
+ * The parameters that apply to this operation, as OpenAPI defines them: the
227
+ * path item's parameters apply to each of its operations, and an operation's
228
+ * own parameter with the same name and location replaces the path item's.
229
+ * The path item's come first.
226
230
  *
227
- * As OpenAPI defines them: the path item's parameters apply to each of its
228
- * operations, and an operation's own parameter with the same name and
229
- * location replaces the path item's. The path item's come first. A
230
- * reference that names nothing (kept under `system.danglingRefs: keep`) is
231
- * left out: it has no name or location, and the parser logged a
232
- * `DANGLING_REF` warning for it.
231
+ * References stay references, so a caller can resolve each one on its own.
232
+ * A reference that names nothing (kept when `system.danglingRefs` lists
233
+ * `parameter`) keeps its place, and resolving it throws `DanglingRefError`.
234
+ * {@link OasOperation.toParams} resolves them all.
235
+ *
236
+ * @returns the parameters, path item's first
237
+ */
238
+ toEffectiveParameters() {
239
+ return (0, toEffectiveParameters_js_1.toEffectiveParameters)({ own: this.parameters, shared: this.pathItem?.parameters });
240
+ }
241
+ /**
242
+ * Resolve all parameters and optionally filter by location: the resolved
243
+ * {@link OasOperation.toEffectiveParameters}.
233
244
  *
234
245
  * @param filter - only include parameters from specified locations
235
246
  * @returns
247
+ * @throws {DanglingRefError} when a parameter is a reference that names nothing
236
248
  */
237
249
  toParams(filter) {
238
- return (0, toEffectiveParameters_js_1.toResolvedParameters)((0, toEffectiveParameters_js_1.toEffectiveParameters)({ own: this.parameters, shared: this.pathItem?.parameters })).filter(param => (filter?.length ? filter.includes(param.location) : true));
250
+ return this.toEffectiveParameters()
251
+ .map(param => param.resolve())
252
+ .filter(param => (filter?.length ? filter.includes(param.location) : true));
239
253
  }
240
254
  /**
241
255
  * Creates an OAS object representation of operation parameters.
@@ -258,12 +272,17 @@ class OasOperation extends OasBase_js_1.OasBase {
258
272
  *
259
273
  * @param options - Conversion options for nested components
260
274
  * @returns OpenAPI v3 operation object
275
+ * @throws {DanglingRefError} when a parameter is a reference that names
276
+ * nothing, as {@link OasOperation.toParams} does: there is no parameter to
277
+ * write, and the caller decides what to do
261
278
  */
262
279
  toJsonSchema(options) {
263
- const parameters = (0, toEffectiveParameters_js_1.toEffectiveParameters)({
264
- own: this.parameters,
265
- shared: this.pathItem?.parameters
266
- });
280
+ const parameters = this.toEffectiveParameters();
281
+ for (const parameter of parameters) {
282
+ if (parameter.isRef() && (0, toEffectiveParameters_js_1.namesNothing)(parameter)) {
283
+ throw new DanglingRefError_js_1.DanglingRefError(parameter.$ref);
284
+ }
285
+ }
267
286
  return {
268
287
  tags: this.tags,
269
288
  summary: this.summary,
@@ -11,14 +11,15 @@ type ToEffectiveParametersArgs = {
11
11
  * The parameters that apply to an operation or webhook, as OpenAPI defines
12
12
  * them: the path item's first, then its own. An own parameter with the same
13
13
  * name and location replaces the path item's. References stay references.
14
- * A reference that names nothing (kept under `system.danglingRefs: keep`)
15
- * has no name or location, so it replaces nothing and nothing replaces it.
14
+ *
15
+ * A reference that names nothing (kept when `system.danglingRefs` lists
16
+ * `parameter`) has no name or location. It keeps its place, and only the
17
+ * same `$ref` replaces it.
16
18
  */
17
19
  export declare const toEffectiveParameters: ({ own, shared }: ToEffectiveParametersArgs) => Parameter[];
18
20
  /**
19
- * Resolves each parameter. A reference that names nothing is left out: it
20
- * has no name or location to render, and the parser logged a `DANGLING_REF`
21
- * warning for it.
21
+ * True for a parameter `$ref` that names nothing in the document, which the
22
+ * parser keeps when `system.danglingRefs` lists `parameter`.
22
23
  */
23
- export declare const toResolvedParameters: (parameters: Parameter[]) => OasParameter[];
24
+ export declare const namesNothing: (parameter: Parameter) => boolean;
24
25
  export {};
@@ -1,47 +1,45 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toResolvedParameters = exports.toEffectiveParameters = void 0;
3
+ exports.namesNothing = exports.toEffectiveParameters = void 0;
4
4
  const DanglingRefError_js_1 = require("../ref/DanglingRefError.js");
5
5
  /**
6
6
  * The parameters that apply to an operation or webhook, as OpenAPI defines
7
7
  * them: the path item's first, then its own. An own parameter with the same
8
8
  * name and location replaces the path item's. References stay references.
9
- * A reference that names nothing (kept under `system.danglingRefs: keep`)
10
- * has no name or location, so it replaces nothing and nothing replaces it.
9
+ *
10
+ * A reference that names nothing (kept when `system.danglingRefs` lists
11
+ * `parameter`) has no name or location. It keeps its place, and only the
12
+ * same `$ref` replaces it.
11
13
  */
12
14
  const toEffectiveParameters = ({ own = [], shared = [] }) => {
13
15
  const ownKeys = new Set(own.map(toParameterKey));
14
- return [
15
- ...shared.filter(parameter => {
16
- const key = toParameterKey(parameter);
17
- return key === undefined || !ownKeys.has(key);
18
- }),
19
- ...own
20
- ];
16
+ return [...shared.filter(parameter => !ownKeys.has(toParameterKey(parameter))), ...own];
21
17
  };
22
18
  exports.toEffectiveParameters = toEffectiveParameters;
23
19
  /**
24
- * Resolves each parameter. A reference that names nothing is left out: it
25
- * has no name or location to render, and the parser logged a `DANGLING_REF`
26
- * warning for it.
20
+ * True for a parameter `$ref` that names nothing in the document, which the
21
+ * parser keeps when `system.danglingRefs` lists `parameter`.
27
22
  */
28
- const toResolvedParameters = (parameters) => parameters.flatMap(parameter => {
29
- const resolved = toResolvedParameter(parameter);
30
- return resolved === undefined ? [] : [resolved];
31
- });
32
- exports.toResolvedParameters = toResolvedParameters;
33
- const toParameterKey = (parameter) => {
34
- const resolved = toResolvedParameter(parameter);
35
- return resolved === undefined ? undefined : `${resolved.location}:${resolved.name}`;
36
- };
37
- const toResolvedParameter = (parameter) => {
23
+ const namesNothing = (parameter) => {
24
+ if (!parameter.isRef()) {
25
+ return false;
26
+ }
38
27
  try {
39
- return parameter.resolve();
28
+ parameter.resolve();
29
+ return false;
40
30
  }
41
31
  catch (error) {
42
32
  if (DanglingRefError_js_1.DanglingRefError.is(error)) {
43
- return undefined;
33
+ return true;
44
34
  }
45
35
  throw error;
46
36
  }
47
37
  };
38
+ exports.namesNothing = namesNothing;
39
+ const toParameterKey = (parameter) => {
40
+ if (parameter.isRef() && (0, exports.namesNothing)(parameter)) {
41
+ return `$ref:${parameter.$ref}`;
42
+ }
43
+ const { name, location } = parameter.resolve();
44
+ return `${location}:${name}`;
45
+ };
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Thrown when a reference that names nothing in the document is resolved.
3
3
  *
4
- * Under `client.json` `system.danglingRefs: strict` (the default) the parser
5
- * removes what holds such a reference, so a generator never meets one. Under
6
- * `keep` the reference stays, and a generator that resolves it can catch
4
+ * By default the parser removes what holds such a reference, so a generator
5
+ * never meets one. When `client.json` `system.danglingRefs` lists the
6
+ * reference's kind, it stays, and a generator that resolves it can catch
7
7
  * this error and render something else in its place. Test for it with
8
8
  * {@link DanglingRefError.is}, not `instanceof`.
9
9
  */
@@ -4,9 +4,9 @@ exports.DanglingRefError = void 0;
4
4
  /**
5
5
  * Thrown when a reference that names nothing in the document is resolved.
6
6
  *
7
- * Under `client.json` `system.danglingRefs: strict` (the default) the parser
8
- * removes what holds such a reference, so a generator never meets one. Under
9
- * `keep` the reference stays, and a generator that resolves it can catch
7
+ * By default the parser removes what holds such a reference, so a generator
8
+ * never meets one. When `client.json` `system.danglingRefs` lists the
9
+ * reference's kind, it stays, and a generator that resolves it can catch
10
10
  * this error and render something else in its place. Test for it with
11
11
  * {@link DanglingRefError.is}, not `instanceof`.
12
12
  */
@@ -233,12 +233,18 @@ export declare class OasRef<T extends OasRefData['refType']> extends OasBase {
233
233
  *
234
234
  * @returns Either the resolved component or another reference in the chain
235
235
  * @throws {DanglingRefError} when the reference names nothing in the
236
- * document (kept under `client.json` `system.danglingRefs: keep`),
236
+ * document (kept when `client.json` `system.danglingRefs` lists its kind),
237
237
  * including a `$ref` with no name, such as `#/components/schemas/`
238
238
  * @throws Error when it names a component of another kind, such as a
239
239
  * `requestBody` ref to `#/components/schemas/…`
240
240
  */
241
241
  resolveOnce(): OasRef<T> | ResolvedRef<T>;
242
+ /**
243
+ * The component name the reference looks up.
244
+ *
245
+ * @throws {DanglingRefError} when the `$ref` has no name, such as
246
+ * `#/components/schemas/`: it names nothing
247
+ */
242
248
  toRefName(): RefName;
243
249
  /**
244
250
  * Narrows this reference to a schema reference.
@@ -462,7 +462,7 @@ class OasRef extends OasBase_js_1.OasBase {
462
462
  *
463
463
  * @returns Either the resolved component or another reference in the chain
464
464
  * @throws {DanglingRefError} when the reference names nothing in the
465
- * document (kept under `client.json` `system.danglingRefs: keep`),
465
+ * document (kept when `client.json` `system.danglingRefs` lists its kind),
466
466
  * including a `$ref` with no name, such as `#/components/schemas/`
467
467
  * @throws Error when it names a component of another kind, such as a
468
468
  * `requestBody` ref to `#/components/schemas/…`
@@ -487,8 +487,14 @@ class OasRef extends OasBase_js_1.OasBase {
487
487
  }
488
488
  return resolved;
489
489
  }
490
+ /**
491
+ * The component name the reference looks up.
492
+ *
493
+ * @throws {DanglingRefError} when the `$ref` has no name, such as
494
+ * `#/components/schemas/`: it names nothing
495
+ */
490
496
  toRefName() {
491
- return (0, refFns_js_1.toRefName)(this.$ref);
497
+ return toLookupName(this.$ref);
492
498
  }
493
499
  /**
494
500
  * Narrows this reference to a schema reference.
@@ -217,7 +217,7 @@ export declare class OasUnion extends OasBase {
217
217
  * property, and that allows only string literals for it. No value may
218
218
  * belong to two members. A member that is a union, or anything other than
219
219
  * an object, makes it `false`, as does a reference on the way that names
220
- * nothing in the document (kept under `system.danglingRefs: keep`).
220
+ * nothing in the document (kept when `system.danglingRefs` lists `schema`).
221
221
  *
222
222
  * It reads the schemas only. A generator may refuse more: one that leaves
223
223
  * out `readOnly` properties cannot discriminate on one.
@@ -288,7 +288,7 @@ class OasUnion extends OasBase_js_1.OasBase {
288
288
  * property, and that allows only string literals for it. No value may
289
289
  * belong to two members. A member that is a union, or anything other than
290
290
  * an object, makes it `false`, as does a reference on the way that names
291
- * nothing in the document (kept under `system.danglingRefs: keep`).
291
+ * nothing in the document (kept when `system.danglingRefs` lists `schema`).
292
292
  *
293
293
  * It reads the schemas only. A generator may refuse more: one that leaves
294
294
  * out `readOnly` properties cannot discriminate on one.
@@ -119,11 +119,21 @@ export declare class OasWebhook extends OasBase {
119
119
  * `undefined` when there is no body or no schema for that media type.
120
120
  */
121
121
  toPayloadSchema(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
122
+ /**
123
+ * The inbound parameters that apply to this webhook, path item parameters
124
+ * included, with references unresolved. Mirrors
125
+ * {@link OasOperation.toEffectiveParameters}.
126
+ *
127
+ * @returns the parameters, path item's first
128
+ */
129
+ toEffectiveParameters(): (OasParameter | OasRef<'parameter'>)[];
122
130
  /**
123
131
  * Resolve the inbound parameters (e.g. the signature/headers a handler
124
132
  * receives), optionally filtered by location. Mirrors
125
133
  * {@link OasOperation.toParams}, path item parameters included; the
126
134
  * parameters carry the same shape, only their direction is inbound.
135
+ *
136
+ * @throws {DanglingRefError} when a parameter is a reference that names nothing
127
137
  */
128
138
  toParams(filter?: OasParameterLocation[]): OasParameter[];
129
139
  /**
@@ -169,14 +169,28 @@ class OasWebhook extends OasBase_js_1.OasBase {
169
169
  toPayloadSchema(mediaType) {
170
170
  return this.toPayload()?.toSchema(mediaType);
171
171
  }
172
+ /**
173
+ * The inbound parameters that apply to this webhook, path item parameters
174
+ * included, with references unresolved. Mirrors
175
+ * {@link OasOperation.toEffectiveParameters}.
176
+ *
177
+ * @returns the parameters, path item's first
178
+ */
179
+ toEffectiveParameters() {
180
+ return (0, toEffectiveParameters_js_1.toEffectiveParameters)({ own: this.parameters, shared: this.pathItem?.parameters });
181
+ }
172
182
  /**
173
183
  * Resolve the inbound parameters (e.g. the signature/headers a handler
174
184
  * receives), optionally filtered by location. Mirrors
175
185
  * {@link OasOperation.toParams}, path item parameters included; the
176
186
  * parameters carry the same shape, only their direction is inbound.
187
+ *
188
+ * @throws {DanglingRefError} when a parameter is a reference that names nothing
177
189
  */
178
190
  toParams(filter) {
179
- return (0, toEffectiveParameters_js_1.toResolvedParameters)((0, toEffectiveParameters_js_1.toEffectiveParameters)({ own: this.parameters, shared: this.pathItem?.parameters })).filter(param => (filter?.length ? filter.includes(param.location) : true));
191
+ return this.toEffectiveParameters()
192
+ .map(param => param.resolve())
193
+ .filter(param => (filter?.length ? filter.includes(param.location) : true));
180
194
  }
181
195
  /**
182
196
  * The status code of the primary acknowledgement response — the lowest 2xx
@@ -5,6 +5,7 @@ const decompose_union_js_1 = require("./decompose-union.js");
5
5
  const merge_js_1 = require("./merge.js");
6
6
  const cross_product_js_1 = require("./cross-product.js");
7
7
  const refFns_js_1 = require("../../../helpers/refFns.js");
8
+ const DanglingRefError_js_1 = require("../../../oas/ref/DanglingRefError.js");
8
9
  const mergeUnion = ({ schema, getRef, system, groupType }) => {
9
10
  const { beforeExcluded, decomposed, afterExcluded } = (0, decompose_union_js_1.decomposeUnion)({ schema, groupType });
10
11
  // if (decomposed.length === 1) {
@@ -54,13 +55,20 @@ exports.toOwnSystem = toOwnSystem;
54
55
  * ({@link toOwnSystem}). Inside an outer first pass under `latestWins`, a
55
56
  * cross product with no pair that merges fails its pair: the outer pass then
56
57
  * leaves the pair out, or lets the later member win.
58
+ *
59
+ * A `$ref` that names nothing is not a contradiction, so its pair is not left
60
+ * out for it: the `DanglingRefError` is thrown on, and `system.danglingRefs`
61
+ * decides (`allOfMember`).
57
62
  */
58
63
  const mergePairs = ({ pairs, merge, system }) => {
59
64
  const mergeEach = (pairSystem) => pairs.flatMap(pair => {
60
65
  try {
61
66
  return [merge(pair, pairSystem)];
62
67
  }
63
- catch (_error) {
68
+ catch (error) {
69
+ if (DanglingRefError_js_1.DanglingRefError.is(error)) {
70
+ throw error;
71
+ }
64
72
  return [];
65
73
  }
66
74
  });
@@ -182,7 +182,7 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
182
182
  const system = (0, allOfSystem_js_1.toAllOfSystem)(context);
183
183
  const merged = (0, merge_intersection_js_1.mergeIntersection)({
184
184
  schema,
185
- getRef: (0, refFns_js_2.toGetRef)(context.documentObject),
185
+ getRef: (0, refFns_js_2.toGetRef)(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
186
186
  system
187
187
  });
188
188
  (0, allOfSystem_js_1.logAllOfContradictions)({ system, stackTrail, parent: schema, context });
@@ -196,7 +196,9 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
196
196
  const merged = (0, merge_union_js_1.mergeUnion)({
197
197
  // A null member makes the union nullable: `oneOf: [$ref, null]` is a nullable reference.
198
198
  schema: withoutNullMembers(schema, 'oneOf'),
199
- getRef: (0, refFns_js_2.toGetRef)(context.documentObject),
199
+ // A member's own `allOf`, or a member merged with the keywords beside
200
+ // the `oneOf`, is merged here, so it follows `allOfMember` too.
201
+ getRef: (0, refFns_js_2.toGetRef)(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
200
202
  system,
201
203
  groupType: 'oneOf'
202
204
  });
@@ -264,7 +266,8 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
264
266
  const system = (0, allOfSystem_js_1.toAllOfSystem)(context);
265
267
  const merged = (0, merge_union_js_1.mergeUnion)({
266
268
  schema: withoutNullMembers(schema, 'anyOf'),
267
- getRef: (0, refFns_js_2.toGetRef)(context.documentObject),
269
+ // As for `oneOf`: what is merged here follows `allOfMember`.
270
+ getRef: (0, refFns_js_2.toGetRef)(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
268
271
  system,
269
272
  groupType: 'anyOf'
270
273
  });
@@ -5,6 +5,7 @@ const decompose_union_js_1 = require("./decompose-union.js");
5
5
  const merge_js_1 = require("./merge.js");
6
6
  const cross_product_js_1 = require("./cross-product.js");
7
7
  const refFns_js_1 = require("../../../helpers/refFns.js");
8
+ const DanglingRefError_js_1 = require("../../../oas/ref/DanglingRefError.js");
8
9
  const mergeUnion = ({ schema, getRef, normalize, system, groupType }) => {
9
10
  const { beforeExcluded, decomposed, afterExcluded } = (0, decompose_union_js_1.decomposeUnion)({ schema, groupType });
10
11
  // if (decomposed.length === 1) {
@@ -61,13 +62,20 @@ exports.toOwnSystem = toOwnSystem;
61
62
  * ({@link toOwnSystem}). Inside an outer first pass under `latestWins`, a
62
63
  * cross product with no pair that merges fails its pair: the outer pass then
63
64
  * leaves the pair out, or lets the later member win.
65
+ *
66
+ * A `$ref` that names nothing is not a contradiction, so its pair is not left
67
+ * out for it: the `DanglingRefError` is thrown on, and `system.danglingRefs`
68
+ * decides (`allOfMember`).
64
69
  */
65
70
  const mergePairs = ({ pairs, merge, system }) => {
66
71
  const mergeEach = (pairSystem) => pairs.flatMap(pair => {
67
72
  try {
68
73
  return [merge(pair, pairSystem)];
69
74
  }
70
- catch (_error) {
75
+ catch (error) {
76
+ if (DanglingRefError_js_1.DanglingRefError.is(error)) {
77
+ throw error;
78
+ }
71
79
  return [];
72
80
  }
73
81
  });
@@ -120,8 +128,9 @@ exports.mergeCrossProduct = mergeCrossProduct;
120
128
  * to a `oneOf` with `minLength` beside it. Union-level keys (`nullable`,
121
129
  * `description`, …) are not merged in, and a `$ref` member is returned
122
130
  * unchanged. A member that conflicts with the
123
- * siblings is dropped, as in the cross product. A schema with no group is
124
- * its own only member and is returned unchanged.
131
+ * siblings is dropped, as in the cross product, but not one with a `$ref`
132
+ * that names nothing: that is no conflict. A schema with no group is its own
133
+ * only member and is returned unchanged.
125
134
  */
126
135
  const withGroupSiblings = ({ schema, members, getRef, normalize, system, groupType }) => {
127
136
  if (!Array.isArray(schema[groupType])) {
@@ -141,7 +150,10 @@ const withGroupSiblings = ({ schema, members, getRef, normalize, system, groupTy
141
150
  try {
142
151
  return (0, merge_js_1.mergeSchemasOrRefs)({ first: siblingSchema, second: member, getRef, normalize, system });
143
152
  }
144
- catch (_error) {
153
+ catch (error) {
154
+ if (DanglingRefError_js_1.DanglingRefError.is(error)) {
155
+ throw error;
156
+ }
145
157
  return undefined;
146
158
  }
147
159
  })
@@ -234,7 +234,7 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
234
234
  const system = (0, allOfSystem_js_1.toAllOfSystem)(context);
235
235
  const merged = (0, merge_intersection_js_1.mergeIntersection)({
236
236
  schema: wrapper,
237
- getRef: (0, refFns_js_2.toGetRef)(context.documentObject),
237
+ getRef: (0, refFns_js_2.toGetRef)(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
238
238
  normalize: normalize_schema_shape_js_1.normalizeMergeMember,
239
239
  system
240
240
  });
@@ -266,7 +266,9 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
266
266
  const system = (0, allOfSystem_js_1.toAllOfSystem)(context);
267
267
  const merged = (0, merge_union_js_1.mergeUnion)({
268
268
  schema: withoutNull,
269
- getRef: (0, refFns_js_2.toGetRef)(context.documentObject),
269
+ // A member's own `allOf`, or a member merged with the keywords beside
270
+ // the `oneOf`, is merged here, so it follows `allOfMember` too.
271
+ getRef: (0, refFns_js_2.toGetRef)(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
270
272
  normalize: normalize_schema_shape_js_1.normalizeMergeMember,
271
273
  system,
272
274
  groupType: 'oneOf'
@@ -347,7 +349,8 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
347
349
  const system = (0, allOfSystem_js_1.toAllOfSystem)(context);
348
350
  const merged = (0, merge_union_js_1.mergeUnion)({
349
351
  schema: withoutNull,
350
- getRef: (0, refFns_js_2.toGetRef)(context.documentObject),
352
+ // As for `oneOf`: what is merged here follows `allOfMember`.
353
+ getRef: (0, refFns_js_2.toGetRef)(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
351
354
  normalize: normalize_schema_shape_js_1.normalizeMergeMember,
352
355
  system,
353
356
  groupType: 'anyOf'
@@ -5,6 +5,7 @@ const decompose_union_js_1 = require("./decompose-union.js");
5
5
  const merge_js_1 = require("./merge.js");
6
6
  const cross_product_js_1 = require("./cross-product.js");
7
7
  const refFns_js_1 = require("../../../helpers/refFns.js");
8
+ const DanglingRefError_js_1 = require("../../../oas/ref/DanglingRefError.js");
8
9
  const mergeUnion = ({ schema, getRef, normalize, system, groupType }) => {
9
10
  const { beforeExcluded, decomposed, afterExcluded } = (0, decompose_union_js_1.decomposeUnion)({ schema, groupType });
10
11
  // if (decomposed.length === 1) {
@@ -61,13 +62,20 @@ exports.toOwnSystem = toOwnSystem;
61
62
  * ({@link toOwnSystem}). Inside an outer first pass under `latestWins`, a
62
63
  * cross product with no pair that merges fails its pair: the outer pass then
63
64
  * leaves the pair out, or lets the later member win.
65
+ *
66
+ * A `$ref` that names nothing is not a contradiction, so its pair is not left
67
+ * out for it: the `DanglingRefError` is thrown on, and `system.danglingRefs`
68
+ * decides (`allOfMember`).
64
69
  */
65
70
  const mergePairs = ({ pairs, merge, system }) => {
66
71
  const mergeEach = (pairSystem) => pairs.flatMap(pair => {
67
72
  try {
68
73
  return [merge(pair, pairSystem)];
69
74
  }
70
- catch (_error) {
75
+ catch (error) {
76
+ if (DanglingRefError_js_1.DanglingRefError.is(error)) {
77
+ throw error;
78
+ }
71
79
  return [];
72
80
  }
73
81
  });
@@ -120,8 +128,9 @@ exports.mergeCrossProduct = mergeCrossProduct;
120
128
  * to a `oneOf` with `minLength` beside it. Union-level keys (`nullable`,
121
129
  * `description`, …) are not merged in, and a `$ref` member is returned
122
130
  * unchanged. A member that conflicts with the
123
- * siblings is dropped, as in the cross product. A schema with no group is
124
- * its own only member and is returned unchanged.
131
+ * siblings is dropped, as in the cross product, but not one with a `$ref`
132
+ * that names nothing: that is no conflict. A schema with no group is its own
133
+ * only member and is returned unchanged.
125
134
  */
126
135
  const withGroupSiblings = ({ schema, members, getRef, normalize, system, groupType }) => {
127
136
  if (!Array.isArray(schema[groupType])) {
@@ -141,7 +150,10 @@ const withGroupSiblings = ({ schema, members, getRef, normalize, system, groupTy
141
150
  try {
142
151
  return (0, merge_js_1.mergeSchemasOrRefs)({ first: siblingSchema, second: member, getRef, normalize, system });
143
152
  }
144
- catch (_error) {
153
+ catch (error) {
154
+ if (DanglingRefError_js_1.DanglingRefError.is(error)) {
155
+ throw error;
156
+ }
145
157
  return undefined;
146
158
  }
147
159
  })
@@ -234,7 +234,7 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
234
234
  const system = (0, allOfSystem_js_1.toAllOfSystem)(context);
235
235
  const merged = (0, merge_intersection_js_1.mergeIntersection)({
236
236
  schema: wrapper,
237
- getRef: (0, refFns_js_2.toGetRef)(context.documentObject),
237
+ getRef: (0, refFns_js_2.toGetRef)(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
238
238
  normalize: normalize_schema_shape_js_1.normalizeMergeMember,
239
239
  system
240
240
  });
@@ -266,7 +266,9 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
266
266
  const system = (0, allOfSystem_js_1.toAllOfSystem)(context);
267
267
  const merged = (0, merge_union_js_1.mergeUnion)({
268
268
  schema: withoutNull,
269
- getRef: (0, refFns_js_2.toGetRef)(context.documentObject),
269
+ // A member's own `allOf`, or a member merged with the keywords beside
270
+ // the `oneOf`, is merged here, so it follows `allOfMember` too.
271
+ getRef: (0, refFns_js_2.toGetRef)(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
270
272
  normalize: normalize_schema_shape_js_1.normalizeMergeMember,
271
273
  system,
272
274
  groupType: 'oneOf'
@@ -347,7 +349,8 @@ const toSchemaV3 = ({ schema, stackTrail, context }) => {
347
349
  const system = (0, allOfSystem_js_1.toAllOfSystem)(context);
348
350
  const merged = (0, merge_union_js_1.mergeUnion)({
349
351
  schema: withoutNull,
350
- getRef: (0, refFns_js_2.toGetRef)(context.documentObject),
352
+ // As for `oneOf`: what is merged here follows `allOfMember`.
353
+ getRef: (0, refFns_js_2.toGetRef)(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
351
354
  normalize: normalize_schema_shape_js_1.normalizeMergeMember,
352
355
  system,
353
356
  groupType: 'anyOf'
@@ -162,6 +162,15 @@ export declare const includeModels: v.GenericSchema<IncludeModels>;
162
162
  * {@link AnchorsSettings} for the consumer-facing fields.
163
163
  */
164
164
  export declare const anchorsSettings: v.GenericSchema<AnchorsSettings>;
165
+ /**
166
+ * What `client.json#settings.system.danglingRefs` can list: each kind of
167
+ * `$ref`, and `allOfMember`, a `$ref` that core merges at parse: a member of
168
+ * an `allOf`, also one inside a `oneOf` or `anyOf` member, or a `oneOf` or
169
+ * `anyOf` member merged with the keywords beside the union.
170
+ */
171
+ export declare const danglingRefKinds: readonly ["schema", "parameter", "requestBody", "response", "header", "securityScheme", "example", "link", "allOfMember"];
172
+ /** A kind of `$ref` that `system.danglingRefs` can let name nothing. */
173
+ export type DanglingRefKind = (typeof danglingRefKinds)[number];
165
174
  /** Valibot schema for {@link SystemSettings}: `client.json#settings.system`. */
166
175
  export declare const systemSettings: v.GenericSchema<SystemSettings>;
167
176
  export declare const clientSettings: v.GenericSchema<ClientSettings>;
@@ -450,15 +459,17 @@ export type SystemSettings = {
450
459
  */
451
460
  anyOf?: 'union' | 'unknown';
452
461
  /**
453
- * `strict` (the default): a `$ref` that names nothing in the document is a
454
- * parse error, and what holds it is removed, with what uses that. `keep`:
455
- * the `$ref` stays, with a warning, and resolving it throws
456
- * `DanglingRefError`, which a generator can catch to render something
457
- * else. With either, a `$ref` to an example or a link is a warning and
458
- * stays, and a `$ref` that core resolves while it parses (an `allOf`
459
- * member that it merges) is an error, and what holds it is removed.
462
+ * The kinds of `$ref` that may name nothing in the document. A dangling
463
+ * `$ref` of a listed kind stays, with a warning, and resolving it throws
464
+ * `DanglingRefError` for the generator to handle. A dangling `$ref` of any
465
+ * other kind is a parse error, and what holds it is removed, with what uses
466
+ * that. `allOfMember` is core's own choice, made at parse: a `$ref` that
467
+ * core merges (a member of an `allOf`, also inside a `oneOf` or `anyOf`
468
+ * member, or a union member merged with the keywords beside the union) is
469
+ * left out of the merge, so its properties are not in the model. The
470
+ * default, `[]`, lists none.
460
471
  */
461
- danglingRefs?: 'strict' | 'keep';
472
+ danglingRefs?: DanglingRefKind[];
462
473
  };
463
474
  export type ClientSettings = {
464
475
  /** Base output path for generated files */
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.skmtcClientConfig = exports.clientSettings = exports.systemSettings = exports.anchorsSettings = exports.includeModels = exports.includeModelRefs = exports.includeOperations = exports.includePaths = exports.skipModels = exports.skipModelRefs = exports.skipOperations = exports.skipPaths = exports.modulePackages = exports.modulePackage = void 0;
36
+ exports.skmtcClientConfig = exports.clientSettings = exports.systemSettings = exports.danglingRefKinds = exports.anchorsSettings = exports.includeModels = exports.includeModelRefs = exports.includeOperations = exports.includePaths = exports.skipModels = exports.skipModelRefs = exports.skipOperations = exports.skipPaths = exports.modulePackages = exports.modulePackage = void 0;
37
37
  /**
38
38
  * @fileoverview SKMTC Core Settings and Configuration
39
39
  *
@@ -205,13 +205,30 @@ exports.anchorsSettings = v.object({
205
205
  enabled: v.boolean(),
206
206
  out: v.optional(v.string())
207
207
  });
208
+ /**
209
+ * What `client.json#settings.system.danglingRefs` can list: each kind of
210
+ * `$ref`, and `allOfMember`, a `$ref` that core merges at parse: a member of
211
+ * an `allOf`, also one inside a `oneOf` or `anyOf` member, or a `oneOf` or
212
+ * `anyOf` member merged with the keywords beside the union.
213
+ */
214
+ exports.danglingRefKinds = [
215
+ 'schema',
216
+ 'parameter',
217
+ 'requestBody',
218
+ 'response',
219
+ 'header',
220
+ 'securityScheme',
221
+ 'example',
222
+ 'link',
223
+ 'allOfMember'
224
+ ];
208
225
  /** Valibot schema for {@link SystemSettings}: `client.json#settings.system`. */
209
226
  exports.systemSettings = v.object({
210
227
  allOf: v.optional(v.picklist(['strict', 'latestWins'])),
211
228
  responseContradictions: v.optional(v.picklist(['strict', 'unknown'])),
212
229
  not: v.optional(v.picklist(['strict', 'unknown'])),
213
230
  anyOf: v.optional(v.picklist(['union', 'unknown'])),
214
- danglingRefs: v.optional(v.picklist(['strict', 'keep']))
231
+ danglingRefs: v.optional(v.array(v.picklist(exports.danglingRefKinds)))
215
232
  });
216
233
  exports.clientSettings = v.object({
217
234
  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/); ' +