@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
@@ -2,6 +2,7 @@ import { decomposeUnion } 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, system, groupType }) => {
6
7
  const { beforeExcluded, decomposed, afterExcluded } = decomposeUnion({ schema, groupType });
7
8
  // if (decomposed.length === 1) {
@@ -49,13 +50,20 @@ export const toOwnSystem = (system) => ({
49
50
  * ({@link toOwnSystem}). Inside an outer first pass under `latestWins`, a
50
51
  * cross product with no pair that merges fails its pair: the outer pass then
51
52
  * leaves the pair out, or lets the later member win.
53
+ *
54
+ * A `$ref` that names nothing is not a contradiction, so its pair is not left
55
+ * out for it: the `DanglingRefError` is thrown on, and `system.danglingRefs`
56
+ * decides (`allOfMember`).
52
57
  */
53
58
  const mergePairs = ({ pairs, merge, system }) => {
54
59
  const mergeEach = (pairSystem) => pairs.flatMap(pair => {
55
60
  try {
56
61
  return [merge(pair, pairSystem)];
57
62
  }
58
- catch (_error) {
63
+ catch (error) {
64
+ if (DanglingRefError.is(error)) {
65
+ throw error;
66
+ }
59
67
  return [];
60
68
  }
61
69
  });
@@ -177,7 +177,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
177
177
  const system = toAllOfSystem(context);
178
178
  const merged = mergeIntersection({
179
179
  schema,
180
- getRef: toGetRef(context.documentObject),
180
+ getRef: toGetRef(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
181
181
  system
182
182
  });
183
183
  logAllOfContradictions({ system, stackTrail, parent: schema, context });
@@ -191,7 +191,9 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
191
191
  const merged = mergeUnion({
192
192
  // A null member makes the union nullable: `oneOf: [$ref, null]` is a nullable reference.
193
193
  schema: withoutNullMembers(schema, 'oneOf'),
194
- getRef: toGetRef(context.documentObject),
194
+ // A member's own `allOf`, or a member merged with the keywords beside
195
+ // the `oneOf`, is merged here, so it follows `allOfMember` too.
196
+ getRef: toGetRef(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
195
197
  system,
196
198
  groupType: 'oneOf'
197
199
  });
@@ -259,7 +261,8 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
259
261
  const system = toAllOfSystem(context);
260
262
  const merged = mergeUnion({
261
263
  schema: withoutNullMembers(schema, 'anyOf'),
262
- getRef: toGetRef(context.documentObject),
264
+ // As for `oneOf`: what is merged here follows `allOfMember`.
265
+ getRef: toGetRef(context.documentObject, $ref => context.toDanglingAllOfMember({ $ref, stackTrail })),
263
266
  system,
264
267
  groupType: 'anyOf'
265
268
  });
@@ -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'
@@ -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.43.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;
@@ -147,17 +147,26 @@ export declare class OasOperation extends OasBase {
147
147
  */
148
148
  traverse(path: SchemaPath, mediaType?: string): OasSchema | OasRef<'schema'>;
149
149
  /**
150
- * Resolve all parameters and optionally filter by location.
150
+ * The parameters that apply to this operation, as OpenAPI defines them: the
151
+ * path item's parameters apply to each of its operations, and an operation's
152
+ * own parameter with the same name and location replaces the path item's.
153
+ * The path item's come first.
151
154
  *
152
- * As OpenAPI defines them: the path item's parameters apply to each of its
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.
155
+ * References stay references, so a caller can resolve each one on its own.
156
+ * A reference that names nothing (kept when `system.danglingRefs` lists
157
+ * `parameter`) keeps its place, and resolving it throws `DanglingRefError`.
158
+ * {@link OasOperation.toParams} resolves them all.
159
+ *
160
+ * @returns the parameters, path item's first
161
+ */
162
+ toEffectiveParameters(): (OasParameter | OasRef<'parameter'>)[];
163
+ /**
164
+ * Resolve all parameters and optionally filter by location: the resolved
165
+ * {@link OasOperation.toEffectiveParameters}.
158
166
  *
159
167
  * @param filter - only include parameters from specified locations
160
168
  * @returns
169
+ * @throws {DanglingRefError} when a parameter is a reference that names nothing
161
170
  */
162
171
  toParams(filter?: OasParameterLocation[]): OasParameter[];
163
172
  /**
@@ -172,6 +181,9 @@ export declare class OasOperation extends OasBase {
172
181
  *
173
182
  * @param options - Conversion options for nested components
174
183
  * @returns OpenAPI v3 operation object
184
+ * @throws {DanglingRefError} when a parameter is a reference that names
185
+ * nothing, as {@link OasOperation.toParams} does: there is no parameter to
186
+ * write, and the caller decides what to do
175
187
  */
176
188
  toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.OperationObject;
177
189
  /**