@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/script/oas/ref/Ref.js
CHANGED
|
@@ -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 _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain;
|
|
13
|
+
var _OasRef_instances, _OasRef_document, _OasRef_resolution, _OasRef_toResolution, _OasRef_toChainResolution, _OasRef_toSiteSchema, _OasRef_toLoop, _OasRef_resolveOasOnce, _OasRef_resolveGqlOnce, _OasRef_someOnChain, _OasRef_toWrittenRef;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.OasRef = void 0;
|
|
16
16
|
require("../../_dnt.polyfills.js");
|
|
@@ -19,45 +19,6 @@ const refFns_js_1 = require("../../helpers/refFns.js");
|
|
|
19
19
|
const OasBase_js_1 = require("../../types/OasBase.js");
|
|
20
20
|
const DanglingRefError_js_1 = require("./DanglingRefError.js");
|
|
21
21
|
const siblings_js_1 = require("../schema/siblings.js");
|
|
22
|
-
/**
|
|
23
|
-
* Converts a ref type to its plural components path.
|
|
24
|
-
*/
|
|
25
|
-
function refTypeToPluralPath(refType) {
|
|
26
|
-
switch (refType) {
|
|
27
|
-
case 'schema':
|
|
28
|
-
return 'schemas';
|
|
29
|
-
case 'requestBody':
|
|
30
|
-
return 'requestBodies';
|
|
31
|
-
case 'parameter':
|
|
32
|
-
return 'parameters';
|
|
33
|
-
case 'response':
|
|
34
|
-
return 'responses';
|
|
35
|
-
case 'example':
|
|
36
|
-
return 'examples';
|
|
37
|
-
case 'header':
|
|
38
|
-
return 'headers';
|
|
39
|
-
case 'securityScheme':
|
|
40
|
-
return 'securitySchemes';
|
|
41
|
-
case 'link':
|
|
42
|
-
return 'links';
|
|
43
|
-
default: {
|
|
44
|
-
const _exhaustive = refType;
|
|
45
|
-
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* The name `resolveOnce` looks up. `toRefName` throws for a `$ref` whose last
|
|
51
|
-
* segment is empty (`#/components/schemas/`): that `$ref` names nothing.
|
|
52
|
-
*/
|
|
53
|
-
const toLookupName = ($ref) => {
|
|
54
|
-
try {
|
|
55
|
-
return (0, refFns_js_1.toRefName)($ref);
|
|
56
|
-
}
|
|
57
|
-
catch {
|
|
58
|
-
throw new DanglingRefError_js_1.DanglingRefError($ref);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
22
|
/**
|
|
62
23
|
* Represents an OpenAPI reference ($ref) in the SKMTC OAS processing system.
|
|
63
24
|
*
|
|
@@ -116,8 +77,8 @@ const toLookupName = ($ref) => {
|
|
|
116
77
|
* function processSchemaOrRef(schema: OasSchema | OasRef<'schema'>) {
|
|
117
78
|
* if (schema.isRef()) {
|
|
118
79
|
* // Handle reference
|
|
119
|
-
* const refName = schema
|
|
120
|
-
* console.log(`Processing reference: ${refName}`);
|
|
80
|
+
* const { refName, refPath } = schema;
|
|
81
|
+
* console.log(`Processing reference: ${refName} in ${refPath}`);
|
|
121
82
|
*
|
|
122
83
|
* // Resolve only when needed
|
|
123
84
|
* const resolved = schema.resolve();
|
|
@@ -179,13 +140,40 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
179
140
|
writable: true,
|
|
180
141
|
value: void 0
|
|
181
142
|
});
|
|
182
|
-
/**
|
|
143
|
+
/**
|
|
144
|
+
* The JSON Reference, as written: a component (`#/components/<bucket>/<name>`)
|
|
145
|
+
* or any other place in the document (`#/components/schemas/Pet/properties/tag`).
|
|
146
|
+
*/
|
|
183
147
|
Object.defineProperty(this, "$ref", {
|
|
184
148
|
enumerable: true,
|
|
185
149
|
configurable: true,
|
|
186
150
|
writable: true,
|
|
187
151
|
value: void 0
|
|
188
152
|
});
|
|
153
|
+
/**
|
|
154
|
+
* The last segment of the `$ref`'s pointer, unescaped: `Pet` for
|
|
155
|
+
* `#/components/schemas/Pet`, `schema0` for
|
|
156
|
+
* `#/components/schemas/__sharedInput/$defs/schema0`. Empty for a `$ref`
|
|
157
|
+
* that ends in `/`, which names nothing.
|
|
158
|
+
*/
|
|
159
|
+
Object.defineProperty(this, "refName", {
|
|
160
|
+
enumerable: true,
|
|
161
|
+
configurable: true,
|
|
162
|
+
writable: true,
|
|
163
|
+
value: void 0
|
|
164
|
+
});
|
|
165
|
+
/**
|
|
166
|
+
* The pointer before {@link refName}, with no percent escapes: `#/components/schemas`
|
|
167
|
+
* for a schema component, `#/components/schemas/__sharedInput/$defs` for
|
|
168
|
+
* the `$defs` entry above. A generator that names by {@link refName} alone
|
|
169
|
+
* may ignore it.
|
|
170
|
+
*/
|
|
171
|
+
Object.defineProperty(this, "refPath", {
|
|
172
|
+
enumerable: true,
|
|
173
|
+
configurable: true,
|
|
174
|
+
writable: true,
|
|
175
|
+
value: void 0
|
|
176
|
+
});
|
|
189
177
|
/**
|
|
190
178
|
* Use-site nullability (see {@link SiblingKeywords.nullable}). Assigned
|
|
191
179
|
* even when `undefined`, so `'nullable' in ref` is always true and the
|
|
@@ -395,6 +383,9 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
395
383
|
_OasRef_resolution.set(this, void 0);
|
|
396
384
|
this.refType = fields.refType;
|
|
397
385
|
this.$ref = fields.$ref;
|
|
386
|
+
const { refName, refPath } = (0, refFns_js_1.toRefParts)({ $ref: fields.$ref });
|
|
387
|
+
this.refName = refName;
|
|
388
|
+
this.refPath = refPath;
|
|
398
389
|
this.nullable = fields.nullable;
|
|
399
390
|
this.readOnly = fields.readOnly;
|
|
400
391
|
this.writeOnly = fields.writeOnly;
|
|
@@ -471,8 +462,9 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
471
462
|
}
|
|
472
463
|
/**
|
|
473
464
|
* Resolves this reference one level. Dispatches on the document's
|
|
474
|
-
* protocol — OAS reads from `document.components.<bucket
|
|
475
|
-
*
|
|
465
|
+
* protocol — OAS reads a component from `document.components.<bucket>`,
|
|
466
|
+
* and any other target from the targets the parser kept by pointer
|
|
467
|
+
* (`OasDocument.toRefTarget`); GQL reads from `document.registry.schemas`.
|
|
476
468
|
*
|
|
477
469
|
* @returns Either the resolved component or another reference in the chain
|
|
478
470
|
* @throws {DanglingRefError} when the reference names nothing in the
|
|
@@ -482,12 +474,14 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
482
474
|
* `requestBody` ref to `#/components/schemas/…`
|
|
483
475
|
*/
|
|
484
476
|
resolveOnce() {
|
|
485
|
-
|
|
477
|
+
if (this.refName === '') {
|
|
478
|
+
throw new DanglingRefError_js_1.DanglingRefError(this.$ref);
|
|
479
|
+
}
|
|
486
480
|
const resolved = __classPrivateFieldGet(this, _OasRef_document, "f").type === 'oas'
|
|
487
|
-
? __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveOasOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value
|
|
488
|
-
: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveGqlOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value
|
|
481
|
+
? __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveOasOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value)
|
|
482
|
+
: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_resolveGqlOnce).call(this, __classPrivateFieldGet(this, _OasRef_document, "f").value);
|
|
489
483
|
if (!resolved) {
|
|
490
|
-
throw new DanglingRefError_js_1.DanglingRefError(this.$ref);
|
|
484
|
+
throw new DanglingRefError_js_1.DanglingRefError(this.$ref, { remote: (0, refFns_js_1.isRemoteRefPath)(this.refPath) });
|
|
491
485
|
}
|
|
492
486
|
if (resolved.isRef()) {
|
|
493
487
|
if (resolved.refType !== this.refType) {
|
|
@@ -501,15 +495,6 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
501
495
|
}
|
|
502
496
|
return resolved;
|
|
503
497
|
}
|
|
504
|
-
/**
|
|
505
|
-
* The component name the reference looks up.
|
|
506
|
-
*
|
|
507
|
-
* @throws {DanglingRefError} when the `$ref` has no name, such as
|
|
508
|
-
* `#/components/schemas/`: it names nothing
|
|
509
|
-
*/
|
|
510
|
-
toRefName() {
|
|
511
|
-
return toLookupName(this.$ref);
|
|
512
|
-
}
|
|
513
498
|
/**
|
|
514
499
|
* Narrows this reference to a schema reference.
|
|
515
500
|
*
|
|
@@ -631,16 +616,12 @@ class OasRef extends OasBase_js_1.OasBase {
|
|
|
631
616
|
const resolved = this.resolve().toJsonSchema({ resolve });
|
|
632
617
|
return resolved;
|
|
633
618
|
}
|
|
634
|
-
const ref = {
|
|
635
|
-
$ref: `#/components/${refTypeToPluralPath(this.refType)}/${this.toRefName()}`
|
|
636
|
-
};
|
|
619
|
+
const ref = { $ref: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toWrittenRef).call(this) };
|
|
637
620
|
return ref;
|
|
638
621
|
}
|
|
639
622
|
/** `{ $ref }` only, as {@link toJsonSchema} without `resolve` (skmtc/skmtc#338). */
|
|
640
623
|
toJSON() {
|
|
641
|
-
return {
|
|
642
|
-
$ref: `#/components/${refTypeToPluralPath(this.refType)}/${this.toRefName()}`
|
|
643
|
-
};
|
|
624
|
+
return { $ref: __classPrivateFieldGet(this, _OasRef_instances, "m", _OasRef_toWrittenRef).call(this) };
|
|
644
625
|
}
|
|
645
626
|
}
|
|
646
627
|
exports.OasRef = OasRef;
|
|
@@ -681,15 +662,21 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
681
662
|
}
|
|
682
663
|
const index = followed.indexOf(next);
|
|
683
664
|
return index === -1 ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_toLoop).call(next, [...followed, next]) : followed.slice(index);
|
|
684
|
-
}, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document
|
|
665
|
+
}, _OasRef_resolveOasOnce = function _OasRef_resolveOasOnce(document) {
|
|
685
666
|
// A `#/components/<bucket>/<name>` ref names its bucket. A request body
|
|
686
667
|
// that is a `$ref` to `#/components/schemas/Pet` names a schema, so it is
|
|
687
|
-
// never looked up in the request bodies.
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
668
|
+
// never looked up in the request bodies. A ref to any other place
|
|
669
|
+
// (`#/components/parameters/limit/schema`) names no bucket: the kind of
|
|
670
|
+
// what it finds is checked in `resolveOnce`.
|
|
671
|
+
const bucket = (0, refFns_js_1.toRefPathBucket)(this.refPath);
|
|
672
|
+
const expected = (0, refFns_js_1.toComponentsBucket)(this.refType);
|
|
673
|
+
if (bucket === undefined) {
|
|
674
|
+
return document.toRefTarget((0, refFns_js_1.toRefPointer)(this));
|
|
675
|
+
}
|
|
676
|
+
if (bucket !== expected) {
|
|
691
677
|
throw new Error(`Ref type mismatch for "${this.$ref}". Expected a ref into "components/${expected}" but it names one in "components/${bucket}"`);
|
|
692
678
|
}
|
|
679
|
+
const refName = this.refName;
|
|
693
680
|
const c = document.components;
|
|
694
681
|
const refType = this.refType;
|
|
695
682
|
switch (refType) {
|
|
@@ -714,14 +701,14 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
714
701
|
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
715
702
|
}
|
|
716
703
|
}
|
|
717
|
-
}, _OasRef_resolveGqlOnce = function _OasRef_resolveGqlOnce(document
|
|
704
|
+
}, _OasRef_resolveGqlOnce = function _OasRef_resolveGqlOnce(document) {
|
|
718
705
|
// GraphQL only ever creates schema refs — there's no GQL concept
|
|
719
706
|
// of a response/parameter/header/etc. ref. The refType field is
|
|
720
707
|
// still typed by `T` for the OAS variants; on the GQL branch we
|
|
721
708
|
// always do a schema lookup and let the post-lookup refType-vs-
|
|
722
709
|
// oasType check catch any caller that constructed a non-schema
|
|
723
710
|
// ref pointing at a GQL document.
|
|
724
|
-
return document.registry.schemas[refName];
|
|
711
|
+
return document.registry.schemas[this.refName];
|
|
725
712
|
}, _OasRef_someOnChain = function _OasRef_someOnChain(check, passed = new Set()) {
|
|
726
713
|
if (check.onRef(this)) {
|
|
727
714
|
return true;
|
|
@@ -731,4 +718,13 @@ _OasRef_document = new WeakMap(), _OasRef_resolution = new WeakMap(), _OasRef_in
|
|
|
731
718
|
}
|
|
732
719
|
const next = this.resolveOnce();
|
|
733
720
|
return next.isRef() ? __classPrivateFieldGet(next, _OasRef_instances, "m", _OasRef_someOnChain).call(next, check, new Set([...passed, this])) : check.onTarget(next);
|
|
721
|
+
}, _OasRef_toWrittenRef = function _OasRef_toWrittenRef() {
|
|
722
|
+
if (this.refName === '') {
|
|
723
|
+
throw new DanglingRefError_js_1.DanglingRefError(this.$ref);
|
|
724
|
+
}
|
|
725
|
+
return (0, refFns_js_1.isDefaultRefPath)({ refPath: this.refPath, refType: this.refType })
|
|
726
|
+
? `#/components/${(0, refFns_js_1.toComponentsBucket)(this.refType)}/${this.refName}`
|
|
727
|
+
: (0, refFns_js_1.isRemoteRefPath)(this.refPath)
|
|
728
|
+
? this.$ref
|
|
729
|
+
: (0, refFns_js_1.toRefPointer)(this).replaceAll('%', '%25');
|
|
734
730
|
};
|
|
@@ -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;
|
|
@@ -322,7 +322,7 @@ class OasRequestBody extends OasBase_js_1.OasBase {
|
|
|
322
322
|
* `mediaType`, the schema of the JSON media type that {@link toJsonContent}
|
|
323
323
|
* picks: `application/json`, else the first JSON-like type such as
|
|
324
324
|
* `application/json;v=1.0` or `application/vnd.api+json`, else `*\/*`
|
|
325
|
-
* when its schema is an object, array, union or `$ref`.
|
|
325
|
+
* when its schema is an object, array, union, intersection or `$ref`.
|
|
326
326
|
* `undefined` when there is no such media type or it has no schema.
|
|
327
327
|
*/
|
|
328
328
|
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;
|
|
@@ -262,7 +262,7 @@ class OasResponse extends OasBase_js_1.OasBase {
|
|
|
262
262
|
* `mediaType`, the schema of the JSON media type that {@link toJsonContent}
|
|
263
263
|
* picks: `application/json`, else the first JSON-like type such as
|
|
264
264
|
* `application/json;v=1.0` or `application/vnd.api+json`, else `*\/*`
|
|
265
|
-
* when its schema is an object, array, union or `$ref`.
|
|
265
|
+
* when its schema is an object, array, union, intersection or `$ref`.
|
|
266
266
|
* `undefined` when there is no such media type or it has no schema.
|
|
267
267
|
*/
|
|
268
268
|
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";
|
|
@@ -36,7 +36,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.toSiblingEnums = exports.toSiblingValue = exports.isIntegerFormat = exports.isNumberFormat = exports.VALUE_CHECKS = exports.isObjectValue = exports.isArrayValue = exports.isBooleanValue = exports.isIntegerValue = exports.isNumberValue = exports.isStringValue = exports.toSiblingAnnotations = exports.toSkippedSiblings = exports.changesValues = exports.changesTarget = exports.hasSiblingKeywords = exports.mergeSiblingKeywords = exports.SIBLINGS_BY_TYPE = void 0;
|
|
39
|
+
exports.toSiblingEnums = exports.toSiblingValue = exports.isIntegerFormat = exports.isNumberFormat = exports.VALUE_CHECKS = exports.isObjectValue = exports.isArrayValue = exports.isBooleanValue = exports.isIntegerValue = exports.isNumberValue = exports.isStringValue = exports.toSiblingAnnotations = exports.toChangedObjectKeywords = exports.toSkippedSiblings = exports.changesValues = exports.changesTarget = exports.hasSiblingKeywords = exports.mergeSiblingKeywords = exports.SIBLINGS_BY_TYPE = void 0;
|
|
40
40
|
const v = __importStar(require("valibot"));
|
|
41
41
|
const isEqual_js_1 = __importDefault(require("lodash-es/isEqual.js"));
|
|
42
42
|
const DanglingRefError_js_1 = require("../ref/DanglingRefError.js");
|
|
@@ -61,7 +61,15 @@ const NUMERIC = [
|
|
|
61
61
|
'exclusiveMinimum',
|
|
62
62
|
'exclusiveMaximum'
|
|
63
63
|
];
|
|
64
|
-
/** The keywords
|
|
64
|
+
/** The keywords of an object. An intersection's `clone` takes them as one more member. */
|
|
65
|
+
const OBJECT_KEYWORDS = [
|
|
66
|
+
'properties',
|
|
67
|
+
'required',
|
|
68
|
+
'additionalProperties',
|
|
69
|
+
'minProperties',
|
|
70
|
+
'maxProperties'
|
|
71
|
+
];
|
|
72
|
+
/** The keywords each schema class's `clone` takes: the fields its type has, and {@link OBJECT_KEYWORDS} for an intersection. */
|
|
65
73
|
exports.SIBLINGS_BY_TYPE = {
|
|
66
74
|
string: [...DESCRIBING, 'deprecated', 'default', 'enums', 'format', 'minLength', 'maxLength', 'pattern'],
|
|
67
75
|
number: [...DESCRIBING, ...NUMERIC],
|
|
@@ -73,13 +81,10 @@ exports.SIBLINGS_BY_TYPE = {
|
|
|
73
81
|
'deprecated',
|
|
74
82
|
'default',
|
|
75
83
|
'enums',
|
|
76
|
-
|
|
77
|
-
'required',
|
|
78
|
-
'additionalProperties',
|
|
79
|
-
'minProperties',
|
|
80
|
-
'maxProperties'
|
|
84
|
+
...OBJECT_KEYWORDS
|
|
81
85
|
],
|
|
82
86
|
union: [...DESCRIBING, 'default'],
|
|
87
|
+
intersection: [...DESCRIBING, 'deprecated', 'default', ...OBJECT_KEYWORDS],
|
|
83
88
|
unknown: DESCRIBING
|
|
84
89
|
};
|
|
85
90
|
/** Every keyword `clone` can apply, for any type. */
|
|
@@ -164,14 +169,21 @@ const BOOLEAN_KEYWORDS = [
|
|
|
164
169
|
* a flag the target already has, and a value equal to the target's change
|
|
165
170
|
* nothing.
|
|
166
171
|
*/
|
|
167
|
-
const toChangedKeywords = (copy, target, siblings) =>
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
172
|
+
const toChangedKeywords = (copy, target, siblings) => {
|
|
173
|
+
// An intersection takes these as a member, so it has no field to compare.
|
|
174
|
+
const objectKeywords = target.type === 'intersection' ? (0, exports.toChangedObjectKeywords)(target, siblings) : [];
|
|
175
|
+
return exports.SIBLINGS_BY_TYPE[target.type].filter(keyword => {
|
|
176
|
+
if (siblings[keyword] === undefined) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
if (target.type === 'intersection' && OBJECT_KEYWORDS.includes(keyword)) {
|
|
180
|
+
return objectKeywords.includes(keyword);
|
|
181
|
+
}
|
|
182
|
+
const applied = Reflect.get(copy, keyword);
|
|
183
|
+
const original = Reflect.get(target, keyword);
|
|
184
|
+
return BOOLEAN_KEYWORDS.includes(keyword) ? (applied === true) !== (original === true) : !(0, isEqual_js_1.default)(applied, original);
|
|
185
|
+
});
|
|
186
|
+
};
|
|
175
187
|
/** Whether the keywords next to a reference change `target` at that site. The engine behind `OasRef.resolve`. */
|
|
176
188
|
const changesTarget = (copy, target, siblings) => toChangedKeywords(copy, target, siblings).length > 0;
|
|
177
189
|
exports.changesTarget = changesTarget;
|
|
@@ -213,24 +225,74 @@ const toSkippedSiblings = (target, siblings, nullable) => {
|
|
|
213
225
|
return false;
|
|
214
226
|
}
|
|
215
227
|
};
|
|
216
|
-
const type = siblings._type !== undefined && !agrees(siblings._type, target
|
|
228
|
+
const type = siblings._type !== undefined && !agrees(siblings._type, target) ? ['type'] : [];
|
|
217
229
|
const others = SIBLING_KEYWORDS.filter(keyword => isSkipped(keyword, siblings[keyword])).map(toDocumentKeyword);
|
|
218
230
|
return [...type, ...others];
|
|
219
231
|
};
|
|
220
232
|
exports.toSkippedSiblings = toSkippedSiblings;
|
|
221
|
-
/**
|
|
222
|
-
|
|
233
|
+
/**
|
|
234
|
+
* The {@link OBJECT_KEYWORDS} next to a reference that say something the
|
|
235
|
+
* members of an intersection do not: a name none of them requires, a property
|
|
236
|
+
* none of them has the same. References in the members count by their target,
|
|
237
|
+
* without the keywords next to them.
|
|
238
|
+
*/
|
|
239
|
+
const toChangedObjectKeywords = (target, siblings) => {
|
|
240
|
+
const objects = target.toTargetParts().filter(part => part.type === 'object');
|
|
241
|
+
const isSame = (keyword) => objects.some(object => (0, isEqual_js_1.default)(object[keyword], siblings[keyword]));
|
|
242
|
+
const isUnchanged = (keyword) => {
|
|
243
|
+
switch (keyword) {
|
|
244
|
+
case 'required':
|
|
245
|
+
return (siblings.required ?? []).every(name => objects.some(object => object.required?.includes(name)));
|
|
246
|
+
case 'properties':
|
|
247
|
+
return Object.keys(siblings.properties ?? {}).every(name => objects.some(object => (0, isEqual_js_1.default)(object.properties?.[name], siblings.properties?.[name])));
|
|
248
|
+
case 'additionalProperties':
|
|
249
|
+
case 'minProperties':
|
|
250
|
+
case 'maxProperties':
|
|
251
|
+
return isSame(keyword);
|
|
252
|
+
default:
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
return OBJECT_KEYWORDS.filter(keyword => siblings[keyword] !== undefined && !isUnchanged(keyword));
|
|
257
|
+
};
|
|
258
|
+
exports.toChangedObjectKeywords = toChangedObjectKeywords;
|
|
223
259
|
/**
|
|
224
260
|
* A `type` next to a reference agrees with the target's when it names it, or
|
|
225
261
|
* `number` for an integer. Next to a union, it agrees when every member,
|
|
226
262
|
* followed through references, has that type (`type: object` next to a
|
|
227
|
-
* `oneOf` of objects): leaving it out then loses nothing.
|
|
263
|
+
* `oneOf` of objects): leaving it out then loses nothing. Next to an
|
|
264
|
+
* intersection, it agrees when one member has that type.
|
|
228
265
|
*/
|
|
229
|
-
const agrees = (type, target
|
|
266
|
+
const agrees = (type, target) => {
|
|
267
|
+
const agreed = new Set();
|
|
268
|
+
// A schema that leads back to itself does not agree by that, so a pass reads
|
|
269
|
+
// it as `false` there. It can agree by another member, so a new pass reads
|
|
270
|
+
// the schemas that agreed, until a pass finds no more of them.
|
|
271
|
+
const runPass = () => {
|
|
272
|
+
const before = agreed.size;
|
|
273
|
+
return agreesInPass({ type, target, agreed, visited: new Set() }) || (agreed.size > before && runPass());
|
|
274
|
+
};
|
|
275
|
+
return runPass();
|
|
276
|
+
};
|
|
277
|
+
const agreesInPass = ({ type, target, agreed, visited }) => {
|
|
278
|
+
if (agreed.has(target)) {
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
if (visited.has(target)) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
visited.add(target);
|
|
285
|
+
const result = toAgreement(type, target, member => agreesInPass({ type, target: member, agreed, visited }));
|
|
286
|
+
if (result) {
|
|
287
|
+
agreed.add(target);
|
|
288
|
+
}
|
|
289
|
+
return result;
|
|
290
|
+
};
|
|
291
|
+
/** {@link agrees} for one schema, with `agreesInside` for its members. */
|
|
292
|
+
const toAgreement = (type, target, agreesInside) => {
|
|
230
293
|
if (target.type === 'union') {
|
|
231
294
|
try {
|
|
232
|
-
return
|
|
233
|
-
target.members.every(member => agrees(type, member.isRef() ? member.resolve() : member, depth + 1));
|
|
295
|
+
return target.members.every(member => agreesInside(member.isRef() ? member.resolve() : member));
|
|
234
296
|
}
|
|
235
297
|
catch (error) {
|
|
236
298
|
// A member that is a dangling reference has no known type, so it does not agree.
|
|
@@ -240,6 +302,9 @@ const agrees = (type, target, depth) => {
|
|
|
240
302
|
throw error;
|
|
241
303
|
}
|
|
242
304
|
}
|
|
305
|
+
if (target.type === 'intersection') {
|
|
306
|
+
return target.toParts().some(agreesInside);
|
|
307
|
+
}
|
|
243
308
|
return type === target.type || (type === 'number' && target.type === 'integer');
|
|
244
309
|
};
|
|
245
310
|
/** Whether `format` fits a schema of `type`, as `clone` reads it: any string for a string. */
|
|
@@ -278,7 +343,7 @@ exports.isArrayValue = isArrayValue;
|
|
|
278
343
|
const isObjectValue = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
279
344
|
exports.isObjectValue = isObjectValue;
|
|
280
345
|
const isAnyValue = (_value) => true;
|
|
281
|
-
/** {@link isStringValue} and the others, keyed by the type they check for. A union or unknown takes any value. */
|
|
346
|
+
/** {@link isStringValue} and the others, keyed by the type they check for. A union, intersection or unknown takes any value. */
|
|
282
347
|
exports.VALUE_CHECKS = {
|
|
283
348
|
string: exports.isStringValue,
|
|
284
349
|
number: exports.isNumberValue,
|
|
@@ -287,6 +352,7 @@ exports.VALUE_CHECKS = {
|
|
|
287
352
|
array: exports.isArrayValue,
|
|
288
353
|
object: exports.isObjectValue,
|
|
289
354
|
union: isAnyValue,
|
|
355
|
+
intersection: isAnyValue,
|
|
290
356
|
unknown: isAnyValue
|
|
291
357
|
};
|
|
292
358
|
/** 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
|
|
@@ -19,6 +19,8 @@ const refFns_js_1 = require("../../helpers/refFns.js");
|
|
|
19
19
|
* element schema.
|
|
20
20
|
* - **union** → the segment selects a member ({@link selectUnionMember}):
|
|
21
21
|
* `'$Circle'` by refName, `'{type:circle}'` by discriminator, `'[0]'` by index.
|
|
22
|
+
* - **intersection** → the segment is read as for a member, references followed:
|
|
23
|
+
* the last member that has the whole path.
|
|
22
24
|
*
|
|
23
25
|
* A ref is resolved only when the path needs to descend *through* it. Anything
|
|
24
26
|
* the path cannot navigate throws a descriptive, segment-named error: a missing
|
|
@@ -56,12 +58,50 @@ const traverseSchema = (value, path) => {
|
|
|
56
58
|
case 'union': {
|
|
57
59
|
return (0, exports.traverseSchema)(selectUnionMember(schema, segment), rest);
|
|
58
60
|
}
|
|
61
|
+
case 'intersection': {
|
|
62
|
+
const members = schema.toParts().filter(part => takesSegment(part, segment));
|
|
63
|
+
if (members.length === 0) {
|
|
64
|
+
throw new Error(`Schema path segment "${segment}" does not match a member of the intersection`);
|
|
65
|
+
}
|
|
66
|
+
return traverseLast(members, path);
|
|
67
|
+
}
|
|
59
68
|
default: {
|
|
60
69
|
throw new Error(`Schema path segment "${segment}" cannot traverse a "${schema.type}" schema`);
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
};
|
|
64
73
|
exports.traverseSchema = traverseSchema;
|
|
74
|
+
/** The schema at `path` in the last of `members` that has the whole path. When none has, the last one's error. */
|
|
75
|
+
const traverseLast = (members, path) => {
|
|
76
|
+
const [last, ...others] = members.toReversed();
|
|
77
|
+
try {
|
|
78
|
+
return (0, exports.traverseSchema)(last, path);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
for (const member of others) {
|
|
82
|
+
try {
|
|
83
|
+
return (0, exports.traverseSchema)(member, path);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// The next member may have the path.
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
/** Whether a member of an intersection is one that `segment` can descend into. */
|
|
93
|
+
const takesSegment = (schema, segment) => {
|
|
94
|
+
switch (schema.type) {
|
|
95
|
+
case 'object':
|
|
96
|
+
return schema.properties?.[segment] !== undefined;
|
|
97
|
+
case 'array':
|
|
98
|
+
return segment === 'items';
|
|
99
|
+
case 'union':
|
|
100
|
+
return /^(\$|\[\d+\]$|\{)/.test(segment);
|
|
101
|
+
default:
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
65
105
|
/**
|
|
66
106
|
* Pick one member of a union for an {@link SchemaPath} segment. The segment's
|
|
67
107
|
* notation chooses the branching strategy:
|
|
@@ -97,8 +137,10 @@ const selectUnionMember = (union, segment) => {
|
|
|
97
137
|
throw new Error(`Schema path segment "${segment}" discriminates on "${propertyName}", but this union's discriminator is "${union.discriminator.propertyName}"`);
|
|
98
138
|
}
|
|
99
139
|
const mapped = union.discriminator.mapping?.[value];
|
|
100
|
-
|
|
101
|
-
const member =
|
|
140
|
+
// A mapping holds a whole `$ref` or a bare schema name.
|
|
141
|
+
const member = mapped?.includes('#')
|
|
142
|
+
? findMemberByPointer(union, mapped)
|
|
143
|
+
: findMemberByRefName(union, mapped ? (0, refFns_js_1.toRefParts)({ $ref: mapped }).refName : value);
|
|
102
144
|
if (!member) {
|
|
103
145
|
throw new Error(`Schema path segment "${segment}" does not resolve to a union member via the discriminator`);
|
|
104
146
|
}
|
|
@@ -109,11 +151,15 @@ const selectUnionMember = (union, segment) => {
|
|
|
109
151
|
if (!member) {
|
|
110
152
|
const refNames = union.members
|
|
111
153
|
.filter(member => member.isRef())
|
|
112
|
-
.map(member => member.
|
|
154
|
+
.map(member => member.refName);
|
|
113
155
|
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'})`);
|
|
114
156
|
}
|
|
115
157
|
return member;
|
|
116
158
|
}
|
|
117
159
|
throw new Error(`Schema path segment "${segment}" is not a valid union selector; use "$RefName", "{discriminator:value}", or "[index]"`);
|
|
118
160
|
};
|
|
119
|
-
const
|
|
161
|
+
const findMemberByPointer = (union, $ref) => {
|
|
162
|
+
const pointer = (0, refFns_js_1.toRefPointer)((0, refFns_js_1.toRefParts)({ $ref }));
|
|
163
|
+
return union.members.find(member => member.isRef() && (0, refFns_js_1.toRefPointer)(member) === pointer);
|
|
164
|
+
};
|
|
165
|
+
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
|
|
@@ -12,7 +12,8 @@ const toAllOfSystem = (context) => ({
|
|
|
12
12
|
not: context.system?.not ?? 'strict',
|
|
13
13
|
anyOf: context.system?.anyOf ?? 'union',
|
|
14
14
|
replaced: new Set(),
|
|
15
|
-
unknown: new Set()
|
|
15
|
+
unknown: new Set(),
|
|
16
|
+
keptRefs: context.keptRefs
|
|
16
17
|
});
|
|
17
18
|
exports.toAllOfSystem = toAllOfSystem;
|
|
18
19
|
/**
|