@skmtc/core 0.45.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/anchors/attribute.js +3 -2
- package/esm/context/CoreContext.d.ts +1 -1
- package/esm/context/CoreContext.js +1 -1
- package/esm/context/GenerateContext.d.ts +13 -10
- package/esm/context/GenerateContext.js +36 -25
- package/esm/context/ParseContext.d.ts +3 -0
- package/esm/context/ParseContext.js +151 -39
- package/esm/context/generateTypes.d.ts +7 -6
- package/esm/dsl/GeneratorKeys.d.ts +21 -15
- package/esm/dsl/GeneratorKeys.js +16 -11
- package/esm/dsl/Inserted.d.ts +1 -1
- package/esm/dsl/Inserted.js +1 -1
- package/esm/dsl/model/ModelDriver.d.ts +6 -5
- package/esm/dsl/model/ModelDriver.js +22 -20
- package/esm/dsl/model/toModelEntry.d.ts +18 -18
- package/esm/dsl/model/toModelEntry.js +9 -9
- package/esm/dsl/model/toModelProjectionBase.d.ts +17 -16
- package/esm/dsl/model/toModelProjectionBase.js +12 -8
- package/esm/dsl/model/types.d.ts +26 -17
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
- package/esm/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
- package/esm/dsl/webhook/toWebhookProjectionBase.js +2 -2
- package/esm/helpers/collateExamples.js +35 -17
- package/esm/helpers/refFns.d.ts +108 -43
- package/esm/helpers/refFns.js +166 -57
- package/esm/mod.d.ts +1 -0
- package/esm/mod.js +1 -0
- package/esm/oas/document/Document.d.ts +6 -0
- package/esm/oas/document/Document.js +44 -2
- package/esm/oas/intersection/Intersection.d.ts +122 -0
- package/esm/oas/intersection/Intersection.js +266 -0
- package/esm/oas/mediaType/jsonMediaType.d.ts +1 -1
- package/esm/oas/mediaType/jsonMediaType.js +3 -3
- package/esm/oas/ref/DanglingRefError.d.ts +5 -2
- package/esm/oas/ref/DanglingRefError.js +4 -3
- package/esm/oas/ref/Ref.d.ts +23 -12
- package/esm/oas/ref/Ref.js +68 -72
- package/esm/oas/requestBody/RequestBody.d.ts +1 -1
- package/esm/oas/requestBody/RequestBody.js +1 -1
- package/esm/oas/response/Response.d.ts +1 -1
- package/esm/oas/response/Response.js +1 -1
- package/esm/oas/schema/Schema.d.ts +4 -2
- package/esm/oas/schema/siblings.d.ts +10 -2
- package/esm/oas/schema/siblings.js +87 -22
- package/esm/oas/schemaPath/traverseSchema.d.ts +2 -0
- package/esm/oas/schemaPath/traverseSchema.js +51 -5
- package/esm/parse/allOfSystem.d.ts +3 -0
- package/esm/parse/allOfSystem.js +2 -1
- package/esm/parse/keptIntersection.d.ts +53 -0
- package/esm/parse/keptIntersection.js +155 -0
- package/esm/parse/keptRefs.d.ts +23 -0
- package/esm/parse/keptRefs.js +59 -0
- package/esm/parse/toCyclicRefs.d.ts +8 -0
- package/esm/parse/toCyclicRefs.js +126 -0
- package/esm/parse/toDeclaredTypes.d.ts +20 -0
- package/esm/parse/toDeclaredTypes.js +43 -0
- package/esm/parse/v3-0/_merge-all-of/merge-intersection.js +8 -4
- package/esm/parse/v3-0/_merge-all-of/merge-union.js +7 -1
- package/esm/parse/v3-0/_merge-all-of/merge.js +13 -0
- package/esm/parse/v3-0/_merge-all-of/types.d.ts +3 -0
- package/esm/parse/v3-0/intersection/toIntersection.d.ts +12 -0
- package/esm/parse/v3-0/intersection/toIntersection.js +61 -0
- package/esm/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-0/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-0/schema/toSchemasV3.js +13 -1
- package/esm/parse/v3-1/_merge-all-of/merge-intersection.js +8 -4
- package/esm/parse/v3-1/_merge-all-of/merge-union.js +7 -1
- package/esm/parse/v3-1/_merge-all-of/merge.js +13 -0
- package/esm/parse/v3-1/_merge-all-of/types.d.ts +3 -0
- package/esm/parse/v3-1/intersection/toIntersection.d.ts +12 -0
- package/esm/parse/v3-1/intersection/toIntersection.js +61 -0
- package/esm/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-1/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-1/schema/toSchemasV3.js +15 -2
- package/esm/parse/v3-2/_merge-all-of/merge-intersection.js +8 -4
- package/esm/parse/v3-2/_merge-all-of/merge-union.js +7 -1
- package/esm/parse/v3-2/_merge-all-of/merge.js +13 -0
- package/esm/parse/v3-2/_merge-all-of/types.d.ts +3 -0
- package/esm/parse/v3-2/intersection/toIntersection.d.ts +12 -0
- package/esm/parse/v3-2/intersection/toIntersection.js +61 -0
- package/esm/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-2/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-2/schema/toSchemasV3.js +15 -2
- package/esm/types/GeneratorType.d.ts +1 -1
- package/esm/types/ProjectionOptions.d.ts +1 -1
- package/esm/types/ProjectionOptions.js +1 -1
- package/esm/types/RefName.d.ts +3 -3
- package/esm/types/Settings.d.ts +9 -0
- package/esm/types/Settings.js +2 -1
- package/esm/types/TypeSystem.d.ts +20 -5
- package/package.json +1 -1
- package/script/anchors/attribute.js +3 -2
- package/script/context/CoreContext.d.ts +1 -1
- package/script/context/CoreContext.js +1 -1
- package/script/context/GenerateContext.d.ts +13 -10
- package/script/context/GenerateContext.js +36 -25
- package/script/context/ParseContext.d.ts +3 -0
- package/script/context/ParseContext.js +150 -38
- package/script/context/generateTypes.d.ts +7 -6
- package/script/dsl/GeneratorKeys.d.ts +21 -15
- package/script/dsl/GeneratorKeys.js +16 -11
- package/script/dsl/Inserted.d.ts +1 -1
- package/script/dsl/Inserted.js +1 -1
- package/script/dsl/model/ModelDriver.d.ts +6 -5
- package/script/dsl/model/ModelDriver.js +22 -20
- package/script/dsl/model/toModelEntry.d.ts +18 -18
- package/script/dsl/model/toModelEntry.js +9 -9
- package/script/dsl/model/toModelProjectionBase.d.ts +17 -16
- package/script/dsl/model/toModelProjectionBase.js +12 -8
- package/script/dsl/model/types.d.ts +26 -17
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
- package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
- package/script/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
- package/script/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
- package/script/dsl/webhook/toWebhookProjectionBase.js +2 -2
- package/script/helpers/collateExamples.js +35 -17
- package/script/helpers/refFns.d.ts +108 -43
- package/script/helpers/refFns.js +180 -59
- package/script/mod.d.ts +1 -0
- package/script/mod.js +1 -0
- package/script/oas/document/Document.d.ts +6 -0
- package/script/oas/document/Document.js +44 -2
- package/script/oas/intersection/Intersection.d.ts +122 -0
- package/script/oas/intersection/Intersection.js +270 -0
- package/script/oas/mediaType/jsonMediaType.d.ts +1 -1
- package/script/oas/mediaType/jsonMediaType.js +3 -3
- package/script/oas/ref/DanglingRefError.d.ts +5 -2
- package/script/oas/ref/DanglingRefError.js +4 -3
- package/script/oas/ref/Ref.d.ts +23 -12
- package/script/oas/ref/Ref.js +67 -71
- package/script/oas/requestBody/RequestBody.d.ts +1 -1
- package/script/oas/requestBody/RequestBody.js +1 -1
- package/script/oas/response/Response.d.ts +1 -1
- package/script/oas/response/Response.js +1 -1
- package/script/oas/schema/Schema.d.ts +4 -2
- package/script/oas/schema/siblings.d.ts +10 -2
- package/script/oas/schema/siblings.js +89 -23
- package/script/oas/schemaPath/traverseSchema.d.ts +2 -0
- package/script/oas/schemaPath/traverseSchema.js +50 -4
- package/script/parse/allOfSystem.d.ts +3 -0
- package/script/parse/allOfSystem.js +2 -1
- package/script/parse/keptIntersection.d.ts +53 -0
- package/script/parse/keptIntersection.js +164 -0
- package/script/parse/keptRefs.d.ts +23 -0
- package/script/parse/keptRefs.js +63 -0
- package/script/parse/toCyclicRefs.d.ts +8 -0
- package/script/parse/toCyclicRefs.js +130 -0
- package/script/parse/toDeclaredTypes.d.ts +20 -0
- package/script/parse/toDeclaredTypes.js +48 -0
- package/script/parse/v3-0/_merge-all-of/merge-intersection.js +8 -4
- package/script/parse/v3-0/_merge-all-of/merge-union.js +7 -1
- package/script/parse/v3-0/_merge-all-of/merge.js +13 -0
- package/script/parse/v3-0/_merge-all-of/types.d.ts +3 -0
- package/script/parse/v3-0/intersection/toIntersection.d.ts +12 -0
- package/script/parse/v3-0/intersection/toIntersection.js +65 -0
- package/script/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-0/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-0/schema/toSchemasV3.js +13 -1
- package/script/parse/v3-1/_merge-all-of/merge-intersection.js +8 -4
- package/script/parse/v3-1/_merge-all-of/merge-union.js +7 -1
- package/script/parse/v3-1/_merge-all-of/merge.js +13 -0
- package/script/parse/v3-1/_merge-all-of/types.d.ts +3 -0
- package/script/parse/v3-1/intersection/toIntersection.d.ts +12 -0
- package/script/parse/v3-1/intersection/toIntersection.js +65 -0
- package/script/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-1/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-1/schema/toSchemasV3.js +15 -2
- package/script/parse/v3-2/_merge-all-of/merge-intersection.js +8 -4
- package/script/parse/v3-2/_merge-all-of/merge-union.js +7 -1
- package/script/parse/v3-2/_merge-all-of/merge.js +13 -0
- package/script/parse/v3-2/_merge-all-of/types.d.ts +3 -0
- package/script/parse/v3-2/intersection/toIntersection.d.ts +12 -0
- package/script/parse/v3-2/intersection/toIntersection.js +65 -0
- package/script/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-2/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-2/schema/toSchemasV3.js +15 -2
- package/script/types/GeneratorType.d.ts +1 -1
- package/script/types/ProjectionOptions.d.ts +1 -1
- package/script/types/ProjectionOptions.js +1 -1
- package/script/types/RefName.d.ts +3 -3
- package/script/types/Settings.d.ts +9 -0
- package/script/types/Settings.js +2 -1
- package/script/types/TypeSystem.d.ts +20 -5
package/esm/oas/ref/Ref.js
CHANGED
|
@@ -9,52 +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_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain;
|
|
12
|
+
var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain, _OasRef_toWrittenRef;
|
|
13
13
|
import "../../_dnt.polyfills.js";
|
|
14
14
|
import { traverseSchema } from '../schemaPath/traverseSchema.js';
|
|
15
|
-
import {
|
|
15
|
+
import { isDefaultRefPath, isRemoteRefPath, toComponentsBucket, toRefParts, toRefPathBucket, toRefPointer } 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
|
-
/**
|
|
20
|
-
* Converts a ref type to its plural components path.
|
|
21
|
-
*/
|
|
22
|
-
function refTypeToPluralPath(refType) {
|
|
23
|
-
switch (refType) {
|
|
24
|
-
case 'schema':
|
|
25
|
-
return 'schemas';
|
|
26
|
-
case 'requestBody':
|
|
27
|
-
return 'requestBodies';
|
|
28
|
-
case 'parameter':
|
|
29
|
-
return 'parameters';
|
|
30
|
-
case 'response':
|
|
31
|
-
return 'responses';
|
|
32
|
-
case 'example':
|
|
33
|
-
return 'examples';
|
|
34
|
-
case 'header':
|
|
35
|
-
return 'headers';
|
|
36
|
-
case 'securityScheme':
|
|
37
|
-
return 'securitySchemes';
|
|
38
|
-
case 'link':
|
|
39
|
-
return 'links';
|
|
40
|
-
default: {
|
|
41
|
-
const _exhaustive = refType;
|
|
42
|
-
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* The name `resolveOnce` looks up. `toRefName` throws for a `$ref` whose last
|
|
48
|
-
* segment is empty (`#/components/schemas/`): that `$ref` names nothing.
|
|
49
|
-
*/
|
|
50
|
-
const toLookupName = ($ref) => {
|
|
51
|
-
try {
|
|
52
|
-
return toRefName($ref);
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
throw new DanglingRefError($ref);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
19
|
/**
|
|
59
20
|
* Represents an OpenAPI reference ($ref) in the SKMTC OAS processing system.
|
|
60
21
|
*
|
|
@@ -113,8 +74,8 @@ const toLookupName = ($ref) => {
|
|
|
113
74
|
* function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
|
|
114
75
|
* if (schema.isRef()) {
|
|
115
76
|
* // Handle reference
|
|
116
|
-
* const refName = schema
|
|
117
|
-
* console.log(`Processing reference: ${refName}`);
|
|
77
|
+
* const { refName, refPath } = schema;
|
|
78
|
+
* console.log(`Processing reference: ${refName} in ${refPath}`);
|
|
118
79
|
*
|
|
119
80
|
* // Resolve only when needed
|
|
120
81
|
* const resolved = schema.resolve();
|
|
@@ -176,13 +137,40 @@ export class OasRef extends OasBase {
|
|
|
176
137
|
writable: true,
|
|
177
138
|
value: void 0
|
|
178
139
|
});
|
|
179
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* The JSON Reference, as written: a component (`#/components/<bucket>/<name>`)
|
|
142
|
+
* or any other place in the document (`#/components/schemas/Pet/properties/tag`).
|
|
143
|
+
*/
|
|
180
144
|
Object.defineProperty(this, "$ref", {
|
|
181
145
|
enumerable: true,
|
|
182
146
|
configurable: true,
|
|
183
147
|
writable: true,
|
|
184
148
|
value: void 0
|
|
185
149
|
});
|
|
150
|
+
/**
|
|
151
|
+
* The last segment of the `$ref`'s pointer, unescaped: `Pet` for
|
|
152
|
+
* `#/components/schemas/Pet`, `schema0` for
|
|
153
|
+
* `#/components/schemas/__sharedInput/$defs/schema0`. Empty for a `$ref`
|
|
154
|
+
* that ends in `/`, which names nothing.
|
|
155
|
+
*/
|
|
156
|
+
Object.defineProperty(this, "refName", {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
configurable: true,
|
|
159
|
+
writable: true,
|
|
160
|
+
value: void 0
|
|
161
|
+
});
|
|
162
|
+
/**
|
|
163
|
+
* The pointer before {@link refName}, with no percent escapes: `#/components/schemas`
|
|
164
|
+
* for a schema component, `#/components/schemas/__sharedInput/$defs` for
|
|
165
|
+
* the `$defs` entry above. A generator that names by {@link refName} alone
|
|
166
|
+
* may ignore it.
|
|
167
|
+
*/
|
|
168
|
+
Object.defineProperty(this, "refPath", {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
configurable: true,
|
|
171
|
+
writable: true,
|
|
172
|
+
value: void 0
|
|
173
|
+
});
|
|
186
174
|
/**
|
|
187
175
|
* Use-site nullability (see {@link SiblingKeywords.nullable}). Assigned
|
|
188
176
|
* even when `undefined`, so `'nullable' in ref` is always true and the
|
|
@@ -392,6 +380,9 @@ export class OasRef extends OasBase {
|
|
|
392
380
|
_OasRef_resolution.set(this, void 0);
|
|
393
381
|
this.refType = fields.refType;
|
|
394
382
|
this.$ref = fields.$ref;
|
|
383
|
+
const { refName, refPath } = toRefParts({ $ref: fields.$ref });
|
|
384
|
+
this.refName = refName;
|
|
385
|
+
this.refPath = refPath;
|
|
395
386
|
this.nullable = fields.nullable;
|
|
396
387
|
this.readOnly = fields.readOnly;
|
|
397
388
|
this.writeOnly = fields.writeOnly;
|
|
@@ -468,8 +459,9 @@ export class OasRef extends OasBase {
|
|
|
468
459
|
}
|
|
469
460
|
/**
|
|
470
461
|
* Resolves this reference one level. Dispatches on the document's
|
|
471
|
-
* protocol — OAS reads from `document.components.<bucket
|
|
472
|
-
*
|
|
462
|
+
* protocol — OAS reads a component from `document.components.<bucket>`,
|
|
463
|
+
* and any other target from the targets the parser kept by pointer
|
|
464
|
+
* (`OasDocument.toRefTarget`); GQL reads from `document.registry.schemas`.
|
|
473
465
|
*
|
|
474
466
|
* @returns Either the resolved component or another reference in the chain
|
|
475
467
|
* @throws {DanglingRefError} when the reference names nothing in the
|
|
@@ -479,12 +471,14 @@ export class OasRef extends OasBase {
|
|
|
479
471
|
* `requestBody` ref to `#/components/schemas/…`
|
|
480
472
|
*/
|
|
481
473
|
resolveOnce() {
|
|
482
|
-
|
|
474
|
+
if (this.refName === '') {
|
|
475
|
+
throw new DanglingRefError(this.$ref);
|
|
476
|
+
}
|
|
483
477
|
const resolved = __classPrivateFieldGet(this, _OasRef_document, "f").type === 'oas'
|
|
484
|
-
? __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveOasOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value
|
|
485
|
-
: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveGqlOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value
|
|
478
|
+
? __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveOasOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value)
|
|
479
|
+
: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveGqlOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value);
|
|
486
480
|
if (!resolved) {
|
|
487
|
-
throw new DanglingRefError(this.$ref);
|
|
481
|
+
throw new DanglingRefError(this.$ref, { remote: isRemoteRefPath(this.refPath) });
|
|
488
482
|
}
|
|
489
483
|
if (resolved.isRef()) {
|
|
490
484
|
if (resolved.refType !== this.refType) {
|
|
@@ -498,15 +492,6 @@ export class OasRef extends OasBase {
|
|
|
498
492
|
}
|
|
499
493
|
return resolved;
|
|
500
494
|
}
|
|
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
|
-
*/
|
|
507
|
-
toRefName() {
|
|
508
|
-
return toLookupName(this.$ref);
|
|
509
|
-
}
|
|
510
495
|
/**
|
|
511
496
|
* Narrows this reference to a schema reference.
|
|
512
497
|
*
|
|
@@ -628,16 +613,12 @@ export class OasRef extends OasBase {
|
|
|
628
613
|
const resolved = this.resolve().toJsonSchema({ resolve });
|
|
629
614
|
return resolved;
|
|
630
615
|
}
|
|
631
|
-
const ref = {
|
|
632
|
-
$ref: `#/components/${refTypeToPluralPath(this.refType)}/${this.toRefName()}`
|
|
633
|
-
};
|
|
616
|
+
const ref = { $ref: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toWrittenRef).call(this) };
|
|
634
617
|
return ref;
|
|
635
618
|
}
|
|
636
619
|
/** `{ $ref }` only, as {@link toJsonSchema} without `resolve` (skmtc/skmtc#338). */
|
|
637
620
|
toJSON() {
|
|
638
|
-
return {
|
|
639
|
-
$ref: `#/components/${refTypeToPluralPath(this.refType)}/${this.toRefName()}`
|
|
640
|
-
};
|
|
621
|
+
return { $ref: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toWrittenRef).call(this) };
|
|
641
622
|
}
|
|
642
623
|
}
|
|
643
624
|
_OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_instances = new WeakSet(), _OasRef_toResolution = function _OasRef_toResolution() {
|
|
@@ -677,15 +658,21 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
677
658
|
}
|
|
678
659
|
const index = followed.indexOf(next);
|
|
679
660
|
return index === -1 ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_toLoop).call(next, [...followed, next]) : followed.slice(index);
|
|
680
|
-
}, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document
|
|
661
|
+
}, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document) {
|
|
681
662
|
// A `#/components/<bucket>/<name>` ref names its bucket. A request body
|
|
682
663
|
// that is a `$ref` to `#/components/schemas/Pet` names a schema, so it is
|
|
683
|
-
// never looked up in the request bodies.
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
664
|
+
// never looked up in the request bodies. A ref to any other place
|
|
665
|
+
// (`#/components/parameters/limit/schema`) names no bucket: the kind of
|
|
666
|
+
// what it finds is checked in `resolveOnce`.
|
|
667
|
+
const bucket = toRefPathBucket(this.refPath);
|
|
668
|
+
const expected = toComponentsBucket(this.refType);
|
|
669
|
+
if (bucket === undefined) {
|
|
670
|
+
return document.toRefTarget(toRefPointer(this));
|
|
671
|
+
}
|
|
672
|
+
if (bucket !== expected) {
|
|
687
673
|
throw new Error(`Ref type mismatch for "${this.$ref}". Expected a ref into "components/${expected}" but it names one in "components/${bucket}"`);
|
|
688
674
|
}
|
|
675
|
+
const refName = this.refName;
|
|
689
676
|
const c = document.components;
|
|
690
677
|
const refType = this.refType;
|
|
691
678
|
switch (refType) {
|
|
@@ -710,14 +697,14 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
710
697
|
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
711
698
|
}
|
|
712
699
|
}
|
|
713
|
-
}, _OasRef_resolveGqlOnce = function _OasRef_resolveGqlOnce(document
|
|
700
|
+
}, _OasRef_resolveGqlOnce = function _OasRef_resolveGqlOnce(document) {
|
|
714
701
|
// GraphQL only ever creates schema refs — there's no GQL concept
|
|
715
702
|
// of a response/parameter/header/etc. ref. The refType field is
|
|
716
703
|
// still typed by `T` for the OAS variants; on the GQL branch we
|
|
717
704
|
// always do a schema lookup and let the post-lookup refType-vs-
|
|
718
705
|
// oasType check catch any caller that constructed a non-schema
|
|
719
706
|
// ref pointing at a GQL document.
|
|
720
|
-
return document.registry.schemas[refName];
|
|
707
|
+
return document.registry.schemas[this.refName];
|
|
721
708
|
}, _OasRef_someOnChain = function _OasRef_someOnChain(check, passed = new Set()) {
|
|
722
709
|
if (check.onRef(this)) {
|
|
723
710
|
return true;
|
|
@@ -727,4 +714,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
727
714
|
}
|
|
728
715
|
const next = this.resolveOnce();
|
|
729
716
|
return next.isRef() ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_someOnChain).call(next, check, new Set([...passed, this])) : check.onTarget(next);
|
|
717
|
+
}, _OasRef_toWrittenRef = function _OasRef_toWrittenRef() {
|
|
718
|
+
if (this.refName === '') {
|
|
719
|
+
throw new DanglingRefError(this.$ref);
|
|
720
|
+
}
|
|
721
|
+
return isDefaultRefPath({ refPath: this.refPath, refType: this.refType })
|
|
722
|
+
? `#/components/${toComponentsBucket(this.refType)}/${this.refName}`
|
|
723
|
+
: isRemoteRefPath(this.refPath)
|
|
724
|
+
? this.$ref
|
|
725
|
+
: toRefPointer(this).replaceAll('%', '%25');
|
|
730
726
|
};
|
|
@@ -296,7 +296,7 @@ export declare class OasRequestBody extends OasBase {
|
|
|
296
296
|
* `mediaType`, the schema of the JSON media type that {@link toJsonContent}
|
|
297
297
|
* picks: `application/json`, else the first JSON-like type such as
|
|
298
298
|
* `application/json;v=1.0` or `application/vnd.api+json`, else `*\/*`
|
|
299
|
-
* when its schema is an object, array, union or `$ref`.
|
|
299
|
+
* when its schema is an object, array, union, intersection or `$ref`.
|
|
300
300
|
* `undefined` when there is no such media type or it has no schema.
|
|
301
301
|
*/
|
|
302
302
|
toSchema(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
|
|
@@ -319,7 +319,7 @@ export class OasRequestBody extends OasBase {
|
|
|
319
319
|
* `mediaType`, the schema of the JSON media type that {@link toJsonContent}
|
|
320
320
|
* picks: `application/json`, else the first JSON-like type such as
|
|
321
321
|
* `application/json;v=1.0` or `application/vnd.api+json`, else `*\/*`
|
|
322
|
-
* when its schema is an object, array, union or `$ref`.
|
|
322
|
+
* when its schema is an object, array, union, intersection or `$ref`.
|
|
323
323
|
* `undefined` when there is no such media type or it has no schema.
|
|
324
324
|
*/
|
|
325
325
|
toSchema(mediaType) {
|
|
@@ -230,7 +230,7 @@ export declare class OasResponse extends OasBase {
|
|
|
230
230
|
* `mediaType`, the schema of the JSON media type that {@link toJsonContent}
|
|
231
231
|
* picks: `application/json`, else the first JSON-like type such as
|
|
232
232
|
* `application/json;v=1.0` or `application/vnd.api+json`, else `*\/*`
|
|
233
|
-
* when its schema is an object, array, union or `$ref`.
|
|
233
|
+
* when its schema is an object, array, union, intersection or `$ref`.
|
|
234
234
|
* `undefined` when there is no such media type or it has no schema.
|
|
235
235
|
*/
|
|
236
236
|
toSchema(mediaType?: string): OasSchema | OasRef<'schema'> | undefined;
|
|
@@ -259,7 +259,7 @@ export class OasResponse extends OasBase {
|
|
|
259
259
|
* `mediaType`, the schema of the JSON media type that {@link toJsonContent}
|
|
260
260
|
* picks: `application/json`, else the first JSON-like type such as
|
|
261
261
|
* `application/json;v=1.0` or `application/vnd.api+json`, else `*\/*`
|
|
262
|
-
* when its schema is an object, array, union or `$ref`.
|
|
262
|
+
* when its schema is an object, array, union, intersection or `$ref`.
|
|
263
263
|
* `undefined` when there is no such media type or it has no schema.
|
|
264
264
|
*/
|
|
265
265
|
toSchema(mediaType) {
|
|
@@ -7,6 +7,7 @@ import type { OasObject } from '../object/Object.js';
|
|
|
7
7
|
import type { OasString } from '../string/String.js';
|
|
8
8
|
import type { OasUnknown } from '../unknown/Unknown.js';
|
|
9
9
|
import type { OasUnion } from '../union/Union.js';
|
|
10
|
+
import type { OasIntersection } from '../intersection/Intersection.js';
|
|
10
11
|
/**
|
|
11
12
|
* Union type representing all possible OpenAPI Schema objects in the SKMTC system.
|
|
12
13
|
*
|
|
@@ -28,7 +29,8 @@ import type { OasUnion } from '../union/Union.js';
|
|
|
28
29
|
* - **{@link OasObject}**: Object schemas with properties, required fields, and constraints
|
|
29
30
|
* - **{@link OasString}**: String schemas with length constraints, patterns, and formats
|
|
30
31
|
* - **{@link OasUnknown}**: Schemas with unknown or mixed types
|
|
31
|
-
* - **{@link OasUnion}**: Union schemas representing oneOf/anyOf
|
|
32
|
+
* - **{@link OasUnion}**: Union schemas representing oneOf/anyOf constructs
|
|
33
|
+
* - **{@link OasIntersection}**: An allOf that keeps a reference
|
|
32
34
|
*
|
|
33
35
|
* @example Type checking and processing
|
|
34
36
|
* ```typescript
|
|
@@ -108,7 +110,7 @@ import type { OasUnion } from '../union/Union.js';
|
|
|
108
110
|
* }
|
|
109
111
|
* ```
|
|
110
112
|
*/
|
|
111
|
-
export type OasSchema = OasArray | OasBoolean | OasInteger | OasNumber | OasObject | OasString | OasUnknown | OasUnion;
|
|
113
|
+
export type OasSchema = OasArray | OasBoolean | OasInteger | OasNumber | OasObject | OasString | OasUnknown | OasUnion | OasIntersection;
|
|
112
114
|
/**
|
|
113
115
|
* Configuration options for JSON Schema conversion operations.
|
|
114
116
|
*
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { OasSchema } from './Schema.js';
|
|
2
2
|
import type { OasRef } from '../ref/Ref.js';
|
|
3
|
+
import type { OasIntersection } from '../intersection/Intersection.js';
|
|
3
4
|
/**
|
|
4
5
|
* The keywords next to a reference in a one-member `allOf`
|
|
5
6
|
* (`{ allOf: [{ $ref }], minLength: 3, description: '…' }`), the use-site
|
|
@@ -68,7 +69,7 @@ export type SiblingKeywords = {
|
|
|
68
69
|
};
|
|
69
70
|
/** A keyword `clone` can apply. `_type` only has to agree. */
|
|
70
71
|
export type SiblingKeyword = Exclude<keyof SiblingKeywords, '_type'>;
|
|
71
|
-
/** The keywords each schema class's `clone` takes: the fields its type has. */
|
|
72
|
+
/** The keywords each schema class's `clone` takes: the fields its type has, and {@link OBJECT_KEYWORDS} for an intersection. */
|
|
72
73
|
export declare const SIBLINGS_BY_TYPE: Record<OasSchema['type'], SiblingKeyword[]>;
|
|
73
74
|
/**
|
|
74
75
|
* The keywords of `over` merged over those of `base`, for a reference copied
|
|
@@ -98,6 +99,13 @@ export declare const changesValues: (copy: OasSchema, target: OasSchema, sibling
|
|
|
98
99
|
* `OasRef.toSkippedSiblings`.
|
|
99
100
|
*/
|
|
100
101
|
export declare const toSkippedSiblings: (target: OasSchema, siblings: SiblingKeywords, nullable: boolean | undefined) => string[];
|
|
102
|
+
/**
|
|
103
|
+
* The {@link OBJECT_KEYWORDS} next to a reference that say something the
|
|
104
|
+
* members of an intersection do not: a name none of them requires, a property
|
|
105
|
+
* none of them has the same. References in the members count by their target,
|
|
106
|
+
* without the keywords next to them.
|
|
107
|
+
*/
|
|
108
|
+
export declare const toChangedObjectKeywords: (target: OasIntersection, siblings: SiblingKeywords) => SiblingKeyword[];
|
|
101
109
|
/** The annotations of `target` with those of `siblings` applied: a sibling's value wins, and extension fields merge. */
|
|
102
110
|
export declare const toSiblingAnnotations: (target: OasSchema, siblings: SiblingKeywords | undefined) => {
|
|
103
111
|
title: string | undefined;
|
|
@@ -113,7 +121,7 @@ export declare const isIntegerValue: (value: unknown) => value is number;
|
|
|
113
121
|
export declare const isBooleanValue: (value: unknown) => value is boolean;
|
|
114
122
|
export declare const isArrayValue: (value: unknown) => value is unknown[];
|
|
115
123
|
export declare const isObjectValue: (value: unknown) => value is Record<string, unknown>;
|
|
116
|
-
/** {@link isStringValue} and the others, keyed by the type they check for. A union or unknown takes any value. */
|
|
124
|
+
/** {@link isStringValue} and the others, keyed by the type they check for. A union, intersection or unknown takes any value. */
|
|
117
125
|
export declare const VALUE_CHECKS: Record<OasSchema['type'], (value: unknown) => boolean>;
|
|
118
126
|
/** The formats a number and an integer take. A string takes any format. */
|
|
119
127
|
export declare const isNumberFormat: (value: unknown) => value is "float" | "double";
|
|
@@ -22,7 +22,15 @@ const NUMERIC = [
|
|
|
22
22
|
'exclusiveMinimum',
|
|
23
23
|
'exclusiveMaximum'
|
|
24
24
|
];
|
|
25
|
-
/** The keywords
|
|
25
|
+
/** The keywords of an object. An intersection's `clone` takes them as one more member. */
|
|
26
|
+
const OBJECT_KEYWORDS = [
|
|
27
|
+
'properties',
|
|
28
|
+
'required',
|
|
29
|
+
'additionalProperties',
|
|
30
|
+
'minProperties',
|
|
31
|
+
'maxProperties'
|
|
32
|
+
];
|
|
33
|
+
/** The keywords each schema class's `clone` takes: the fields its type has, and {@link OBJECT_KEYWORDS} for an intersection. */
|
|
26
34
|
export const SIBLINGS_BY_TYPE = {
|
|
27
35
|
string: [...DESCRIBING, 'deprecated', 'default', 'enums', 'format', 'minLength', 'maxLength', 'pattern'],
|
|
28
36
|
number: [...DESCRIBING, ...NUMERIC],
|
|
@@ -34,13 +42,10 @@ export const SIBLINGS_BY_TYPE = {
|
|
|
34
42
|
'deprecated',
|
|
35
43
|
'default',
|
|
36
44
|
'enums',
|
|
37
|
-
|
|
38
|
-
'required',
|
|
39
|
-
'additionalProperties',
|
|
40
|
-
'minProperties',
|
|
41
|
-
'maxProperties'
|
|
45
|
+
...OBJECT_KEYWORDS
|
|
42
46
|
],
|
|
43
47
|
union: [...DESCRIBING, 'default'],
|
|
48
|
+
intersection: [...DESCRIBING, 'deprecated', 'default', ...OBJECT_KEYWORDS],
|
|
44
49
|
unknown: DESCRIBING
|
|
45
50
|
};
|
|
46
51
|
/** Every keyword `clone` can apply, for any type. */
|
|
@@ -123,14 +128,21 @@ const BOOLEAN_KEYWORDS = [
|
|
|
123
128
|
* a flag the target already has, and a value equal to the target's change
|
|
124
129
|
* nothing.
|
|
125
130
|
*/
|
|
126
|
-
const toChangedKeywords = (copy, target, siblings) =>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
const toChangedKeywords = (copy, target, siblings) => {
|
|
132
|
+
// An intersection takes these as a member, so it has no field to compare.
|
|
133
|
+
const objectKeywords = target.type === 'intersection' ? toChangedObjectKeywords(target, siblings) : [];
|
|
134
|
+
return SIBLINGS_BY_TYPE[target.type].filter(keyword => {
|
|
135
|
+
if (siblings[keyword] === undefined) {
|
|
136
|
+
return false;
|
|
137
|
+
}
|
|
138
|
+
if (target.type === 'intersection' && OBJECT_KEYWORDS.includes(keyword)) {
|
|
139
|
+
return objectKeywords.includes(keyword);
|
|
140
|
+
}
|
|
141
|
+
const applied = Reflect.get(copy, keyword);
|
|
142
|
+
const original = Reflect.get(target, keyword);
|
|
143
|
+
return BOOLEAN_KEYWORDS.includes(keyword) ? (applied === true) !== (original === true) : !isEqual(applied, original);
|
|
144
|
+
});
|
|
145
|
+
};
|
|
134
146
|
/** Whether the keywords next to a reference change `target` at that site. The engine behind `OasRef.resolve`. */
|
|
135
147
|
export const changesTarget = (copy, target, siblings) => toChangedKeywords(copy, target, siblings).length > 0;
|
|
136
148
|
/**
|
|
@@ -170,23 +182,72 @@ export const toSkippedSiblings = (target, siblings, nullable) => {
|
|
|
170
182
|
return false;
|
|
171
183
|
}
|
|
172
184
|
};
|
|
173
|
-
const type = siblings._type !== undefined && !agrees(siblings._type, target
|
|
185
|
+
const type = siblings._type !== undefined && !agrees(siblings._type, target) ? ['type'] : [];
|
|
174
186
|
const others = SIBLING_KEYWORDS.filter(keyword => isSkipped(keyword, siblings[keyword])).map(toDocumentKeyword);
|
|
175
187
|
return [...type, ...others];
|
|
176
188
|
};
|
|
177
|
-
/**
|
|
178
|
-
|
|
189
|
+
/**
|
|
190
|
+
* The {@link OBJECT_KEYWORDS} next to a reference that say something the
|
|
191
|
+
* members of an intersection do not: a name none of them requires, a property
|
|
192
|
+
* none of them has the same. References in the members count by their target,
|
|
193
|
+
* without the keywords next to them.
|
|
194
|
+
*/
|
|
195
|
+
export const toChangedObjectKeywords = (target, siblings) => {
|
|
196
|
+
const objects = target.toTargetParts().filter(part => part.type === 'object');
|
|
197
|
+
const isSame = (keyword) => objects.some(object => isEqual(object[keyword], siblings[keyword]));
|
|
198
|
+
const isUnchanged = (keyword) => {
|
|
199
|
+
switch (keyword) {
|
|
200
|
+
case 'required':
|
|
201
|
+
return (siblings.required ?? []).every(name => objects.some(object => object.required?.includes(name)));
|
|
202
|
+
case 'properties':
|
|
203
|
+
return Object.keys(siblings.properties ?? {}).every(name => objects.some(object => isEqual(object.properties?.[name], siblings.properties?.[name])));
|
|
204
|
+
case 'additionalProperties':
|
|
205
|
+
case 'minProperties':
|
|
206
|
+
case 'maxProperties':
|
|
207
|
+
return isSame(keyword);
|
|
208
|
+
default:
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
return OBJECT_KEYWORDS.filter(keyword => siblings[keyword] !== undefined && !isUnchanged(keyword));
|
|
213
|
+
};
|
|
179
214
|
/**
|
|
180
215
|
* A `type` next to a reference agrees with the target's when it names it, or
|
|
181
216
|
* `number` for an integer. Next to a union, it agrees when every member,
|
|
182
217
|
* followed through references, has that type (`type: object` next to a
|
|
183
|
-
* `oneOf` of objects): leaving it out then loses nothing.
|
|
218
|
+
* `oneOf` of objects): leaving it out then loses nothing. Next to an
|
|
219
|
+
* intersection, it agrees when one member has that type.
|
|
184
220
|
*/
|
|
185
|
-
const agrees = (type, target
|
|
221
|
+
const agrees = (type, target) => {
|
|
222
|
+
const agreed = new Set();
|
|
223
|
+
// A schema that leads back to itself does not agree by that, so a pass reads
|
|
224
|
+
// it as `false` there. It can agree by another member, so a new pass reads
|
|
225
|
+
// the schemas that agreed, until a pass finds no more of them.
|
|
226
|
+
const runPass = () => {
|
|
227
|
+
const before = agreed.size;
|
|
228
|
+
return agreesInPass({ type, target, agreed, visited: new Set() }) || (agreed.size > before && runPass());
|
|
229
|
+
};
|
|
230
|
+
return runPass();
|
|
231
|
+
};
|
|
232
|
+
const agreesInPass = ({ type, target, agreed, visited }) => {
|
|
233
|
+
if (agreed.has(target)) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
if (visited.has(target)) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
visited.add(target);
|
|
240
|
+
const result = toAgreement(type, target, member => agreesInPass({ type, target: member, agreed, visited }));
|
|
241
|
+
if (result) {
|
|
242
|
+
agreed.add(target);
|
|
243
|
+
}
|
|
244
|
+
return result;
|
|
245
|
+
};
|
|
246
|
+
/** {@link agrees} for one schema, with `agreesInside` for its members. */
|
|
247
|
+
const toAgreement = (type, target, agreesInside) => {
|
|
186
248
|
if (target.type === 'union') {
|
|
187
249
|
try {
|
|
188
|
-
return
|
|
189
|
-
target.members.every(member => agrees(type, member.isRef() ? member.resolve() : member, depth + 1));
|
|
250
|
+
return target.members.every(member => agreesInside(member.isRef() ? member.resolve() : member));
|
|
190
251
|
}
|
|
191
252
|
catch (error) {
|
|
192
253
|
// A member that is a dangling reference has no known type, so it does not agree.
|
|
@@ -196,6 +257,9 @@ const agrees = (type, target, depth) => {
|
|
|
196
257
|
throw error;
|
|
197
258
|
}
|
|
198
259
|
}
|
|
260
|
+
if (target.type === 'intersection') {
|
|
261
|
+
return target.toParts().some(agreesInside);
|
|
262
|
+
}
|
|
199
263
|
return type === target.type || (type === 'number' && target.type === 'integer');
|
|
200
264
|
};
|
|
201
265
|
/** Whether `format` fits a schema of `type`, as `clone` reads it: any string for a string. */
|
|
@@ -227,7 +291,7 @@ export const isBooleanValue = (value) => typeof value === 'boolean';
|
|
|
227
291
|
export const isArrayValue = (value) => Array.isArray(value);
|
|
228
292
|
export const isObjectValue = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
229
293
|
const isAnyValue = (_value) => true;
|
|
230
|
-
/** {@link isStringValue} and the others, keyed by the type they check for. A union or unknown takes any value. */
|
|
294
|
+
/** {@link isStringValue} and the others, keyed by the type they check for. A union, intersection or unknown takes any value. */
|
|
231
295
|
export const VALUE_CHECKS = {
|
|
232
296
|
string: isStringValue,
|
|
233
297
|
number: isNumberValue,
|
|
@@ -236,6 +300,7 @@ export const VALUE_CHECKS = {
|
|
|
236
300
|
array: isArrayValue,
|
|
237
301
|
object: isObjectValue,
|
|
238
302
|
union: isAnyValue,
|
|
303
|
+
intersection: isAnyValue,
|
|
239
304
|
unknown: isAnyValue
|
|
240
305
|
};
|
|
241
306
|
/** The formats a number and an integer take. A string takes any format. */
|
|
@@ -18,6 +18,8 @@ import type { SchemaPath } from '../../types/SchemaPath.js';
|
|
|
18
18
|
* element schema.
|
|
19
19
|
* - **union** → the segment selects a member ({@link selectUnionMember}):
|
|
20
20
|
* `'$Circle'` by refName, `'{type:circle}'` by discriminator, `'[0]'` by index.
|
|
21
|
+
* - **intersection** → the segment is read as for a member, references followed:
|
|
22
|
+
* the last member that has the whole path.
|
|
21
23
|
*
|
|
22
24
|
* A ref is resolved only when the path needs to descend *through* it. Anything
|
|
23
25
|
* the path cannot navigate throws a descriptive, segment-named error: a missing
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toRefParts, toRefPointer } from '../../helpers/refFns.js';
|
|
2
2
|
/**
|
|
3
3
|
* Walk an {@link SchemaPath} into a schema, resolving `$ref`s as it descends.
|
|
4
4
|
*
|
|
@@ -16,6 +16,8 @@ import { toRefName } from '../../helpers/refFns.js';
|
|
|
16
16
|
* element schema.
|
|
17
17
|
* - **union** → the segment selects a member ({@link selectUnionMember}):
|
|
18
18
|
* `'$Circle'` by refName, `'{type:circle}'` by discriminator, `'[0]'` by index.
|
|
19
|
+
* - **intersection** → the segment is read as for a member, references followed:
|
|
20
|
+
* the last member that has the whole path.
|
|
19
21
|
*
|
|
20
22
|
* A ref is resolved only when the path needs to descend *through* it. Anything
|
|
21
23
|
* the path cannot navigate throws a descriptive, segment-named error: a missing
|
|
@@ -53,11 +55,49 @@ export const traverseSchema = (value, path) => {
|
|
|
53
55
|
case 'union': {
|
|
54
56
|
return traverseSchema(selectUnionMember(schema, segment), rest);
|
|
55
57
|
}
|
|
58
|
+
case 'intersection': {
|
|
59
|
+
const members = schema.toParts().filter(part => takesSegment(part, segment));
|
|
60
|
+
if (members.length === 0) {
|
|
61
|
+
throw new Error(`Schema path segment "${segment}" does not match a member of the intersection`);
|
|
62
|
+
}
|
|
63
|
+
return traverseLast(members, path);
|
|
64
|
+
}
|
|
56
65
|
default: {
|
|
57
66
|
throw new Error(`Schema path segment "${segment}" cannot traverse a "${schema.type}" schema`);
|
|
58
67
|
}
|
|
59
68
|
}
|
|
60
69
|
};
|
|
70
|
+
/** The schema at `path` in the last of `members` that has the whole path. When none has, the last one's error. */
|
|
71
|
+
const traverseLast = (members, path) => {
|
|
72
|
+
const [last, ...others] = members.toReversed();
|
|
73
|
+
try {
|
|
74
|
+
return traverseSchema(last, path);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
for (const member of others) {
|
|
78
|
+
try {
|
|
79
|
+
return traverseSchema(member, path);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// The next member may have the path.
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
/** Whether a member of an intersection is one that `segment` can descend into. */
|
|
89
|
+
const takesSegment = (schema, segment) => {
|
|
90
|
+
switch (schema.type) {
|
|
91
|
+
case 'object':
|
|
92
|
+
return schema.properties?.[segment] !== undefined;
|
|
93
|
+
case 'array':
|
|
94
|
+
return segment === 'items';
|
|
95
|
+
case 'union':
|
|
96
|
+
return /^(\$|\[\d+\]$|\{)/.test(segment);
|
|
97
|
+
default:
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
61
101
|
/**
|
|
62
102
|
* Pick one member of a union for an {@link SchemaPath} segment. The segment's
|
|
63
103
|
* notation chooses the branching strategy:
|
|
@@ -93,8 +133,10 @@ const selectUnionMember = (union, segment) => {
|
|
|
93
133
|
throw new Error(`Schema path segment "${segment}" discriminates on "${propertyName}", but this union's discriminator is "${union.discriminator.propertyName}"`);
|
|
94
134
|
}
|
|
95
135
|
const mapped = union.discriminator.mapping?.[value];
|
|
96
|
-
|
|
97
|
-
const member =
|
|
136
|
+
// A mapping holds a whole `$ref` or a bare schema name.
|
|
137
|
+
const member = mapped?.includes('#')
|
|
138
|
+
? findMemberByPointer(union, mapped)
|
|
139
|
+
: findMemberByRefName(union, mapped ? toRefParts({ $ref: mapped }).refName : value);
|
|
98
140
|
if (!member) {
|
|
99
141
|
throw new Error(`Schema path segment "${segment}" does not resolve to a union member via the discriminator`);
|
|
100
142
|
}
|
|
@@ -105,11 +147,15 @@ const selectUnionMember = (union, segment) => {
|
|
|
105
147
|
if (!member) {
|
|
106
148
|
const refNames = union.members
|
|
107
149
|
.filter(member => member.isRef())
|
|
108
|
-
.map(member => member.
|
|
150
|
+
.map(member => member.refName);
|
|
109
151
|
throw new Error(`Schema path segment "${segment}" does not match a union member refName (available: ${refNames.map(name => `$${name}`).join(', ') || 'none — use "[index]" for inline members'})`);
|
|
110
152
|
}
|
|
111
153
|
return member;
|
|
112
154
|
}
|
|
113
155
|
throw new Error(`Schema path segment "${segment}" is not a valid union selector; use "$RefName", "{discriminator:value}", or "[index]"`);
|
|
114
156
|
};
|
|
115
|
-
const
|
|
157
|
+
const findMemberByPointer = (union, $ref) => {
|
|
158
|
+
const pointer = toRefPointer(toRefParts({ $ref }));
|
|
159
|
+
return union.members.find(member => member.isRef() && toRefPointer(member) === pointer);
|
|
160
|
+
};
|
|
161
|
+
const findMemberByRefName = (union, refName) => union.members.find(member => member.isRef() && member.refName === refName);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ParseContextType } from '../context/parseTypes.js';
|
|
2
|
+
import type { KeptRefs } from './keptRefs.js';
|
|
2
3
|
import type { StackTrail } from '../context/StackTrail.js';
|
|
3
4
|
/** What the `allOf` merge reads of `client.json#settings.system`, and what it reports back. */
|
|
4
5
|
type AllOfSystem = {
|
|
@@ -9,6 +10,8 @@ type AllOfSystem = {
|
|
|
9
10
|
replaced: Set<string>;
|
|
10
11
|
/** The keywords the merge read as any value: `anyOf` under `system.anyOf: unknown`. */
|
|
11
12
|
unknown: Set<string>;
|
|
13
|
+
/** The refs that stay refs (`system.intersections`). */
|
|
14
|
+
keptRefs: KeptRefs | undefined;
|
|
12
15
|
};
|
|
13
16
|
/**
|
|
14
17
|
* The `system` settings for one merge: the `allOf` mode, `strict` when the
|
package/esm/parse/allOfSystem.js
CHANGED
|
@@ -9,7 +9,8 @@ export const toAllOfSystem = (context) => ({
|
|
|
9
9
|
not: context.system?.not ?? 'strict',
|
|
10
10
|
anyOf: context.system?.anyOf ?? 'union',
|
|
11
11
|
replaced: new Set(),
|
|
12
|
-
unknown: new Set()
|
|
12
|
+
unknown: new Set(),
|
|
13
|
+
keptRefs: context.keptRefs
|
|
13
14
|
});
|
|
14
15
|
/**
|
|
15
16
|
* One warning for a schema whose `allOf` members contradicted, naming the
|