@skmtc/core 0.42.0 → 0.44.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.
- package/esm/context/ParseContext.d.ts +4 -2
- package/esm/context/ParseContext.js +23 -8
- package/esm/context/generateTypes.d.ts +3 -2
- package/esm/helpers/refFns.d.ts +8 -3
- package/esm/helpers/refFns.js +26 -9
- package/esm/oas/operation/Operation.d.ts +19 -4
- package/esm/oas/operation/Operation.js +30 -10
- package/esm/oas/operation/toEffectiveParameters.d.ts +9 -0
- package/esm/oas/operation/toEffectiveParameters.js +27 -0
- package/esm/oas/ref/DanglingRefError.d.ts +18 -3
- package/esm/oas/ref/DanglingRefError.js +17 -4
- package/esm/oas/ref/Ref.d.ts +29 -13
- package/esm/oas/ref/Ref.js +63 -38
- package/esm/oas/webhook/Webhook.d.ts +10 -0
- package/esm/oas/webhook/Webhook.js +13 -1
- package/esm/parse/anyOfSystem.js +6 -8
- package/esm/parse/v3-0/schema/toSchemasV3.js +3 -3
- package/esm/parse/v3-1/schema/toSchemasV3.js +3 -3
- package/esm/parse/v3-2/schema/toSchemasV3.js +3 -3
- package/package.json +1 -1
- package/script/context/ParseContext.d.ts +4 -2
- package/script/context/ParseContext.js +23 -8
- package/script/context/generateTypes.d.ts +3 -2
- package/script/helpers/refFns.d.ts +8 -3
- package/script/helpers/refFns.js +27 -10
- package/script/oas/operation/Operation.d.ts +19 -4
- package/script/oas/operation/Operation.js +29 -9
- package/script/oas/operation/toEffectiveParameters.d.ts +9 -0
- package/script/oas/operation/toEffectiveParameters.js +29 -1
- package/script/oas/ref/DanglingRefError.d.ts +18 -3
- package/script/oas/ref/DanglingRefError.js +17 -4
- package/script/oas/ref/Ref.d.ts +29 -13
- package/script/oas/ref/Ref.js +63 -38
- package/script/oas/webhook/Webhook.d.ts +10 -0
- package/script/oas/webhook/Webhook.js +13 -1
- package/script/parse/anyOfSystem.js +6 -8
- package/script/parse/v3-0/schema/toSchemasV3.js +3 -3
- package/script/parse/v3-1/schema/toSchemasV3.js +3 -3
- package/script/parse/v3-2/schema/toSchemasV3.js +3 -3
package/esm/oas/ref/Ref.js
CHANGED
|
@@ -9,14 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toSiteSchema, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce;
|
|
12
|
+
var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain;
|
|
13
13
|
import "../../_dnt.polyfills.js";
|
|
14
14
|
import { traverseSchema } from '../schemaPath/traverseSchema.js';
|
|
15
15
|
import { toRefName } from '../../helpers/refFns.js';
|
|
16
16
|
import { OasBase } from '../../types/OasBase.js';
|
|
17
17
|
import { DanglingRefError } from './DanglingRefError.js';
|
|
18
18
|
import { changesTarget, changesValues, hasSiblingKeywords, mergeSiblingKeywords, toSkippedSiblings } from '../schema/siblings.js';
|
|
19
|
-
const MAX_LOOKUPS = 10;
|
|
20
19
|
/**
|
|
21
20
|
* Converts a ref type to its plural components path.
|
|
22
21
|
*/
|
|
@@ -68,7 +67,7 @@ const toLookupName = ($ref) => {
|
|
|
68
67
|
* - **Type Safety**: Generic parameter ensures resolved types match the reference type
|
|
69
68
|
* - **Lazy Resolution**: References are resolved on-demand, not during construction
|
|
70
69
|
* - **Chain Resolution**: Handles references that point to other references
|
|
71
|
-
* - **
|
|
70
|
+
* - **Loop Detection**: A chain of references that loops names nothing ({@link OasRef.toLoop})
|
|
72
71
|
* - **Type Validation**: Ensures resolved objects match expected reference types
|
|
73
72
|
*
|
|
74
73
|
* @template T - The type of component this reference points to
|
|
@@ -434,8 +433,8 @@ export class OasRef extends OasBase {
|
|
|
434
433
|
/**
|
|
435
434
|
* Recursively resolves this reference to its final target component.
|
|
436
435
|
*
|
|
437
|
-
* Follows
|
|
438
|
-
*
|
|
436
|
+
* Follows the chain of references until it reaches a component that is
|
|
437
|
+
* not a reference. A schema reference returns the
|
|
439
438
|
* schema at this site: when the keywords next to it, or next to a
|
|
440
439
|
* reference on the chain ({@link SiblingKeywords}), change the target, a
|
|
441
440
|
* copy of the target with them applied. When they change nothing, the
|
|
@@ -445,12 +444,27 @@ export class OasRef extends OasBase {
|
|
|
445
444
|
* model every reference to it sees, and a copy is built once, kept on
|
|
446
445
|
* this reference, and returned on every call.
|
|
447
446
|
*
|
|
448
|
-
* @param lookupsPerformed - Internal counter to prevent infinite recursion
|
|
449
447
|
* @returns The resolved component
|
|
450
|
-
* @throws
|
|
448
|
+
* @throws {DanglingRefError} when a reference on the chain names nothing,
|
|
449
|
+
* or the chain loops ({@link toLoop}), so it never reaches a component.
|
|
450
|
+
* The parser keeps either one only when `system.danglingRefs` lists its kind.
|
|
451
|
+
* @throws Error when a reference on the chain names a component of another
|
|
452
|
+
* kind (see {@link resolveOnce})
|
|
451
453
|
*/
|
|
452
|
-
resolve(
|
|
453
|
-
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this
|
|
454
|
+
resolve() {
|
|
455
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this).resolved;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* The references that form the loop this reference's chain comes back to,
|
|
459
|
+
* starting with the first one it comes back to, or `undefined` when the
|
|
460
|
+
* chain reaches a component. `A` a `$ref` to `B`, and `B` to `A`, form a
|
|
461
|
+
* loop: from `A` the chain goes to `B`, then to `A` again, and never
|
|
462
|
+
* reaches a component. A reference that leads into a loop is not part of it.
|
|
463
|
+
*
|
|
464
|
+
* @throws what {@link resolveOnce} throws, at any step of the chain
|
|
465
|
+
*/
|
|
466
|
+
toLoop() {
|
|
467
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toLoop).call(this, [this]);
|
|
454
468
|
}
|
|
455
469
|
/**
|
|
456
470
|
* Resolves this reference one level. Dispatches on the document's
|
|
@@ -484,8 +498,14 @@ export class OasRef extends OasBase {
|
|
|
484
498
|
}
|
|
485
499
|
return resolved;
|
|
486
500
|
}
|
|
501
|
+
/**
|
|
502
|
+
* The component name the reference looks up.
|
|
503
|
+
*
|
|
504
|
+
* @throws {DanglingRefError} when the `$ref` has no name, such as
|
|
505
|
+
* `#/components/schemas/`: it names nothing
|
|
506
|
+
*/
|
|
487
507
|
toRefName() {
|
|
488
|
-
return
|
|
508
|
+
return toLookupName(this.$ref);
|
|
489
509
|
}
|
|
490
510
|
/**
|
|
491
511
|
* Narrows this reference to a schema reference.
|
|
@@ -548,7 +568,7 @@ export class OasRef extends OasBase {
|
|
|
548
568
|
if (!this.hasSiblings()) {
|
|
549
569
|
return false;
|
|
550
570
|
}
|
|
551
|
-
const { target, resolved } = __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this
|
|
571
|
+
const { target, resolved } = __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toResolution).call(this);
|
|
552
572
|
// Widened from the generic ResolvedRef<T>, so `oasType` narrows them.
|
|
553
573
|
const original = target;
|
|
554
574
|
const applied = resolved;
|
|
@@ -575,35 +595,18 @@ export class OasRef extends OasBase {
|
|
|
575
595
|
* Whether the value is `readOnly` at this site, as Forge reads it: on this
|
|
576
596
|
* reference (`{ allOf: [{ $ref }], readOnly: true }`), or on what it points
|
|
577
597
|
* to, through any chain of references. A `readOnly: false` does not undo
|
|
578
|
-
* another's `true`. `false` for a reference to anything but a schema.
|
|
579
|
-
*
|
|
580
|
-
* @param lookupsPerformed - Internal counter that stops a chain of references with no schema
|
|
598
|
+
* another's `true`. `false` for a reference to anything but a schema. In a
|
|
599
|
+
* loop ({@link toLoop}), which reaches no schema, only the references count.
|
|
581
600
|
*/
|
|
582
|
-
isReadOnly(
|
|
583
|
-
|
|
584
|
-
return true;
|
|
585
|
-
}
|
|
586
|
-
if (lookupsPerformed >= MAX_LOOKUPS) {
|
|
587
|
-
return false;
|
|
588
|
-
}
|
|
589
|
-
const resolved = this.resolveOnce();
|
|
590
|
-
return resolved.isRef() ? resolved.isReadOnly(lookupsPerformed + 1) : resolved.isReadOnly();
|
|
601
|
+
isReadOnly() {
|
|
602
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_someOnChain).call(this, { onRef: ref => ref.readOnly === true, onTarget: target => target.isReadOnly() });
|
|
591
603
|
}
|
|
592
604
|
/**
|
|
593
605
|
* Whether the value is `writeOnly` at this site: on this reference, or on
|
|
594
606
|
* what it points to, as {@link isReadOnly} reads `readOnly`.
|
|
595
|
-
*
|
|
596
|
-
* @param lookupsPerformed - Internal counter that stops a chain of references with no schema
|
|
597
607
|
*/
|
|
598
|
-
isWriteOnly(
|
|
599
|
-
|
|
600
|
-
return true;
|
|
601
|
-
}
|
|
602
|
-
if (lookupsPerformed >= MAX_LOOKUPS) {
|
|
603
|
-
return false;
|
|
604
|
-
}
|
|
605
|
-
const resolved = this.resolveOnce();
|
|
606
|
-
return resolved.isRef() ? resolved.isWriteOnly(lookupsPerformed + 1) : resolved.isWriteOnly();
|
|
608
|
+
isWriteOnly() {
|
|
609
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_someOnChain).call(this, { onRef: ref => ref.writeOnly === true, onTarget: target => target.isWriteOnly() });
|
|
607
610
|
}
|
|
608
611
|
/**
|
|
609
612
|
* Returns the discriminated parsed document this ref resolves
|
|
@@ -637,15 +640,21 @@ export class OasRef extends OasBase {
|
|
|
637
640
|
};
|
|
638
641
|
}
|
|
639
642
|
}
|
|
640
|
-
_OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_instances = new WeakSet(), _OasRef_toResolution = function _OasRef_toResolution(
|
|
643
|
+
_OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_instances = new WeakSet(), _OasRef_toResolution = function _OasRef_toResolution() {
|
|
641
644
|
if (__classPrivateFieldGet(this, _OasRef_resolution, "f") !== undefined) {
|
|
642
645
|
return __classPrivateFieldGet(this, _OasRef_resolution, "f");
|
|
643
646
|
}
|
|
644
|
-
|
|
645
|
-
|
|
647
|
+
const loop = this.toLoop();
|
|
648
|
+
if (loop !== undefined) {
|
|
649
|
+
throw new DanglingRefError(this.$ref, { loop: loop.map(({ $ref }) => $ref) });
|
|
650
|
+
}
|
|
651
|
+
return __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toChainResolution).call(this);
|
|
652
|
+
}, _OasRef_toChainResolution = function _OasRef_toChainResolution() {
|
|
653
|
+
if (__classPrivateFieldGet(this, _OasRef_resolution, "f") !== undefined) {
|
|
654
|
+
return __classPrivateFieldGet(this, _OasRef_resolution, "f");
|
|
646
655
|
}
|
|
647
656
|
const resolved = this.resolveOnce();
|
|
648
|
-
const target = resolved.isRef() ? resolved
|
|
657
|
+
const target = resolved.isRef() ? __classPrivateFieldGet(resolved, _OasRef_instances, "m", _OasRef_toChainResolution).call(resolved).resolved : resolved;
|
|
649
658
|
const resolution = { target, resolved: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toSiteSchema).call(this, target) };
|
|
650
659
|
__classPrivateFieldSet(this, _OasRef_resolution, resolution, "f");
|
|
651
660
|
return resolution;
|
|
@@ -661,6 +670,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
661
670
|
// A schema's copy is a schema of the same class. TypeScript cannot relate
|
|
662
671
|
// OasSchema to ResolvedRef<T> for a generic T, as in resolveOnce().
|
|
663
672
|
return changesTarget(copy, component, this) ? copy : target;
|
|
673
|
+
}, _OasRef_toLoop = function _OasRef_toLoop(followed) {
|
|
674
|
+
const next = this.resolveOnce();
|
|
675
|
+
if (!next.isRef()) {
|
|
676
|
+
return undefined;
|
|
677
|
+
}
|
|
678
|
+
const index = followed.indexOf(next);
|
|
679
|
+
return index === -1 ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_toLoop).call(next, [...followed, next]) : followed.slice(index);
|
|
664
680
|
}, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document, refName) {
|
|
665
681
|
// A `#/components/<bucket>/<name>` ref names its bucket. A request body
|
|
666
682
|
// that is a `$ref` to `#/components/schemas/Pet` names a schema, so it is
|
|
@@ -702,4 +718,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
702
718
|
// oasType check catch any caller that constructed a non-schema
|
|
703
719
|
// ref pointing at a GQL document.
|
|
704
720
|
return document.registry.schemas[refName];
|
|
721
|
+
}, _OasRef_someOnChain = function _OasRef_someOnChain(check, passed = new Set()) {
|
|
722
|
+
if (check.onRef(this)) {
|
|
723
|
+
return true;
|
|
724
|
+
}
|
|
725
|
+
if (passed.has(this)) {
|
|
726
|
+
return false;
|
|
727
|
+
}
|
|
728
|
+
const next = this.resolveOnce();
|
|
729
|
+
return next.isRef() ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_someOnChain).call(next, check, new Set([...passed, this])) : check.onTarget(next);
|
|
705
730
|
};
|
|
@@ -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
|
/**
|
|
@@ -166,14 +166,26 @@ export class OasWebhook extends OasBase {
|
|
|
166
166
|
toPayloadSchema(mediaType) {
|
|
167
167
|
return this.toPayload()?.toSchema(mediaType);
|
|
168
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* The inbound parameters that apply to this webhook, path item parameters
|
|
171
|
+
* included, with references unresolved. Mirrors
|
|
172
|
+
* {@link OasOperation.toEffectiveParameters}.
|
|
173
|
+
*
|
|
174
|
+
* @returns the parameters, path item's first
|
|
175
|
+
*/
|
|
176
|
+
toEffectiveParameters() {
|
|
177
|
+
return toEffectiveParameters({ own: this.parameters, shared: this.pathItem?.parameters });
|
|
178
|
+
}
|
|
169
179
|
/**
|
|
170
180
|
* Resolve the inbound parameters (e.g. the signature/headers a handler
|
|
171
181
|
* receives), optionally filtered by location. Mirrors
|
|
172
182
|
* {@link OasOperation.toParams}, path item parameters included; the
|
|
173
183
|
* parameters carry the same shape, only their direction is inbound.
|
|
184
|
+
*
|
|
185
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
174
186
|
*/
|
|
175
187
|
toParams(filter) {
|
|
176
|
-
return toEffectiveParameters(
|
|
188
|
+
return this.toEffectiveParameters()
|
|
177
189
|
.map(param => param.resolve())
|
|
178
190
|
.filter(param => (filter?.length ? filter.includes(param.location) : true));
|
|
179
191
|
}
|
package/esm/parse/anyOfSystem.js
CHANGED
|
@@ -30,13 +30,11 @@ const isScalarMember = (member) => {
|
|
|
30
30
|
return (Array.isArray(fields.enum) &&
|
|
31
31
|
fields.enum.every(value => value === null || SCALAR_VALUE_TYPES.includes(typeof value)));
|
|
32
32
|
};
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return steps < 10 ? toMemberSchema(getRef(member), getRef, steps + 1) : undefined;
|
|
39
|
-
};
|
|
33
|
+
/**
|
|
34
|
+
* The schema a member names. `getRef` follows the whole chain of `$ref`s, and
|
|
35
|
+
* a chain that loops names nothing, as in `toGetRef`.
|
|
36
|
+
*/
|
|
37
|
+
const toMemberSchema = (member, getRef) => ('$ref' in member ? getRef(member) : member);
|
|
40
38
|
/**
|
|
41
39
|
* Whether `system.anyOf: unknown` reads an `anyOf` as any value, as
|
|
42
40
|
* Cloudflare's `cf` reads it: when it has two or more members, not counting a
|
|
@@ -52,7 +50,7 @@ export const isUnknownAnyOf = ({ members, setting, getRef }) => {
|
|
|
52
50
|
return false;
|
|
53
51
|
}
|
|
54
52
|
const values = members.filter(member => !isNullMember(member)).map(member => toMemberSchema(member, getRef));
|
|
55
|
-
return values.length > 1 && !values.every(
|
|
53
|
+
return values.length > 1 && !values.every(isScalarMember);
|
|
56
54
|
};
|
|
57
55
|
/**
|
|
58
56
|
* `schema` with its other keywords and without an `anyOf` that
|
|
@@ -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, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
181
181
|
system
|
|
182
182
|
});
|
|
183
183
|
logAllOfContradictions({ system, stackTrail, parent: schema, context });
|
|
@@ -193,7 +193,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
193
193
|
schema: withoutNullMembers(schema, 'oneOf'),
|
|
194
194
|
// A member's own `allOf`, or a member merged with the keywords beside
|
|
195
195
|
// the `oneOf`, is merged here, so it follows `allOfMember` too.
|
|
196
|
-
getRef: toGetRef(context.documentObject,
|
|
196
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
197
197
|
system,
|
|
198
198
|
groupType: 'oneOf'
|
|
199
199
|
});
|
|
@@ -262,7 +262,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
262
262
|
const merged = mergeUnion({
|
|
263
263
|
schema: withoutNullMembers(schema, 'anyOf'),
|
|
264
264
|
// As for `oneOf`: what is merged here follows `allOfMember`.
|
|
265
|
-
getRef: toGetRef(context.documentObject,
|
|
265
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
266
266
|
system,
|
|
267
267
|
groupType: 'anyOf'
|
|
268
268
|
});
|
|
@@ -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, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
233
233
|
normalize: normalizeMergeMember,
|
|
234
234
|
system
|
|
235
235
|
});
|
|
@@ -263,7 +263,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
263
263
|
schema: withoutNull,
|
|
264
264
|
// A member's own `allOf`, or a member merged with the keywords beside
|
|
265
265
|
// the `oneOf`, is merged here, so it follows `allOfMember` too.
|
|
266
|
-
getRef: toGetRef(context.documentObject,
|
|
266
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
267
267
|
normalize: normalizeMergeMember,
|
|
268
268
|
system,
|
|
269
269
|
groupType: 'oneOf'
|
|
@@ -345,7 +345,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
345
345
|
const merged = mergeUnion({
|
|
346
346
|
schema: withoutNull,
|
|
347
347
|
// As for `oneOf`: what is merged here follows `allOfMember`.
|
|
348
|
-
getRef: toGetRef(context.documentObject,
|
|
348
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
349
349
|
normalize: normalizeMergeMember,
|
|
350
350
|
system,
|
|
351
351
|
groupType: 'anyOf'
|
|
@@ -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, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
233
233
|
normalize: normalizeMergeMember,
|
|
234
234
|
system
|
|
235
235
|
});
|
|
@@ -263,7 +263,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
263
263
|
schema: withoutNull,
|
|
264
264
|
// A member's own `allOf`, or a member merged with the keywords beside
|
|
265
265
|
// the `oneOf`, is merged here, so it follows `allOfMember` too.
|
|
266
|
-
getRef: toGetRef(context.documentObject,
|
|
266
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
267
267
|
normalize: normalizeMergeMember,
|
|
268
268
|
system,
|
|
269
269
|
groupType: 'oneOf'
|
|
@@ -345,7 +345,7 @@ export const toSchemaV3 = ({ schema, stackTrail, context }) => {
|
|
|
345
345
|
const merged = mergeUnion({
|
|
346
346
|
schema: withoutNull,
|
|
347
347
|
// As for `oneOf`: what is merged here follows `allOfMember`.
|
|
348
|
-
getRef: toGetRef(context.documentObject,
|
|
348
|
+
getRef: toGetRef(context.documentObject, error => context.toDanglingAllOfMember({ error, stackTrail })),
|
|
349
349
|
normalize: normalizeMergeMember,
|
|
350
350
|
system,
|
|
351
351
|
groupType: 'anyOf'
|
package/package.json
CHANGED
|
@@ -30,6 +30,7 @@ import type { GqlParseOptions, LogAtArgs, LogIssueArgs, LogIssueAtArgs, LogIssue
|
|
|
30
30
|
import type { ParseIssue } from './ParseIssue.js';
|
|
31
31
|
import type { OasRef } from '../oas/ref/Ref.js';
|
|
32
32
|
import type { OasRefData } from '../oas/ref/ref-types.js';
|
|
33
|
+
import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
|
|
33
34
|
export type { ParseIssue, GqlIssueType } from './ParseIssue.js';
|
|
34
35
|
export type { GqlParseOptions, LogAtArgs, LogIssueArgs, LogIssueAtArgs, LogIssueNoKeyArgs, LogSkippedValuesArgs, ParseContextType, ParseErrorInput, ParseIssueInput, ParseWarningInput } from './parseTypes.js';
|
|
35
36
|
type OasProtocolState = {
|
|
@@ -53,7 +54,8 @@ type GqlProtocolState = {
|
|
|
53
54
|
};
|
|
54
55
|
type ProtocolState = OasProtocolState | GqlProtocolState;
|
|
55
56
|
type ToDanglingAllOfMemberArgs = {
|
|
56
|
-
|
|
57
|
+
/** Why the member names nothing: no schema has its name, or its `$ref`s loop. */
|
|
58
|
+
error: DanglingRefError;
|
|
57
59
|
/** The schema that holds the `allOf`. */
|
|
58
60
|
stackTrail: StackTrail;
|
|
59
61
|
};
|
|
@@ -182,7 +184,7 @@ export declare class ParseContext {
|
|
|
182
184
|
* removed. It is separate from `schema`: here core decides, at parse, and
|
|
183
185
|
* the generator never sees the member.
|
|
184
186
|
*/
|
|
185
|
-
toDanglingAllOfMember({
|
|
187
|
+
toDanglingAllOfMember({ error, stackTrail }: ToDanglingAllOfMemberArgs): OpenAPIV3.SchemaObject;
|
|
186
188
|
/**
|
|
187
189
|
* Register an error against a ref key — typically called when the
|
|
188
190
|
* 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_removeHolder;
|
|
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_toRefError, _ParseContext_toLoopOf, _ParseContext_removeHolder;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ParseContext = void 0;
|
|
16
16
|
/**
|
|
@@ -404,15 +404,14 @@ class ParseContext {
|
|
|
404
404
|
* removed. It is separate from `schema`: here core decides, at parse, and
|
|
405
405
|
* the generator never sees the member.
|
|
406
406
|
*/
|
|
407
|
-
toDanglingAllOfMember({
|
|
408
|
-
const error = new DanglingRefError_js_1.DanglingRefError($ref);
|
|
407
|
+
toDanglingAllOfMember({ error, stackTrail }) {
|
|
409
408
|
if (!this.system.danglingRefs?.includes('allOfMember')) {
|
|
410
409
|
throw error;
|
|
411
410
|
}
|
|
412
411
|
this.logIssueNoKey({
|
|
413
412
|
level: 'warning',
|
|
414
413
|
message: `${error.message}. It is left out of the allOf merge (system.danglingRefs lists 'allOfMember').`,
|
|
415
|
-
parent: { $ref },
|
|
414
|
+
parent: { $ref: error.ref },
|
|
416
415
|
stackTrail,
|
|
417
416
|
type: 'DANGLING_REF'
|
|
418
417
|
});
|
|
@@ -688,10 +687,8 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
688
687
|
if (__classPrivateFieldGet(this, _ParseContext_refErrors, "f").has(toRefKey(ref.$ref))) {
|
|
689
688
|
return;
|
|
690
689
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
catch (error) {
|
|
690
|
+
const error = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toRefError).call(this, ref);
|
|
691
|
+
if (error !== undefined) {
|
|
695
692
|
if (!DanglingRefError_js_1.DanglingRefError.is(error)) {
|
|
696
693
|
const message = error instanceof Error ? error.message : String(error);
|
|
697
694
|
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
|
|
@@ -722,6 +719,24 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
722
719
|
}
|
|
723
720
|
}
|
|
724
721
|
});
|
|
722
|
+
}, _ParseContext_toRefError = function _ParseContext_toRefError(ref) {
|
|
723
|
+
try {
|
|
724
|
+
ref.resolveOnce();
|
|
725
|
+
}
|
|
726
|
+
catch (error) {
|
|
727
|
+
return error;
|
|
728
|
+
}
|
|
729
|
+
const loop = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toLoopOf).call(this, ref);
|
|
730
|
+
return loop === undefined ? undefined : new DanglingRefError_js_1.DanglingRefError(ref.$ref, { loop: loop.map(({ $ref }) => $ref) });
|
|
731
|
+
}, _ParseContext_toLoopOf = function _ParseContext_toLoopOf(ref) {
|
|
732
|
+
try {
|
|
733
|
+
const loop = ref.toLoop();
|
|
734
|
+
return loop?.includes(ref) ? loop : undefined;
|
|
735
|
+
}
|
|
736
|
+
catch {
|
|
737
|
+
// A ref further on names nothing or the wrong kind: it reports that itself.
|
|
738
|
+
return undefined;
|
|
739
|
+
}
|
|
725
740
|
}, _ParseContext_removeHolder = function _ParseContext_removeHolder({ consumer, ref, error, type, message }) {
|
|
726
741
|
this.logIssueNoKey({
|
|
727
742
|
level: 'error',
|
|
@@ -185,8 +185,9 @@ export type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3
|
|
|
185
185
|
* of two or more members as any value. The schema keeps its other keywords.
|
|
186
186
|
* One for each schema.
|
|
187
187
|
*
|
|
188
|
-
* `DANGLING_REF` — a `$ref` names nothing in the document
|
|
189
|
-
*
|
|
188
|
+
* `DANGLING_REF` — a `$ref` names nothing in the document: no component has
|
|
189
|
+
* its name, or it is part of a loop of `$ref`s (`A` is a `$ref` to `B`, and
|
|
190
|
+
* `B` to `A`). One for each place the `$ref` is written. A `warning` when `system.danglingRefs` lists
|
|
190
191
|
* the `$ref`'s kind: the ref stays, and resolving it throws
|
|
191
192
|
* `DanglingRefError`; with `allOfMember` listed, a `$ref` that core merges
|
|
192
193
|
* (in an `allOf`, or in a `oneOf` or `anyOf` member) is left out of the
|
|
@@ -2,6 +2,7 @@ import "../_dnt.polyfills.js";
|
|
|
2
2
|
import type { RefName } from '../types/RefName.js';
|
|
3
3
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
4
4
|
import type { ReferenceObject } from '../parse/v3-0/_merge-all-of/types.js';
|
|
5
|
+
import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
|
|
5
6
|
/**
|
|
6
7
|
* Extracts a reference name from an OpenAPI $ref string.
|
|
7
8
|
*
|
|
@@ -121,7 +122,8 @@ export declare const isRef: (value: unknown) => value is Ref;
|
|
|
121
122
|
* @param oasDocument - The OpenAPI document containing the schemas to resolve against
|
|
122
123
|
* @returns A function that resolves reference objects to schema objects
|
|
123
124
|
*
|
|
124
|
-
* @throws {DanglingRefError} When a reference names no schema in the document
|
|
125
|
+
* @throws {DanglingRefError} When a reference names no schema in the document,
|
|
126
|
+
* or its chain of references loops, unless `onDangling` reads something in its place
|
|
125
127
|
*
|
|
126
128
|
* @example Basic usage
|
|
127
129
|
* ```typescript
|
|
@@ -172,6 +174,9 @@ export declare const isRef: (value: unknown) => value is Ref;
|
|
|
172
174
|
* ```
|
|
173
175
|
*/
|
|
174
176
|
export declare const toGetRef: (oasDocument: OpenAPIV3.Document, onDangling?: OnDangling) => ({ $ref }: ReferenceObject) => OpenAPIV3.SchemaObject;
|
|
175
|
-
/**
|
|
176
|
-
|
|
177
|
+
/**
|
|
178
|
+
* What a resolver reads in place of a `$ref` that names nothing: no schema
|
|
179
|
+
* has its name, or its chain of `$ref`s loops. It may throw `error`.
|
|
180
|
+
*/
|
|
181
|
+
type OnDangling = (error: DanglingRefError) => OpenAPIV3.SchemaObject;
|
|
177
182
|
export {};
|
package/script/helpers/refFns.js
CHANGED
|
@@ -143,7 +143,8 @@ exports.isRef = isRef;
|
|
|
143
143
|
* @param oasDocument - The OpenAPI document containing the schemas to resolve against
|
|
144
144
|
* @returns A function that resolves reference objects to schema objects
|
|
145
145
|
*
|
|
146
|
-
* @throws {DanglingRefError} When a reference names no schema in the document
|
|
146
|
+
* @throws {DanglingRefError} When a reference names no schema in the document,
|
|
147
|
+
* or its chain of references loops, unless `onDangling` reads something in its place
|
|
147
148
|
*
|
|
148
149
|
* @example Basic usage
|
|
149
150
|
* ```typescript
|
|
@@ -193,18 +194,34 @@ exports.isRef = isRef;
|
|
|
193
194
|
* }
|
|
194
195
|
* ```
|
|
195
196
|
*/
|
|
196
|
-
const toGetRef = (oasDocument, onDangling) => ({ $ref }) => {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
197
|
+
const toGetRef = (oasDocument, onDangling) => ({ $ref }) => toTargetSchema({ oasDocument, onDangling, $ref, followed: [] });
|
|
198
|
+
exports.toGetRef = toGetRef;
|
|
199
|
+
/**
|
|
200
|
+
* The schema at the end of the chain of `$ref`s. A `$ref` that names nothing,
|
|
201
|
+
* or a chain that comes back to a component it has passed (`A` is a `$ref`
|
|
202
|
+
* to `B`, and `B` to `A`), gives `onDangling` a `DanglingRefError`, or throws it.
|
|
203
|
+
*/
|
|
204
|
+
const toTargetSchema = ({ oasDocument, onDangling, $ref, followed }) => {
|
|
205
|
+
const item = oasDocument.components?.schemas?.[(0, exports.toRefName)($ref)];
|
|
206
|
+
if (!item) {
|
|
207
|
+
return toDangling(onDangling, new DanglingRefError_js_1.DanglingRefError($ref));
|
|
201
208
|
}
|
|
202
|
-
if (item) {
|
|
209
|
+
if (!(0, exports.isRef)(item)) {
|
|
203
210
|
return item;
|
|
204
211
|
}
|
|
212
|
+
const passed = [...followed, $ref];
|
|
213
|
+
const loopStart = passed.findIndex(each => (0, exports.toRefName)(each) === (0, exports.toRefName)(item.$ref));
|
|
214
|
+
if (loopStart === -1) {
|
|
215
|
+
return toTargetSchema({ oasDocument, onDangling, $ref: item.$ref, followed: passed });
|
|
216
|
+
}
|
|
217
|
+
// The `$ref`s written in the loop's components: each one after the `$ref`
|
|
218
|
+
// that first named one of them, as `OasRef.toLoop` gives them.
|
|
219
|
+
const loop = [...passed.slice(loopStart + 1), item.$ref];
|
|
220
|
+
return toDangling(onDangling, new DanglingRefError_js_1.DanglingRefError(passed[0] ?? $ref, { loop }));
|
|
221
|
+
};
|
|
222
|
+
const toDangling = (onDangling, error) => {
|
|
205
223
|
if (onDangling) {
|
|
206
|
-
return onDangling(
|
|
224
|
+
return onDangling(error);
|
|
207
225
|
}
|
|
208
|
-
throw
|
|
226
|
+
throw error;
|
|
209
227
|
};
|
|
210
|
-
exports.toGetRef = toGetRef;
|
|
@@ -147,14 +147,26 @@ export declare class OasOperation extends OasBase {
|
|
|
147
147
|
*/
|
|
148
148
|
traverse(path: SchemaPath, mediaType?: string): OasSchema | OasRef<'schema'>;
|
|
149
149
|
/**
|
|
150
|
-
*
|
|
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
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
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}.
|
|
155
166
|
*
|
|
156
167
|
* @param filter - only include parameters from specified locations
|
|
157
168
|
* @returns
|
|
169
|
+
* @throws {DanglingRefError} when a parameter is a reference that names nothing
|
|
158
170
|
*/
|
|
159
171
|
toParams(filter?: OasParameterLocation[]): OasParameter[];
|
|
160
172
|
/**
|
|
@@ -169,6 +181,9 @@ export declare class OasOperation extends OasBase {
|
|
|
169
181
|
*
|
|
170
182
|
* @param options - Conversion options for nested components
|
|
171
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
|
|
172
187
|
*/
|
|
173
188
|
toJsonSchema(options: ToJsonSchemaOptions): OpenAPIV3.OperationObject;
|
|
174
189
|
/**
|