@skmtc/core 0.45.0 → 0.46.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.js +136 -34
- package/esm/context/generateTypes.d.ts +5 -4
- 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/refFns.d.ts +108 -43
- package/esm/helpers/refFns.js +166 -57
- package/esm/oas/document/Document.d.ts +6 -0
- package/esm/oas/document/Document.js +44 -2
- 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/schemaPath/traverseSchema.js +11 -5
- 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-1/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-1/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-2/ref/toRefTargetV3.js +70 -0
- 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/TypeSystem.d.ts +3 -3
- 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.js +135 -33
- package/script/context/generateTypes.d.ts +5 -4
- 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/refFns.d.ts +108 -43
- package/script/helpers/refFns.js +180 -59
- package/script/oas/document/Document.d.ts +6 -0
- package/script/oas/document/Document.js +44 -2
- 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/schemaPath/traverseSchema.js +10 -4
- 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-1/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-1/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-2/ref/toRefTargetV3.js +74 -0
- 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/TypeSystem.d.ts +3 -3
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
|
};
|
|
@@ -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
|
*
|
|
@@ -93,8 +93,10 @@ const selectUnionMember = (union, segment) => {
|
|
|
93
93
|
throw new Error(`Schema path segment "${segment}" discriminates on "${propertyName}", but this union's discriminator is "${union.discriminator.propertyName}"`);
|
|
94
94
|
}
|
|
95
95
|
const mapped = union.discriminator.mapping?.[value];
|
|
96
|
-
|
|
97
|
-
const member =
|
|
96
|
+
// A mapping holds a whole `$ref` or a bare schema name.
|
|
97
|
+
const member = mapped?.includes('#')
|
|
98
|
+
? findMemberByPointer(union, mapped)
|
|
99
|
+
: findMemberByRefName(union, mapped ? toRefParts({ $ref: mapped }).refName : value);
|
|
98
100
|
if (!member) {
|
|
99
101
|
throw new Error(`Schema path segment "${segment}" does not resolve to a union member via the discriminator`);
|
|
100
102
|
}
|
|
@@ -105,11 +107,15 @@ const selectUnionMember = (union, segment) => {
|
|
|
105
107
|
if (!member) {
|
|
106
108
|
const refNames = union.members
|
|
107
109
|
.filter(member => member.isRef())
|
|
108
|
-
.map(member => member.
|
|
110
|
+
.map(member => member.refName);
|
|
109
111
|
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
112
|
}
|
|
111
113
|
return member;
|
|
112
114
|
}
|
|
113
115
|
throw new Error(`Schema path segment "${segment}" is not a valid union selector; use "$RefName", "{discriminator:value}", or "[index]"`);
|
|
114
116
|
};
|
|
115
|
-
const
|
|
117
|
+
const findMemberByPointer = (union, $ref) => {
|
|
118
|
+
const pointer = toRefPointer(toRefParts({ $ref }));
|
|
119
|
+
return union.members.find(member => member.isRef() && toRefPointer(member) === pointer);
|
|
120
|
+
};
|
|
121
|
+
const findMemberByRefName = (union, refName) => union.members.find(member => member.isRef() && member.refName === refName);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
3
|
+
import type { ComponentsEntry } from '../../../oas/components/Components.js';
|
|
4
|
+
import type { OasRefData } from '../../../oas/ref/ref-types.js';
|
|
5
|
+
/** What {@link toRefTargetV3} parses. */
|
|
6
|
+
export type ToRefTargetArgs = {
|
|
7
|
+
/** The kind of component the ref is written for. */
|
|
8
|
+
refType: OasRefData['refType'];
|
|
9
|
+
/** The last segment of the target's pointer, unescaped: the key it parses under. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** The raw value at the pointer. */
|
|
12
|
+
value: Record<string, unknown>;
|
|
13
|
+
/** The trail of the target's parent, so the target parses at its own position. */
|
|
14
|
+
stackTrail: StackTrail;
|
|
15
|
+
context: ParseContextType;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Parses the target of a ref that does not point at a component
|
|
19
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
20
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
21
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
22
|
+
*/
|
|
23
|
+
export declare const toRefTargetV3: ({ refType, name, value, stackTrail, context }: ToRefTargetArgs) => ComponentsEntry | undefined;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isPlainObject } from '../../isPlainObject.js';
|
|
2
|
+
import { toOptionalSchemasV3 } from '../schema/toSchemasV3.js';
|
|
3
|
+
import { toOptionalParametersV3 } from '../parameter/toParameterV3.js';
|
|
4
|
+
import { toOptionalResponsesV3 } from '../response/toResponseV3.js';
|
|
5
|
+
import { toRequestBodiesV3 } from '../requestBody/toRequestBodiesV3.js';
|
|
6
|
+
import { toComponentHeadersV3 } from '../header/toHeadersV3.js';
|
|
7
|
+
import { toLinksV3 } from '../link/toLinksV3.js';
|
|
8
|
+
import { toExampleV3 } from '../example/toExamplesV3.js';
|
|
9
|
+
import { toSecuritySchemesV3 } from '../securitySchemes/toSecuritySchemes.js';
|
|
10
|
+
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
11
|
+
/**
|
|
12
|
+
* The raw value read as the OpenAPI type its parser takes, as the components
|
|
13
|
+
* parser reads `documentObject.components`: the parser checks what it reads.
|
|
14
|
+
*/
|
|
15
|
+
const isRawEntry = (value) => isPlainObject(value);
|
|
16
|
+
/**
|
|
17
|
+
* Parses the target of a ref that does not point at a component
|
|
18
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
19
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
20
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
21
|
+
*/
|
|
22
|
+
export const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
|
|
23
|
+
switch (refType) {
|
|
24
|
+
case 'schema':
|
|
25
|
+
return isRawEntry(value)
|
|
26
|
+
? toOptionalSchemasV3({ schemas: { [name]: value }, stackTrail, context })?.[name]
|
|
27
|
+
: undefined;
|
|
28
|
+
case 'parameter':
|
|
29
|
+
return isRawEntry(value)
|
|
30
|
+
? toOptionalParametersV3({ parameters: { [name]: value }, stackTrail, context })?.[name]
|
|
31
|
+
: undefined;
|
|
32
|
+
case 'response':
|
|
33
|
+
return isRawEntry(value)
|
|
34
|
+
? toOptionalResponsesV3({ responses: { [name]: value }, stackTrail, context })?.[name]
|
|
35
|
+
: undefined;
|
|
36
|
+
case 'requestBody':
|
|
37
|
+
return isRawEntry(value)
|
|
38
|
+
? toRequestBodiesV3({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
|
|
39
|
+
: undefined;
|
|
40
|
+
case 'header':
|
|
41
|
+
return isRawEntry(value)
|
|
42
|
+
? toComponentHeadersV3({ headers: { [name]: value }, stackTrail, context })?.[name]
|
|
43
|
+
: undefined;
|
|
44
|
+
case 'link':
|
|
45
|
+
return isRawEntry(value)
|
|
46
|
+
? toLinksV3({ links: { [name]: value }, stackTrail, context })?.[name]
|
|
47
|
+
: undefined;
|
|
48
|
+
case 'example':
|
|
49
|
+
// No components parser reads a single example by key, so the target
|
|
50
|
+
// is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
|
|
51
|
+
return isRawEntry(value)
|
|
52
|
+
? tryParseAt({
|
|
53
|
+
stackTrail,
|
|
54
|
+
key: name,
|
|
55
|
+
context,
|
|
56
|
+
type: 'INVALID_EXAMPLE',
|
|
57
|
+
parent: value,
|
|
58
|
+
fn: st => toExampleV3({ example: value, stackTrail: st, context })
|
|
59
|
+
})
|
|
60
|
+
: undefined;
|
|
61
|
+
case 'securityScheme':
|
|
62
|
+
return isRawEntry(value)
|
|
63
|
+
? toSecuritySchemesV3({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
|
|
64
|
+
: undefined;
|
|
65
|
+
default: {
|
|
66
|
+
const _exhaustive = refType;
|
|
67
|
+
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
3
|
+
import type { ComponentsEntry } from '../../../oas/components/Components.js';
|
|
4
|
+
import type { OasRefData } from '../../../oas/ref/ref-types.js';
|
|
5
|
+
/** What {@link toRefTargetV3} parses. */
|
|
6
|
+
export type ToRefTargetArgs = {
|
|
7
|
+
/** The kind of component the ref is written for. */
|
|
8
|
+
refType: OasRefData['refType'];
|
|
9
|
+
/** The last segment of the target's pointer, unescaped: the key it parses under. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** The raw value at the pointer. */
|
|
12
|
+
value: Record<string, unknown>;
|
|
13
|
+
/** The trail of the target's parent, so the target parses at its own position. */
|
|
14
|
+
stackTrail: StackTrail;
|
|
15
|
+
context: ParseContextType;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Parses the target of a ref that does not point at a component
|
|
19
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
20
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
21
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
22
|
+
*/
|
|
23
|
+
export declare const toRefTargetV3: ({ refType, name, value, stackTrail, context }: ToRefTargetArgs) => ComponentsEntry | undefined;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isPlainObject } from '../../isPlainObject.js';
|
|
2
|
+
import { toOptionalSchemasV3 } from '../schema/toSchemasV3.js';
|
|
3
|
+
import { toOptionalParametersV3 } from '../parameter/toParameterV3.js';
|
|
4
|
+
import { toOptionalResponsesV3 } from '../response/toResponseV3.js';
|
|
5
|
+
import { toRequestBodiesV3 } from '../requestBody/toRequestBodiesV3.js';
|
|
6
|
+
import { toComponentHeadersV3 } from '../header/toHeadersV3.js';
|
|
7
|
+
import { toLinksV3 } from '../link/toLinksV3.js';
|
|
8
|
+
import { toExampleV3 } from '../example/toExamplesV3.js';
|
|
9
|
+
import { toSecuritySchemesV3 } from '../securitySchemes/toSecuritySchemes.js';
|
|
10
|
+
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
11
|
+
/**
|
|
12
|
+
* The raw value read as the OpenAPI type its parser takes, as the components
|
|
13
|
+
* parser reads `documentObject.components`: the parser checks what it reads.
|
|
14
|
+
*/
|
|
15
|
+
const isRawEntry = (value) => isPlainObject(value);
|
|
16
|
+
/**
|
|
17
|
+
* Parses the target of a ref that does not point at a component
|
|
18
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
19
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
20
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
21
|
+
*/
|
|
22
|
+
export const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
|
|
23
|
+
switch (refType) {
|
|
24
|
+
case 'schema':
|
|
25
|
+
return isRawEntry(value)
|
|
26
|
+
? toOptionalSchemasV3({ schemas: { [name]: value }, stackTrail, context })?.[name]
|
|
27
|
+
: undefined;
|
|
28
|
+
case 'parameter':
|
|
29
|
+
return isRawEntry(value)
|
|
30
|
+
? toOptionalParametersV3({ parameters: { [name]: value }, stackTrail, context })?.[name]
|
|
31
|
+
: undefined;
|
|
32
|
+
case 'response':
|
|
33
|
+
return isRawEntry(value)
|
|
34
|
+
? toOptionalResponsesV3({ responses: { [name]: value }, stackTrail, context })?.[name]
|
|
35
|
+
: undefined;
|
|
36
|
+
case 'requestBody':
|
|
37
|
+
return isRawEntry(value)
|
|
38
|
+
? toRequestBodiesV3({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
|
|
39
|
+
: undefined;
|
|
40
|
+
case 'header':
|
|
41
|
+
return isRawEntry(value)
|
|
42
|
+
? toComponentHeadersV3({ headers: { [name]: value }, stackTrail, context })?.[name]
|
|
43
|
+
: undefined;
|
|
44
|
+
case 'link':
|
|
45
|
+
return isRawEntry(value)
|
|
46
|
+
? toLinksV3({ links: { [name]: value }, stackTrail, context })?.[name]
|
|
47
|
+
: undefined;
|
|
48
|
+
case 'example':
|
|
49
|
+
// No components parser reads a single example by key, so the target
|
|
50
|
+
// is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
|
|
51
|
+
return isRawEntry(value)
|
|
52
|
+
? tryParseAt({
|
|
53
|
+
stackTrail,
|
|
54
|
+
key: name,
|
|
55
|
+
context,
|
|
56
|
+
type: 'INVALID_EXAMPLE',
|
|
57
|
+
parent: value,
|
|
58
|
+
fn: st => toExampleV3({ example: value, stackTrail: st, context })
|
|
59
|
+
})
|
|
60
|
+
: undefined;
|
|
61
|
+
case 'securityScheme':
|
|
62
|
+
return isRawEntry(value)
|
|
63
|
+
? toSecuritySchemesV3({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
|
|
64
|
+
: undefined;
|
|
65
|
+
default: {
|
|
66
|
+
const _exhaustive = refType;
|
|
67
|
+
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
3
|
+
import type { ComponentsEntry } from '../../../oas/components/Components.js';
|
|
4
|
+
import type { OasRefData } from '../../../oas/ref/ref-types.js';
|
|
5
|
+
/** What {@link toRefTargetV3} parses. */
|
|
6
|
+
export type ToRefTargetArgs = {
|
|
7
|
+
/** The kind of component the ref is written for. */
|
|
8
|
+
refType: OasRefData['refType'];
|
|
9
|
+
/** The last segment of the target's pointer, unescaped: the key it parses under. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** The raw value at the pointer. */
|
|
12
|
+
value: Record<string, unknown>;
|
|
13
|
+
/** The trail of the target's parent, so the target parses at its own position. */
|
|
14
|
+
stackTrail: StackTrail;
|
|
15
|
+
context: ParseContextType;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Parses the target of a ref that does not point at a component
|
|
19
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
20
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
21
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
22
|
+
*/
|
|
23
|
+
export declare const toRefTargetV3: ({ refType, name, value, stackTrail, context }: ToRefTargetArgs) => ComponentsEntry | undefined;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isPlainObject } from '../../isPlainObject.js';
|
|
2
|
+
import { toOptionalSchemasV3 } from '../schema/toSchemasV3.js';
|
|
3
|
+
import { toOptionalParametersV3 } from '../parameter/toParameterV3.js';
|
|
4
|
+
import { toOptionalResponsesV3 } from '../response/toResponseV3.js';
|
|
5
|
+
import { toRequestBodiesV3 } from '../requestBody/toRequestBodiesV3.js';
|
|
6
|
+
import { toComponentHeadersV3 } from '../header/toHeadersV3.js';
|
|
7
|
+
import { toLinksV3 } from '../link/toLinksV3.js';
|
|
8
|
+
import { toExampleV3 } from '../example/toExamplesV3.js';
|
|
9
|
+
import { toSecuritySchemesV3 } from '../securitySchemes/toSecuritySchemes.js';
|
|
10
|
+
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
11
|
+
/**
|
|
12
|
+
* The raw value read as the OpenAPI type its parser takes, as the components
|
|
13
|
+
* parser reads `documentObject.components`: the parser checks what it reads.
|
|
14
|
+
*/
|
|
15
|
+
const isRawEntry = (value) => isPlainObject(value);
|
|
16
|
+
/**
|
|
17
|
+
* Parses the target of a ref that does not point at a component
|
|
18
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
19
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
20
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
21
|
+
*/
|
|
22
|
+
export const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
|
|
23
|
+
switch (refType) {
|
|
24
|
+
case 'schema':
|
|
25
|
+
return isRawEntry(value)
|
|
26
|
+
? toOptionalSchemasV3({ schemas: { [name]: value }, stackTrail, context })?.[name]
|
|
27
|
+
: undefined;
|
|
28
|
+
case 'parameter':
|
|
29
|
+
return isRawEntry(value)
|
|
30
|
+
? toOptionalParametersV3({ parameters: { [name]: value }, stackTrail, context })?.[name]
|
|
31
|
+
: undefined;
|
|
32
|
+
case 'response':
|
|
33
|
+
return isRawEntry(value)
|
|
34
|
+
? toOptionalResponsesV3({ responses: { [name]: value }, stackTrail, context })?.[name]
|
|
35
|
+
: undefined;
|
|
36
|
+
case 'requestBody':
|
|
37
|
+
return isRawEntry(value)
|
|
38
|
+
? toRequestBodiesV3({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
|
|
39
|
+
: undefined;
|
|
40
|
+
case 'header':
|
|
41
|
+
return isRawEntry(value)
|
|
42
|
+
? toComponentHeadersV3({ headers: { [name]: value }, stackTrail, context })?.[name]
|
|
43
|
+
: undefined;
|
|
44
|
+
case 'link':
|
|
45
|
+
return isRawEntry(value)
|
|
46
|
+
? toLinksV3({ links: { [name]: value }, stackTrail, context })?.[name]
|
|
47
|
+
: undefined;
|
|
48
|
+
case 'example':
|
|
49
|
+
// No components parser reads a single example by key, so the target
|
|
50
|
+
// is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
|
|
51
|
+
return isRawEntry(value)
|
|
52
|
+
? tryParseAt({
|
|
53
|
+
stackTrail,
|
|
54
|
+
key: name,
|
|
55
|
+
context,
|
|
56
|
+
type: 'INVALID_EXAMPLE',
|
|
57
|
+
parent: value,
|
|
58
|
+
fn: st => toExampleV3({ example: value, stackTrail: st, context })
|
|
59
|
+
})
|
|
60
|
+
: undefined;
|
|
61
|
+
case 'securityScheme':
|
|
62
|
+
return isRawEntry(value)
|
|
63
|
+
? toSecuritySchemesV3({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
|
|
64
|
+
: undefined;
|
|
65
|
+
default: {
|
|
66
|
+
const _exhaustive = refType;
|
|
67
|
+
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -43,7 +43,7 @@ import type { ModelEntry } from '../dsl/model/toModelEntry.js';
|
|
|
43
43
|
*
|
|
44
44
|
* const modelEntry = toModelEntry({
|
|
45
45
|
* id: 'typescript-models',
|
|
46
|
-
* transform: ({ context,
|
|
46
|
+
* transform: ({ context, ref }) => {}
|
|
47
47
|
* });
|
|
48
48
|
* // modelEntry.type === 'model'
|
|
49
49
|
* ```
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @fileoverview Caller options for projections.
|
|
3
3
|
*
|
|
4
4
|
* Options are typed data the CALLING generator passes when it inserts a
|
|
5
|
-
* peer: `context.insertModel(Peer,
|
|
5
|
+
* peer: `context.insertModel(Peer, ref, { options })`. Enrichments are
|
|
6
6
|
* the user's per-subject configuration and a variant selects one of them;
|
|
7
7
|
* options belong to the caller.
|
|
8
8
|
*
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @fileoverview Caller options for projections.
|
|
3
3
|
*
|
|
4
4
|
* Options are typed data the CALLING generator passes when it inserts a
|
|
5
|
-
* peer: `context.insertModel(Peer,
|
|
5
|
+
* peer: `context.insertModel(Peer, ref, { options })`. Enrichments are
|
|
6
6
|
* the user's per-subject configuration and a variant selects one of them;
|
|
7
7
|
* options belong to the caller.
|
|
8
8
|
*
|
package/esm/types/RefName.d.ts
CHANGED
|
@@ -99,14 +99,14 @@ import type { Brand } from './Brand.js';
|
|
|
99
99
|
* @example In generator contexts
|
|
100
100
|
* ```typescript
|
|
101
101
|
* class ModelGenerator extends ModelProjectionBase {
|
|
102
|
-
* constructor(args: {
|
|
102
|
+
* constructor(args: { ref: RefParts; ... }) {
|
|
103
103
|
* super(args);
|
|
104
|
-
* // this.refName is
|
|
104
|
+
* // this.ref.refName is the name of the model's ref
|
|
105
105
|
* }
|
|
106
106
|
*
|
|
107
107
|
* toDefinition(): Definition {
|
|
108
108
|
* // RefName ensures we're working with valid schema identifiers
|
|
109
|
-
* const schemaName = this.refName; // Type: RefName
|
|
109
|
+
* const schemaName = this.ref.refName; // Type: RefName
|
|
110
110
|
* return new Definition({
|
|
111
111
|
* identifier: createType(schemaName),
|
|
112
112
|
* // ...
|
|
@@ -7,7 +7,7 @@ import type { GenerateContextType } from '../context/generateTypes.js';
|
|
|
7
7
|
import type { CustomValue } from '../dsl/CustomValue.js';
|
|
8
8
|
import type { OasVoid } from '../oas/void/Void.js';
|
|
9
9
|
import type { GeneratorKey } from '../dsl/GeneratorKeys.js';
|
|
10
|
-
import type {
|
|
10
|
+
import type { RefParts } from '../helpers/refFns.js';
|
|
11
11
|
/**
|
|
12
12
|
* Union type representing all possible type system values in the SKMTC code generation system.
|
|
13
13
|
*
|
|
@@ -539,8 +539,8 @@ export type TypeSystemArgs<Schema extends SchemaType> = {
|
|
|
539
539
|
destinationPath: string;
|
|
540
540
|
/** The schema to transform */
|
|
541
541
|
schema: Schema;
|
|
542
|
-
/**
|
|
543
|
-
rootRef?:
|
|
542
|
+
/** The ref of the model whose value tree holds the schema */
|
|
543
|
+
rootRef?: RefParts;
|
|
544
544
|
/** Whether the schema field is required */
|
|
545
545
|
required: boolean | undefined;
|
|
546
546
|
};
|