@skmtc/core 0.41.0 → 0.42.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 (53) 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 +1 -4
  9. package/esm/oas/operation/Operation.js +5 -6
  10. package/esm/oas/operation/toEffectiveParameters.d.ts +0 -8
  11. package/esm/oas/operation/toEffectiveParameters.js +3 -32
  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 +1 -1
  15. package/esm/oas/ref/Ref.js +1 -1
  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.js +4 -2
  19. package/esm/parse/v3-0/_merge-all-of/merge-union.js +9 -1
  20. package/esm/parse/v3-0/schema/toSchemasV3.js +6 -3
  21. package/esm/parse/v3-1/_merge-all-of/merge-union.js +16 -4
  22. package/esm/parse/v3-1/schema/toSchemasV3.js +6 -3
  23. package/esm/parse/v3-2/_merge-all-of/merge-union.js +16 -4
  24. package/esm/parse/v3-2/schema/toSchemasV3.js +6 -3
  25. package/esm/types/Settings.d.ts +19 -8
  26. package/esm/types/Settings.js +18 -1
  27. package/package.json +1 -1
  28. package/script/context/ParseContext.d.ts +17 -0
  29. package/script/context/ParseContext.js +50 -28
  30. package/script/context/generateTypes.d.ts +10 -10
  31. package/script/context/tryParseAt.d.ts +3 -3
  32. package/script/context/tryParseAt.js +4 -4
  33. package/script/helpers/refFns.d.ts +3 -1
  34. package/script/helpers/refFns.js +5 -2
  35. package/script/oas/operation/Operation.d.ts +1 -4
  36. package/script/oas/operation/Operation.js +4 -5
  37. package/script/oas/operation/toEffectiveParameters.d.ts +0 -8
  38. package/script/oas/operation/toEffectiveParameters.js +4 -34
  39. package/script/oas/ref/DanglingRefError.d.ts +3 -3
  40. package/script/oas/ref/DanglingRefError.js +3 -3
  41. package/script/oas/ref/Ref.d.ts +1 -1
  42. package/script/oas/ref/Ref.js +1 -1
  43. package/script/oas/union/Union.d.ts +1 -1
  44. package/script/oas/union/Union.js +1 -1
  45. package/script/oas/webhook/Webhook.js +3 -1
  46. package/script/parse/v3-0/_merge-all-of/merge-union.js +9 -1
  47. package/script/parse/v3-0/schema/toSchemasV3.js +6 -3
  48. package/script/parse/v3-1/_merge-all-of/merge-union.js +16 -4
  49. package/script/parse/v3-1/schema/toSchemasV3.js +6 -3
  50. package/script/parse/v3-2/_merge-all-of/merge-union.js +16 -4
  51. package/script/parse/v3-2/schema/toSchemasV3.js +6 -3
  52. package/script/types/Settings.d.ts +19 -8
  53. package/script/types/Settings.js +19 -2
@@ -2,6 +2,7 @@ import { decomposeUnion, isUnionLevelKey } from './decompose-union.js';
2
2
  import { mergeSchemasOrRefs } from './merge.js';
3
3
  import { crossProduct } from './cross-product.js';
4
4
  import { isRef } from '../../../helpers/refFns.js';
5
+ import { DanglingRefError } from '../../../oas/ref/DanglingRefError.js';
5
6
  export const mergeUnion = ({ schema, getRef, normalize, system, groupType }) => {
6
7
  const { beforeExcluded, decomposed, afterExcluded } = decomposeUnion({ schema, groupType });
7
8
  // if (decomposed.length === 1) {
@@ -56,13 +57,20 @@ export const toOwnSystem = (system) => ({
56
57
  * ({@link toOwnSystem}). Inside an outer first pass under `latestWins`, a
57
58
  * cross product with no pair that merges fails its pair: the outer pass then
58
59
  * leaves the pair out, or lets the later member win.
60
+ *
61
+ * A `$ref` that names nothing is not a contradiction, so its pair is not left
62
+ * out for it: the `DanglingRefError` is thrown on, and `system.danglingRefs`
63
+ * decides (`allOfMember`).
59
64
  */
60
65
  const mergePairs = ({ pairs, merge, system }) => {
61
66
  const mergeEach = (pairSystem) => pairs.flatMap(pair => {
62
67
  try {
63
68
  return [merge(pair, pairSystem)];
64
69
  }
65
- catch (_error) {
70
+ catch (error) {
71
+ if (DanglingRefError.is(error)) {
72
+ throw error;
73
+ }
66
74
  return [];
67
75
  }
68
76
  });
@@ -114,8 +122,9 @@ export const mergeCrossProduct = ({ first, second, getRef, normalize, system, gr
114
122
  * to a `oneOf` with `minLength` beside it. Union-level keys (`nullable`,
115
123
  * `description`, …) are not merged in, and a `$ref` member is returned
116
124
  * unchanged. A member that conflicts with the
117
- * siblings is dropped, as in the cross product. A schema with no group is
118
- * its own only member and is returned unchanged.
125
+ * siblings is dropped, as in the cross product, but not one with a `$ref`
126
+ * that names nothing: that is no conflict. A schema with no group is its own
127
+ * only member and is returned unchanged.
119
128
  */
120
129
  const withGroupSiblings = ({ schema, members, getRef, normalize, system, groupType }) => {
121
130
  if (!Array.isArray(schema[groupType])) {
@@ -135,7 +144,10 @@ const withGroupSiblings = ({ schema, members, getRef, normalize, system, groupTy
135
144
  try {
136
145
  return mergeSchemasOrRefs({ first: siblingSchema, second: member, getRef, normalize, system });
137
146
  }
138
- catch (_error) {
147
+ catch (error) {
148
+ if (DanglingRefError.is(error)) {
149
+ throw error;
150
+ }
139
151
  return undefined;
140
152
  }
141
153
  })
@@ -229,7 +229,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
229
229
  const system = toAllOfSystem(context);
230
230
  const merged = mergeIntersection({
231
231
  schema: wrapper,
232
- getRef: toGetRef(context.documentObject),
232
+ getRef: toGetRef(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
233
233
  normalize: normalizeMergeMember,
234
234
  system
235
235
  });
@@ -261,7 +261,9 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
261
261
  const system = toAllOfSystem(context);
262
262
  const merged = mergeUnion({
263
263
  schema: withoutNull,
264
- getRef: toGetRef(context.documentObject),
264
+ // A member's own `allOf`, or a member merged with the keywords beside
265
+ // the `oneOf`, is merged here, so it follows `allOfMember` too.
266
+ getRef: toGetRef(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
265
267
  normalize: normalizeMergeMember,
266
268
  system,
267
269
  groupType: 'oneOf'
@@ -342,7 +344,8 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
342
344
  const system = toAllOfSystem(context);
343
345
  const merged = mergeUnion({
344
346
  schema: withoutNull,
345
- getRef: toGetRef(context.documentObject),
347
+ // As for `oneOf`: what is merged here follows `allOfMember`.
348
+ getRef: toGetRef(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
346
349
  normalize: normalizeMergeMember,
347
350
  system,
348
351
  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 */
@@ -169,13 +169,30 @@ export const anchorsSettings = v.object({
169
169
  enabled: v.boolean(),
170
170
  out: v.optional(v.string())
171
171
  });
172
+ /**
173
+ * What `client.json#settings.system.danglingRefs` can list: each kind of
174
+ * `$ref`, and `allOfMember`, a `$ref` that core merges at parse: a member of
175
+ * an `allOf`, also one inside a `oneOf` or `anyOf` member, or a `oneOf` or
176
+ * `anyOf` member merged with the keywords beside the union.
177
+ */
178
+ export const danglingRefKinds = [
179
+ 'schema',
180
+ 'parameter',
181
+ 'requestBody',
182
+ 'response',
183
+ 'header',
184
+ 'securityScheme',
185
+ 'example',
186
+ 'link',
187
+ 'allOfMember'
188
+ ];
172
189
  /** Valibot schema for {@link SystemSettings}: `client.json#settings.system`. */
173
190
  export const systemSettings = v.object({
174
191
  allOf: v.optional(v.picklist(['strict', 'latestWins'])),
175
192
  responseContradictions: v.optional(v.picklist(['strict', 'unknown'])),
176
193
  not: v.optional(v.picklist(['strict', 'unknown'])),
177
194
  anyOf: v.optional(v.picklist(['union', 'unknown'])),
178
- danglingRefs: v.optional(v.picklist(['strict', 'keep']))
195
+ danglingRefs: v.optional(v.array(v.picklist(danglingRefKinds)))
179
196
  });
180
197
  export const clientSettings = v.object({
181
198
  basePath: v.optional(v.pipe(v.string(), v.check(basePath => !isAbsolutePath(basePath), 'basePath must be relative to the SKMTC root (the directory containing .skmtc/); ' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skmtc/core",
3
- "version": "0.41.0",
3
+ "version": "0.42.0",
4
4
  "description": "Skmtc is a declarative code generation framework",
5
5
  "keywords": [
6
6
  "openapi",
@@ -52,6 +52,11 @@ type GqlProtocolState = {
52
52
  options: GqlParseOptions;
53
53
  };
54
54
  type ProtocolState = OasProtocolState | GqlProtocolState;
55
+ type ToDanglingAllOfMemberArgs = {
56
+ $ref: string;
57
+ /** The schema that holds the `allOf`. */
58
+ stackTrail: StackTrail;
59
+ };
55
60
  type ConstructorArgs = {
56
61
  input: SkmtcDocumentInput;
57
62
  logger: Logger;
@@ -166,6 +171,18 @@ export declare class ParseContext {
166
171
  * resolve it there.
167
172
  */
168
173
  registerOasRef<T extends OasRefData['refType']>(consumer: StackTrail, ref: OasRef<T>): void;
174
+ /**
175
+ * What a merge reads in place of a `$ref` that names nothing: an `allOf`
176
+ * member, or in a `oneOf` or `anyOf`, a member's own `allOf` member or a
177
+ * member merged with the keywords beside the union. When
178
+ * `system.danglingRefs` lists `allOfMember`, it is `{}`, which
179
+ * adds nothing to the merge (`A & unknown` is `A`), and a `DANGLING_REF`
180
+ * warning at `stackTrail`: the model has no properties from that member.
181
+ * Otherwise it throws `DanglingRefError`, and what holds the `allOf` is
182
+ * removed. It is separate from `schema`: here core decides, at parse, and
183
+ * the generator never sees the member.
184
+ */
185
+ toDanglingAllOfMember({ $ref, stackTrail }: ToDanglingAllOfMemberArgs): OpenAPIV3.SchemaObject;
169
186
  /**
170
187
  * Register an error against a ref key — typically called when the
171
188
  * target of a `$ref` (or type reference) fails to parse. `undefined`
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
11
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
12
  };
13
- var _ParseContext_instances, _ParseContext_refConsumers, _ParseContext_refErrors, _ParseContext_oasRefs, _ParseContext_rootFrames, _ParseContext_removeComponent, _ParseContext_removeConsumer, _ParseContext_removePathParameterConsumer, _ParseContext_toRawComponentParameter, _ParseContext_logDependencyIssue, _ParseContext_toDocumentTrail, _ParseContext_checkRefs, _ParseContext_logDanglingRef;
13
+ var _ParseContext_instances, _ParseContext_refConsumers, _ParseContext_refErrors, _ParseContext_oasRefs, _ParseContext_rootFrames, _ParseContext_removeComponent, _ParseContext_removeConsumer, _ParseContext_removePathParameterConsumer, _ParseContext_toRawComponentParameter, _ParseContext_logDependencyIssue, _ParseContext_toDocumentTrail, _ParseContext_checkRefs, _ParseContext_removeHolder;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.ParseContext = void 0;
16
16
  /**
@@ -393,6 +393,31 @@ class ParseContext {
393
393
  this.registerRef(consumer, toRefKey(ref.$ref));
394
394
  __classPrivateFieldGet(this, _ParseContext_oasRefs, "f").push({ consumer, ref });
395
395
  }
396
+ /**
397
+ * What a merge reads in place of a `$ref` that names nothing: an `allOf`
398
+ * member, or in a `oneOf` or `anyOf`, a member's own `allOf` member or a
399
+ * member merged with the keywords beside the union. When
400
+ * `system.danglingRefs` lists `allOfMember`, it is `{}`, which
401
+ * adds nothing to the merge (`A & unknown` is `A`), and a `DANGLING_REF`
402
+ * warning at `stackTrail`: the model has no properties from that member.
403
+ * Otherwise it throws `DanglingRefError`, and what holds the `allOf` is
404
+ * removed. It is separate from `schema`: here core decides, at parse, and
405
+ * the generator never sees the member.
406
+ */
407
+ toDanglingAllOfMember({ $ref, stackTrail }) {
408
+ const error = new DanglingRefError_js_1.DanglingRefError($ref);
409
+ if (!this.system.danglingRefs?.includes('allOfMember')) {
410
+ throw error;
411
+ }
412
+ this.logIssueNoKey({
413
+ level: 'warning',
414
+ message: `${error.message}. It is left out of the allOf merge (system.danglingRefs lists 'allOfMember').`,
415
+ parent: { $ref },
416
+ stackTrail,
417
+ type: 'DANGLING_REF'
418
+ });
419
+ return {};
420
+ }
396
421
  /**
397
422
  * Register an error against a ref key — typically called when the
398
423
  * target of a `$ref` (or type reference) fails to parse. `undefined`
@@ -667,48 +692,45 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
667
692
  ref.resolveOnce();
668
693
  }
669
694
  catch (error) {
670
- if (DanglingRefError_js_1.DanglingRefError.is(error)) {
671
- __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_logDanglingRef).call(this, { consumer, ref, error });
695
+ if (!DanglingRefError_js_1.DanglingRefError.is(error)) {
696
+ const message = error instanceof Error ? error.message : String(error);
697
+ __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
698
+ consumer,
699
+ ref,
700
+ error,
701
+ type: 'REF_TYPE_MISMATCH',
702
+ message: `${message}, so what holds it is removed.`
703
+ });
672
704
  }
673
- else {
705
+ else if (this.system.danglingRefs?.includes(ref.refType)) {
674
706
  this.logIssueNoKey({
675
707
  level: 'warning',
676
- message: `${error instanceof Error ? error.message : String(error)}. It is kept, and resolving it throws.`,
708
+ message: `${error.message}. It is kept (system.danglingRefs lists '${ref.refType}'), and resolving it throws DanglingRefError.`,
677
709
  parent: { $ref: ref.$ref },
678
710
  stackTrail: consumer,
679
- type: 'REF_TYPE_MISMATCH'
711
+ type: 'DANGLING_REF'
712
+ });
713
+ }
714
+ else {
715
+ __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
716
+ consumer,
717
+ ref,
718
+ error,
719
+ type: 'DANGLING_REF',
720
+ message: `${error.message}, so what holds it is removed. To keep it, list '${ref.refType}' in system.danglingRefs.`
680
721
  });
681
722
  }
682
723
  }
683
724
  });
684
- }, _ParseContext_logDanglingRef = function _ParseContext_logDanglingRef({ consumer, ref, error }) {
685
- const exampleOrLink = ref.refType === 'example' || ref.refType === 'link';
686
- if (exampleOrLink || this.system.danglingRefs === 'keep') {
687
- this.logIssueNoKey({
688
- level: 'warning',
689
- message: exampleOrLink
690
- ? `${error.message}. It is kept, as a ref to an example or a link is in both system.danglingRefs modes, and resolving it throws DanglingRefError.`
691
- : `${error.message}. It is kept (system.danglingRefs is keep), and resolving it throws DanglingRefError.`,
692
- parent: { $ref: ref.$ref },
693
- stackTrail: consumer,
694
- type: 'DANGLING_REF'
695
- });
696
- return;
697
- }
698
- // An error inside a component removes that component, and what uses it
699
- // (`removeErroredItems`).
725
+ }, _ParseContext_removeHolder = function _ParseContext_removeHolder({ consumer, ref, error, type, message }) {
700
726
  this.logIssueNoKey({
701
727
  level: 'error',
702
- message: `${error.message}, so what holds it is removed (system.danglingRefs is strict).`,
728
+ message,
703
729
  cause: error,
704
730
  parent: { $ref: ref.$ref },
705
731
  stackTrail: consumer,
706
- type: 'DANGLING_REF'
732
+ type
707
733
  });
708
- // What holds the ref outside the components (an operation, a webhook, a
709
- // path-level parameter) is removed here. Its own location has the
710
- // DANGLING_REF already; an operation that a path-level parameter applies
711
- // to gets an INVALID_DEPENDENCY_REF.
712
734
  const documentTrail = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentTrail).call(this, consumer);
713
735
  if (documentTrail.toStackRef() !== undefined) {
714
736
  return;
@@ -186,18 +186,18 @@ export type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3
186
186
  * One for each schema.
187
187
  *
188
188
  * `DANGLING_REF` — a `$ref` names nothing in the document. One for each
189
- * place the `$ref` is written. An `error` under `system.danglingRefs:
190
- * strict` (the default): what holds the ref is removed, and each item that
191
- * uses it gets an `INVALID_DEPENDENCY_REF`. A `warning` under `keep`: the
192
- * ref stays, and resolving it throws `DanglingRefError`. A ref to an example
193
- * or a link is a `warning` in both modes. A ref that core resolves while it
194
- * parses (an `allOf` member that it merges) is an `error` in both modes, at
195
- * the item that holds it.
189
+ * place the `$ref` is written. A `warning` when `system.danglingRefs` lists
190
+ * the `$ref`'s kind: the ref stays, and resolving it throws
191
+ * `DanglingRefError`; with `allOfMember` listed, a `$ref` that core merges
192
+ * (in an `allOf`, or in a `oneOf` or `anyOf` member) is left out of the
193
+ * merge. Otherwise (the default lists none)
194
+ * an `error`: what holds the ref is removed, and each item that uses it gets
195
+ * an `INVALID_DEPENDENCY_REF`.
196
196
  *
197
- * `REF_TYPE_MISMATCH` (`warning`) — a `$ref` names a component of the wrong
197
+ * `REF_TYPE_MISMATCH` (`error`) — a `$ref` names a component of the wrong
198
198
  * kind, such as a request body that is a `$ref` to
199
- * `#/components/schemas/Pet`. One for each place the `$ref` is written. The
200
- * ref stays, and resolving it throws.
199
+ * `#/components/schemas/Pet`. One for each place the `$ref` is written. What
200
+ * holds the ref is removed; `system.danglingRefs` does not apply.
201
201
  *
202
202
  * `RUN_FAILED` (`error`) — the run itself failed outside the per-item
203
203
  * catches. Its `location` names the entry and phase, for example
@@ -61,9 +61,9 @@ export type TryParseAtArgs<T> = {
61
61
  *
62
62
  * - logs a `level: 'error'` issue at the child location with the
63
63
  * given `type` and the thrown value as `cause`. A `DanglingRefError`
64
- * is logged as `DANGLING_REF`: core resolved a ref while it parsed (an
65
- * `allOf` member it merges, say), so the ref cannot be kept, whatever
66
- * `system.danglingRefs` is
64
+ * is logged as `DANGLING_REF`: core resolved a ref while it parsed (one
65
+ * it merges, in an `allOf` or a `oneOf` or `anyOf` member, when
66
+ * `system.danglingRefs` does not list `allOfMember`)
67
67
  * - registers a ref error if `refKey` is provided
68
68
  * - returns `undefined`
69
69
  *
@@ -28,9 +28,9 @@ const DanglingRefError_js_1 = require("../oas/ref/DanglingRefError.js");
28
28
  *
29
29
  * - logs a `level: 'error'` issue at the child location with the
30
30
  * given `type` and the thrown value as `cause`. A `DanglingRefError`
31
- * is logged as `DANGLING_REF`: core resolved a ref while it parsed (an
32
- * `allOf` member it merges, say), so the ref cannot be kept, whatever
33
- * `system.danglingRefs` is
31
+ * is logged as `DANGLING_REF`: core resolved a ref while it parsed (one
32
+ * it merges, in an `allOf` or a `oneOf` or `anyOf` member, when
33
+ * `system.danglingRefs` does not list `allOfMember`)
34
34
  * - registers a ref error if `refKey` is provided
35
35
  * - returns `undefined`
36
36
  *
@@ -52,7 +52,7 @@ const tryParseAt = ({ stackTrail, key, context, type, parent, refKey, fn }) => {
52
52
  stackTrail: childStack,
53
53
  parent,
54
54
  message: dangling
55
- ? `${normalized.message}. Core resolves it while it parses, so what holds it is removed whatever system.danglingRefs is.`
55
+ ? `${normalized.message}. Core resolves it while it parses, so what holds it is removed.`
56
56
  : normalized.message,
57
57
  cause: normalized,
58
58
  type: dangling ? 'DANGLING_REF' : type
@@ -171,5 +171,7 @@ export declare const isRef: (value: unknown) => value is Ref;
171
171
  * }
172
172
  * ```
173
173
  */
174
- export declare const toGetRef: (oasDocument: OpenAPIV3.Document) => ({ $ref }: ReferenceObject) => OpenAPIV3.SchemaObject;
174
+ export declare const toGetRef: (oasDocument: OpenAPIV3.Document, onDangling?: OnDangling) => ({ $ref }: ReferenceObject) => OpenAPIV3.SchemaObject;
175
+ /** What a resolver reads in place of a `$ref` that names nothing; it may throw. */
176
+ type OnDangling = ($ref: string) => OpenAPIV3.SchemaObject;
175
177
  export {};
@@ -193,15 +193,18 @@ exports.isRef = isRef;
193
193
  * }
194
194
  * ```
195
195
  */
196
- const toGetRef = (oasDocument) => ({ $ref }) => {
196
+ const toGetRef = (oasDocument, onDangling) => ({ $ref }) => {
197
197
  const refName = (0, exports.toRefName)($ref);
198
198
  const item = oasDocument.components?.schemas?.[refName];
199
199
  if ((0, exports.isRef)(item)) {
200
- return (0, exports.toGetRef)(oasDocument)(item);
200
+ return (0, exports.toGetRef)(oasDocument, onDangling)(item);
201
201
  }
202
202
  if (item) {
203
203
  return item;
204
204
  }
205
+ if (onDangling) {
206
+ return onDangling($ref);
207
+ }
205
208
  throw new DanglingRefError_js_1.DanglingRefError($ref);
206
209
  };
207
210
  exports.toGetRef = toGetRef;
@@ -151,10 +151,7 @@ export declare class OasOperation extends OasBase {
151
151
  *
152
152
  * As OpenAPI defines them: the path item's parameters apply to each of its
153
153
  * operations, and an operation's own parameter with the same name and
154
- * location replaces the path item's. The path item's come first. A
155
- * reference that names nothing (kept under `system.danglingRefs: keep`) is
156
- * left out: it has no name or location, and the parser logged a
157
- * `DANGLING_REF` warning for it.
154
+ * location replaces the path item's. The path item's come first.
158
155
  *
159
156
  * @param filter - only include parameters from specified locations
160
157
  * @returns
@@ -226,16 +226,15 @@ class OasOperation extends OasBase_js_1.OasBase {
226
226
  *
227
227
  * As OpenAPI defines them: the path item's parameters apply to each of its
228
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.
229
+ * location replaces the path item's. The path item's come first.
233
230
  *
234
231
  * @param filter - only include parameters from specified locations
235
232
  * @returns
236
233
  */
237
234
  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));
235
+ return (0, toEffectiveParameters_js_1.toEffectiveParameters)({ own: this.parameters, shared: this.pathItem?.parameters })
236
+ .map(param => param.resolve())
237
+ .filter(param => (filter?.length ? filter.includes(param.location) : true));
239
238
  }
240
239
  /**
241
240
  * Creates an OAS object representation of operation parameters.
@@ -11,14 +11,6 @@ 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.
16
14
  */
17
15
  export declare const toEffectiveParameters: ({ own, shared }: ToEffectiveParametersArgs) => Parameter[];
18
- /**
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.
22
- */
23
- export declare const toResolvedParameters: (parameters: Parameter[]) => OasParameter[];
24
16
  export {};
@@ -1,47 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toResolvedParameters = exports.toEffectiveParameters = void 0;
4
- const DanglingRefError_js_1 = require("../ref/DanglingRefError.js");
3
+ exports.toEffectiveParameters = void 0;
5
4
  /**
6
5
  * The parameters that apply to an operation or webhook, as OpenAPI defines
7
6
  * them: the path item's first, then its own. An own parameter with the same
8
7
  * 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.
11
8
  */
12
9
  const toEffectiveParameters = ({ own = [], shared = [] }) => {
13
10
  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
- ];
11
+ return [...shared.filter(parameter => !ownKeys.has(toParameterKey(parameter))), ...own];
21
12
  };
22
13
  exports.toEffectiveParameters = toEffectiveParameters;
23
- /**
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.
27
- */
28
- const toResolvedParameters = (parameters) => parameters.flatMap(parameter => {
29
- const resolved = toResolvedParameter(parameter);
30
- return resolved === undefined ? [] : [resolved];
31
- });
32
- exports.toResolvedParameters = toResolvedParameters;
33
14
  const toParameterKey = (parameter) => {
34
- const resolved = toResolvedParameter(parameter);
35
- return resolved === undefined ? undefined : `${resolved.location}:${resolved.name}`;
36
- };
37
- const toResolvedParameter = (parameter) => {
38
- try {
39
- return parameter.resolve();
40
- }
41
- catch (error) {
42
- if (DanglingRefError_js_1.DanglingRefError.is(error)) {
43
- return undefined;
44
- }
45
- throw error;
46
- }
15
+ const { name, location } = parameter.resolve();
16
+ return `${location}:${name}`;
47
17
  };
@@ -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,7 +233,7 @@ 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/…`
@@ -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/…`
@@ -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.
@@ -176,7 +176,9 @@ class OasWebhook extends OasBase_js_1.OasBase {
176
176
  * parameters carry the same shape, only their direction is inbound.
177
177
  */
178
178
  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));
179
+ return (0, toEffectiveParameters_js_1.toEffectiveParameters)({ own: this.parameters, shared: this.pathItem?.parameters })
180
+ .map(param => param.resolve())
181
+ .filter(param => (filter?.length ? filter.includes(param.location) : true));
180
182
  }
181
183
  /**
182
184
  * 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
  });