@skmtc/core 0.44.2 → 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 +7 -6
- package/esm/context/generateTypes.js +2 -0
- 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/header/Header.js +4 -1
- package/esm/oas/parameter/Parameter.d.ts +1 -1
- package/esm/oas/parameter/Parameter.js +5 -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/missingSchema.d.ts +30 -0
- package/esm/parse/missingSchema.js +33 -0
- package/esm/parse/v3-0/header/toHeadersV3.js +5 -0
- package/esm/parse/v3-0/parameter/toParameterV3.js +11 -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-1/header/toHeadersV3.js +5 -0
- package/esm/parse/v3-1/parameter/toParameterV3.js +11 -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/header/toHeadersV3.js +5 -0
- package/esm/parse/v3-2/parameter/toParameterV3.js +11 -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 +7 -6
- package/script/context/generateTypes.js +2 -0
- 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/header/Header.js +4 -1
- package/script/oas/parameter/Parameter.d.ts +1 -1
- package/script/oas/parameter/Parameter.js +5 -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/missingSchema.d.ts +30 -0
- package/script/parse/missingSchema.js +38 -0
- package/script/parse/v3-0/header/toHeadersV3.js +5 -0
- package/script/parse/v3-0/parameter/toParameterV3.js +11 -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-1/header/toHeadersV3.js +5 -0
- package/script/parse/v3-1/parameter/toParameterV3.js +11 -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/header/toHeadersV3.js +5 -0
- package/script/parse/v3-2/parameter/toParameterV3.js +11 -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
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _ParseContext_instances, _ParseContext_refConsumers, _ParseContext_refErrors, _ParseContext_oasRefs, _ParseContext_rootFrames, _ParseContext_removeComponent, _ParseContext_removeConsumer, _ParseContext_removePathParameterConsumer,
|
|
13
|
+
var _ParseContext_instances, _ParseContext_refConsumers, _ParseContext_refErrors, _ParseContext_oasRefs, _ParseContext_refTargets, _ParseContext_refTarget, _ParseContext_issueIdentities, _ParseContext_rootFrames, _ParseContext_removeComponent, _ParseContext_parseRefTargets, _ParseContext_inRefTarget, _ParseContext_addIssue, _ParseContext_removeConsumer, _ParseContext_removePathParameterConsumer, _ParseContext_logDependencyIssue, _ParseContext_toDocumentTrail, _ParseContext_checkRefs, _ParseContext_toRefError, _ParseContext_toLoopOf, _ParseContext_removeHolder;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ParseContext = void 0;
|
|
16
16
|
/**
|
|
@@ -44,20 +44,52 @@ const StackTrail_js_1 = require("./StackTrail.js");
|
|
|
44
44
|
const isPlainObject_js_1 = require("../parse/isPlainObject.js");
|
|
45
45
|
const pathParameters_js_1 = require("../parse/pathParameters.js");
|
|
46
46
|
const SerializedError_js_1 = require("../types/SerializedError.js");
|
|
47
|
+
const tryParseAt_js_1 = require("./tryParseAt.js");
|
|
47
48
|
const DanglingRefError_js_1 = require("../oas/ref/DanglingRefError.js");
|
|
48
49
|
const refFns_js_1 = require("../helpers/refFns.js");
|
|
50
|
+
const toRefTargetV3_js_1 = require("../parse/v3-0/ref/toRefTargetV3.js");
|
|
51
|
+
const toRefTargetV3_js_2 = require("../parse/v3-1/ref/toRefTargetV3.js");
|
|
52
|
+
const toRefTargetV3_js_3 = require("../parse/v3-2/ref/toRefTargetV3.js");
|
|
49
53
|
/**
|
|
50
|
-
* The key a `$ref`'s consumers and errors are kept under. A
|
|
51
|
-
* `#/components/<bucket
|
|
52
|
-
*
|
|
54
|
+
* The key a `$ref`'s consumers and errors are kept under. A component ref
|
|
55
|
+
* (`#/components/<bucket>/<name>`) is keyed by the name it resolves,
|
|
56
|
+
* unescaped, which is the key `StackTrail.toStackRef()` gives that
|
|
53
57
|
* component's own errors: `#/components/schemas/Foo%20Bar` is kept under
|
|
54
|
-
* `#/components/schemas/Foo Bar`. Any other
|
|
58
|
+
* `#/components/schemas/Foo Bar`. Any other ref is keyed by its whole
|
|
59
|
+
* pointer in one spelling (`toRefPointer`), which is also the key its
|
|
60
|
+
* parsed target is kept under.
|
|
55
61
|
*/
|
|
56
|
-
const toRefKey = (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return bucket === undefined ? $ref : `#/components/${bucket}/${(0, refFns_js_1.toRefName)($ref)}`;
|
|
62
|
+
const toRefKey = ({ refName, refPath }) => {
|
|
63
|
+
const bucket = (0, refFns_js_1.toRefPathBucket)(refPath);
|
|
64
|
+
return bucket === undefined ? (0, refFns_js_1.toRefPointer)({ refName, refPath }) : `#/components/${bucket}/${refName}`;
|
|
60
65
|
};
|
|
66
|
+
/** The issue logged when a ref target's parser throws. */
|
|
67
|
+
const toInvalidType = (refType) => {
|
|
68
|
+
switch (refType) {
|
|
69
|
+
case 'schema':
|
|
70
|
+
return 'INVALID_SCHEMA';
|
|
71
|
+
case 'requestBody':
|
|
72
|
+
return 'INVALID_REQUEST_BODY';
|
|
73
|
+
case 'parameter':
|
|
74
|
+
return 'INVALID_PARAMETER';
|
|
75
|
+
case 'response':
|
|
76
|
+
case 'link':
|
|
77
|
+
// A link has no type of its own: in the document's walk its response reports it.
|
|
78
|
+
return 'INVALID_RESPONSE';
|
|
79
|
+
case 'example':
|
|
80
|
+
return 'INVALID_EXAMPLE';
|
|
81
|
+
case 'header':
|
|
82
|
+
return 'INVALID_HEADER';
|
|
83
|
+
case 'securityScheme':
|
|
84
|
+
return 'INVALID_SECURITY_SCHEME';
|
|
85
|
+
default: {
|
|
86
|
+
const _exhaustive = refType;
|
|
87
|
+
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
/** Two issues with the same level, type, location and message are the same issue. */
|
|
92
|
+
const toIssueIdentity = (issue) => [issue.level, issue.type, issue.location, issue.message].join('\u0000');
|
|
61
93
|
/** The stored form of an issue: an error's `cause` as a `SerializedError`. */
|
|
62
94
|
const toParseIssue = (issue) => {
|
|
63
95
|
if (issue.level !== 'error') {
|
|
@@ -134,6 +166,16 @@ class ParseContext {
|
|
|
134
166
|
);
|
|
135
167
|
/** Each OAS ref and the place it is written, which `#checkRefs` resolves once the document is parsed. */
|
|
136
168
|
_ParseContext_oasRefs.set(this, []
|
|
169
|
+
/** The key (`toRefKey`) of each ref target `#parseRefTargets` parsed. */
|
|
170
|
+
);
|
|
171
|
+
/** The key (`toRefKey`) of each ref target `#parseRefTargets` parsed. */
|
|
172
|
+
_ParseContext_refTargets.set(this, new Set()
|
|
173
|
+
/** The key of the ref target `#inRefTarget` runs for; `undefined` in the document's own walk. */
|
|
174
|
+
);
|
|
175
|
+
/** The key of the ref target `#inRefTarget` runs for; `undefined` in the document's own walk. */
|
|
176
|
+
_ParseContext_refTarget.set(this, void 0);
|
|
177
|
+
/** What identifies each issue logged so far (`toIssueIdentity`). */
|
|
178
|
+
_ParseContext_issueIdentities.set(this, new Set()
|
|
137
179
|
/**
|
|
138
180
|
* Frames of the trail `parse()` was called with (`[traceId, spanId,
|
|
139
181
|
* 'parse']` through `toArtifacts`). Every trail built during the walk
|
|
@@ -263,6 +305,7 @@ class ParseContext {
|
|
|
263
305
|
stackTrail,
|
|
264
306
|
context: this
|
|
265
307
|
});
|
|
308
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_parseRefTargets).call(this, toRefTargetV3_js_1.toRefTargetV3);
|
|
266
309
|
break;
|
|
267
310
|
case '3.1':
|
|
268
311
|
oasState.oasDocument.fields = (0, toDocumentFieldsV3_js_2.toDocumentFieldsV3)({
|
|
@@ -270,6 +313,7 @@ class ParseContext {
|
|
|
270
313
|
stackTrail,
|
|
271
314
|
context: this
|
|
272
315
|
});
|
|
316
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_parseRefTargets).call(this, toRefTargetV3_js_2.toRefTargetV3);
|
|
273
317
|
break;
|
|
274
318
|
case '3.2':
|
|
275
319
|
oasState.oasDocument.fields = (0, toDocumentFieldsV3_js_3.toDocumentFieldsV3)({
|
|
@@ -277,6 +321,7 @@ class ParseContext {
|
|
|
277
321
|
stackTrail,
|
|
278
322
|
context: this
|
|
279
323
|
});
|
|
324
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_parseRefTargets).call(this, toRefTargetV3_js_3.toRefTargetV3);
|
|
280
325
|
break;
|
|
281
326
|
default: {
|
|
282
327
|
const _exhaustive = dialect;
|
|
@@ -330,7 +375,15 @@ class ParseContext {
|
|
|
330
375
|
pending.forEach(({ refKey }) => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeComponent).call(this, refKey));
|
|
331
376
|
// `pending` grows while it is walked: each removed component queues its own consumers.
|
|
332
377
|
for (const { refKey, rootCause } of pending) {
|
|
333
|
-
for (const consumer of __classPrivateFieldGet(this, _ParseContext_refConsumers, "f").get(refKey) ?? []) {
|
|
378
|
+
for (const { consumer, refTarget } of __classPrivateFieldGet(this, _ParseContext_refConsumers, "f").get(refKey) ?? []) {
|
|
379
|
+
// The ref is inside a ref target: the target is removed, and what refers to it next.
|
|
380
|
+
if (refTarget !== undefined) {
|
|
381
|
+
if (this.oasDocument.removeRefTarget(refTarget) !== undefined) {
|
|
382
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_inRefTarget).call(this, refTarget, () => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_logDependencyIssue).call(this, { location: consumer.toString(), refKey, rootCause }));
|
|
383
|
+
pending.push({ refKey: refTarget, rootCause });
|
|
384
|
+
}
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
334
387
|
const documentTrail = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentTrail).call(this, consumer);
|
|
335
388
|
const removedLocations = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeConsumer).call(this, consumer, documentTrail);
|
|
336
389
|
removedLocations.forEach(location => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_logDependencyIssue).call(this, { location, refKey, rootCause }));
|
|
@@ -375,12 +428,13 @@ class ParseContext {
|
|
|
375
428
|
* would use type names or qualified field paths.
|
|
376
429
|
*/
|
|
377
430
|
registerRef(consumer, refKey) {
|
|
431
|
+
const refConsumer = { consumer, refTarget: __classPrivateFieldGet(this, _ParseContext_refTarget, "f") };
|
|
378
432
|
const existing = __classPrivateFieldGet(this, _ParseContext_refConsumers, "f").get(refKey);
|
|
379
433
|
if (existing) {
|
|
380
|
-
existing.push(
|
|
434
|
+
existing.push(refConsumer);
|
|
381
435
|
}
|
|
382
436
|
else {
|
|
383
|
-
__classPrivateFieldGet(this, _ParseContext_refConsumers, "f").set(refKey, [
|
|
437
|
+
__classPrivateFieldGet(this, _ParseContext_refConsumers, "f").set(refKey, [refConsumer]);
|
|
384
438
|
}
|
|
385
439
|
}
|
|
386
440
|
/**
|
|
@@ -390,8 +444,8 @@ class ParseContext {
|
|
|
390
444
|
* resolve it there.
|
|
391
445
|
*/
|
|
392
446
|
registerOasRef(consumer, ref) {
|
|
393
|
-
this.registerRef(consumer, toRefKey(ref
|
|
394
|
-
__classPrivateFieldGet(this, _ParseContext_oasRefs, "f").push({ consumer, ref });
|
|
447
|
+
this.registerRef(consumer, toRefKey(ref));
|
|
448
|
+
__classPrivateFieldGet(this, _ParseContext_oasRefs, "f").push({ consumer, ref, refTarget: __classPrivateFieldGet(this, _ParseContext_refTarget, "f") });
|
|
395
449
|
}
|
|
396
450
|
/**
|
|
397
451
|
* What a merge reads in place of a `$ref` that names nothing: an `allOf`
|
|
@@ -451,8 +505,8 @@ class ParseContext {
|
|
|
451
505
|
* manifest).
|
|
452
506
|
*/
|
|
453
507
|
logIssueAt(issue, parent) {
|
|
454
|
-
this.
|
|
455
|
-
if (!this.silent) {
|
|
508
|
+
const added = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, toParseIssue(issue));
|
|
509
|
+
if (added && !this.silent) {
|
|
456
510
|
this.logger.warn({
|
|
457
511
|
protocol: issue.protocol,
|
|
458
512
|
level: issue.level,
|
|
@@ -486,7 +540,7 @@ class ParseContext {
|
|
|
486
540
|
// points at. No-op for non-component trails (and for GQL
|
|
487
541
|
// trails) because `toStackRef` returns `undefined` and
|
|
488
542
|
// `registerRefError` ignores undefined refs.
|
|
489
|
-
this.registerRefError(issue.cause ?? issue.message, __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentTrail).call(this, stackTrail).toStackRef(), location);
|
|
543
|
+
this.registerRefError(issue.cause ?? issue.message, __classPrivateFieldGet(this, _ParseContext_refTarget, "f") ?? __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentTrail).call(this, stackTrail).toStackRef(), location);
|
|
490
544
|
this.logIssueAt({
|
|
491
545
|
protocol,
|
|
492
546
|
level: 'error',
|
|
@@ -569,14 +623,65 @@ class ParseContext {
|
|
|
569
623
|
}
|
|
570
624
|
}
|
|
571
625
|
exports.ParseContext = ParseContext;
|
|
572
|
-
_ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMap(), _ParseContext_oasRefs = new WeakMap(), _ParseContext_rootFrames = new WeakMap(), _ParseContext_instances = new WeakSet(), _ParseContext_removeComponent = function _ParseContext_removeComponent(refKey) {
|
|
626
|
+
_ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMap(), _ParseContext_oasRefs = new WeakMap(), _ParseContext_refTargets = new WeakMap(), _ParseContext_refTarget = new WeakMap(), _ParseContext_issueIdentities = new WeakMap(), _ParseContext_rootFrames = new WeakMap(), _ParseContext_instances = new WeakSet(), _ParseContext_removeComponent = function _ParseContext_removeComponent(refKey) {
|
|
573
627
|
if (this.protocol.type !== 'oas') {
|
|
574
628
|
return;
|
|
575
629
|
}
|
|
630
|
+
if (__classPrivateFieldGet(this, _ParseContext_refTargets, "f").has(refKey)) {
|
|
631
|
+
this.protocol.oasDocument.removeRefTarget(refKey);
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
576
634
|
const match = /^#\/components\/([^/]+)\/(.+)$/.exec(refKey);
|
|
577
635
|
if (match) {
|
|
578
636
|
this.protocol.oasDocument.removeItem(new StackTrail_js_1.StackTrail(['components', match[1], match[2]]));
|
|
579
637
|
}
|
|
638
|
+
}, _ParseContext_parseRefTargets = function _ParseContext_parseRefTargets(toRefTarget) {
|
|
639
|
+
if (this.protocol.type !== 'oas') {
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
const { oasDocument, documentObject } = this.protocol;
|
|
643
|
+
for (const { ref } of __classPrivateFieldGet(this, _ParseContext_oasRefs, "f")) {
|
|
644
|
+
const key = toRefKey(ref);
|
|
645
|
+
// A ref to a component, of its own kind or not, is resolved in
|
|
646
|
+
// `components`; `#checkRefs` reports one of the wrong kind.
|
|
647
|
+
if (ref.refName === '' || (0, refFns_js_1.toRefPathBucket)(ref.refPath) !== undefined || __classPrivateFieldGet(this, _ParseContext_refTargets, "f").has(key)) {
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
const value = (0, refFns_js_1.toRawRefTarget)(documentObject, ref);
|
|
651
|
+
if (!(0, isPlainObject_js_1.isPlainObject)(value)) {
|
|
652
|
+
continue;
|
|
653
|
+
}
|
|
654
|
+
__classPrivateFieldGet(this, _ParseContext_refTargets, "f").add(key);
|
|
655
|
+
const parent = new StackTrail_js_1.StackTrail([...__classPrivateFieldGet(this, _ParseContext_rootFrames, "f"), ...(0, refFns_js_1.toRefPathSegments)(ref.refPath)]);
|
|
656
|
+
const target = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_inRefTarget).call(this, key, () => (0, tryParseAt_js_1.tryParseAt)({
|
|
657
|
+
stackTrail: parent,
|
|
658
|
+
key: ref.refName,
|
|
659
|
+
context: this,
|
|
660
|
+
type: toInvalidType(ref.refType),
|
|
661
|
+
parent: value,
|
|
662
|
+
fn: () => toRefTarget({ refType: ref.refType, name: ref.refName, value, stackTrail: parent, context: this })
|
|
663
|
+
}));
|
|
664
|
+
if (target !== undefined) {
|
|
665
|
+
oasDocument.setRefTarget(key, target);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}, _ParseContext_inRefTarget = function _ParseContext_inRefTarget(key, fn) {
|
|
669
|
+
const previous = __classPrivateFieldGet(this, _ParseContext_refTarget, "f");
|
|
670
|
+
__classPrivateFieldSet(this, _ParseContext_refTarget, key, "f");
|
|
671
|
+
try {
|
|
672
|
+
return fn();
|
|
673
|
+
}
|
|
674
|
+
finally {
|
|
675
|
+
__classPrivateFieldSet(this, _ParseContext_refTarget, previous, "f");
|
|
676
|
+
}
|
|
677
|
+
}, _ParseContext_addIssue = function _ParseContext_addIssue(issue) {
|
|
678
|
+
const identity = toIssueIdentity(issue);
|
|
679
|
+
if (__classPrivateFieldGet(this, _ParseContext_refTarget, "f") !== undefined && __classPrivateFieldGet(this, _ParseContext_issueIdentities, "f").has(identity)) {
|
|
680
|
+
return false;
|
|
681
|
+
}
|
|
682
|
+
__classPrivateFieldGet(this, _ParseContext_issueIdentities, "f").add(identity);
|
|
683
|
+
this.issues.push(issue);
|
|
684
|
+
return true;
|
|
580
685
|
}, _ParseContext_removeConsumer = function _ParseContext_removeConsumer(consumer, documentTrail) {
|
|
581
686
|
switch (this.protocol.type) {
|
|
582
687
|
case 'oas': {
|
|
@@ -615,7 +720,9 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
615
720
|
: [];
|
|
616
721
|
const rawEntry = rawEntries[Number(index)];
|
|
617
722
|
const entryRef = (0, isPlainObject_js_1.isPlainObject)(rawEntry) && typeof rawEntry.$ref === 'string' ? rawEntry.$ref : undefined;
|
|
618
|
-
const nameAndIn = (0, pathParameters_js_1.toNameAndIn)(entryRef === undefined
|
|
723
|
+
const nameAndIn = (0, pathParameters_js_1.toNameAndIn)(entryRef === undefined
|
|
724
|
+
? rawEntry
|
|
725
|
+
: (0, refFns_js_1.toRawRefTarget)(documentObject, (0, refFns_js_1.toRefParts)({ $ref: entryRef })));
|
|
619
726
|
const broken = [{ location: documentTrail.toString(), message: '', ...nameAndIn }];
|
|
620
727
|
const operations = first === 'paths'
|
|
621
728
|
? oasDocument.operations.filter(({ path }) => path === second)
|
|
@@ -637,13 +744,6 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
637
744
|
: [new StackTrail_js_1.StackTrail([...prefix, first, second, method]).toString()];
|
|
638
745
|
});
|
|
639
746
|
return removedLocations;
|
|
640
|
-
}, _ParseContext_toRawComponentParameter = function _ParseContext_toRawComponentParameter($ref) {
|
|
641
|
-
if (this.protocol.type !== 'oas') {
|
|
642
|
-
return undefined;
|
|
643
|
-
}
|
|
644
|
-
const match = /^#\/components\/parameters\/(.+)$/.exec($ref);
|
|
645
|
-
const parameters = this.protocol.documentObject.components?.parameters;
|
|
646
|
-
return match && (0, isPlainObject_js_1.isPlainObject)(parameters) ? parameters[match[1]] : undefined;
|
|
647
747
|
}, _ParseContext_logDependencyIssue = function _ParseContext_logDependencyIssue({ location, refKey, rootCause }) {
|
|
648
748
|
const { error } = rootCause;
|
|
649
749
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -651,7 +751,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
651
751
|
const message = `Depends on '${refKey}', removed because of the error${at}: ${errorMessage}`;
|
|
652
752
|
switch (this.protocol.type) {
|
|
653
753
|
case 'oas':
|
|
654
|
-
this.
|
|
754
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, {
|
|
655
755
|
protocol: 'oas',
|
|
656
756
|
level: 'error',
|
|
657
757
|
type: 'INVALID_DEPENDENCY_REF',
|
|
@@ -661,7 +761,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
661
761
|
});
|
|
662
762
|
break;
|
|
663
763
|
case 'gql':
|
|
664
|
-
this.
|
|
764
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, {
|
|
665
765
|
protocol: 'gql',
|
|
666
766
|
level: 'error',
|
|
667
767
|
type: 'INVALID_DEPENDENCY_REF',
|
|
@@ -683,8 +783,8 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
683
783
|
rootFrames.every((frame, index) => frames[index] === frame);
|
|
684
784
|
return startsWithRoot ? new StackTrail_js_1.StackTrail(frames.slice(rootFrames.length)) : stackTrail;
|
|
685
785
|
}, _ParseContext_checkRefs = function _ParseContext_checkRefs() {
|
|
686
|
-
__classPrivateFieldGet(this, _ParseContext_oasRefs, "f").forEach(({ consumer, ref }) => {
|
|
687
|
-
if (__classPrivateFieldGet(this, _ParseContext_refErrors, "f").has(toRefKey(ref
|
|
786
|
+
__classPrivateFieldGet(this, _ParseContext_oasRefs, "f").forEach(({ consumer, ref, refTarget }) => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_inRefTarget).call(this, refTarget, () => {
|
|
787
|
+
if (__classPrivateFieldGet(this, _ParseContext_refErrors, "f").has(toRefKey(ref))) {
|
|
688
788
|
return;
|
|
689
789
|
}
|
|
690
790
|
const error = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toRefError).call(this, ref);
|
|
@@ -694,6 +794,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
694
794
|
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
|
|
695
795
|
consumer,
|
|
696
796
|
ref,
|
|
797
|
+
refTarget,
|
|
697
798
|
error,
|
|
698
799
|
type: 'REF_TYPE_MISMATCH',
|
|
699
800
|
message: `${message}, so what holds it is removed.`
|
|
@@ -712,13 +813,14 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
712
813
|
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
|
|
713
814
|
consumer,
|
|
714
815
|
ref,
|
|
816
|
+
refTarget,
|
|
715
817
|
error,
|
|
716
818
|
type: 'DANGLING_REF',
|
|
717
819
|
message: `${error.message}, so what holds it is removed. To keep it, list '${ref.refType}' in system.danglingRefs.`
|
|
718
820
|
});
|
|
719
821
|
}
|
|
720
822
|
}
|
|
721
|
-
});
|
|
823
|
+
}));
|
|
722
824
|
}, _ParseContext_toRefError = function _ParseContext_toRefError(ref) {
|
|
723
825
|
try {
|
|
724
826
|
ref.resolveOnce();
|
|
@@ -737,7 +839,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
737
839
|
// A ref further on names nothing or the wrong kind: it reports that itself.
|
|
738
840
|
return undefined;
|
|
739
841
|
}
|
|
740
|
-
}, _ParseContext_removeHolder = function _ParseContext_removeHolder({ consumer, ref, error, type, message }) {
|
|
842
|
+
}, _ParseContext_removeHolder = function _ParseContext_removeHolder({ consumer, ref, refTarget, error, type, message }) {
|
|
741
843
|
this.logIssueNoKey({
|
|
742
844
|
level: 'error',
|
|
743
845
|
message,
|
|
@@ -747,7 +849,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
747
849
|
type
|
|
748
850
|
});
|
|
749
851
|
const documentTrail = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentTrail).call(this, consumer);
|
|
750
|
-
if (documentTrail.toStackRef() !== undefined) {
|
|
852
|
+
if (refTarget !== undefined || documentTrail.toStackRef() !== undefined) {
|
|
751
853
|
return;
|
|
752
854
|
}
|
|
753
855
|
const location = consumer.toString();
|
|
@@ -17,7 +17,7 @@ import type { OasRef } from '../oas/ref/Ref.js';
|
|
|
17
17
|
import type { OasVoid } from '../oas/void/Void.js';
|
|
18
18
|
import type { ModelProjection, NormalizedModelProjection } from '../dsl/model/types.js';
|
|
19
19
|
import type { ContentSettings } from '../dsl/ContentSettings.js';
|
|
20
|
-
import type {
|
|
20
|
+
import type { RefParts } from '../helpers/refFns.js';
|
|
21
21
|
import type { SchemaToNonRef, TypeSystemOutput } from '../types/TypeSystem.js';
|
|
22
22
|
import type { FileBase } from '../dsl/FileBase.js';
|
|
23
23
|
import type { ImportBase } from '../dsl/ImportBase.js';
|
|
@@ -204,7 +204,7 @@ export type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3
|
|
|
204
204
|
* catches. Its `location` names the entry and phase, for example
|
|
205
205
|
* `toArtifacts:render`.
|
|
206
206
|
*/
|
|
207
|
-
export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISSING_STRING_TYPE' | 'MISSING_ARRAY_TYPE' | 'MISSING_BOOLEAN_TYPE' | 'MISSING_RESPONSES' | 'MISSING_INFO' | 'EMPTY_PARAMETER' | 'INVALID_EXAMPLE' | 'INVALID_ENUM' | 'INVALID_DEFAULT' | 'INVALID_NULLABLE' | 'UNEXPECTED_FORMAT' | 'INVALID_RESPONSE' | 'INVALID_REQUEST_BODY' | 'INVALID_HEADER' | 'INVALID_FORMAT' | 'INVALID_OPERATION' | 'INVALID_SCHEMA' | 'INVALID_PARAMETER' | 'INVALID_SECURITY_SCHEME' | 'INVALID_DEPENDENCY_REF' | 'EXAMPLE_AND_EXAMPLES_DEFINED' | 'INVALID_TAG_PARENT' | 'INVALID_TAG' | 'INVALID_EXTERNAL_DOCS' | 'UNSUPPORTED_OPERATION_METHOD' | 'WILDCARD_MEDIA_TYPE' | 'NO_JSON_MEDIA_TYPE' | 'ALLOF_CONTRADICTION' | 'ANYOF_AS_UNKNOWN' | 'DANGLING_REF' | 'REF_TYPE_MISMATCH' | 'RUN_FAILED';
|
|
207
|
+
export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISSING_STRING_TYPE' | 'MISSING_ARRAY_TYPE' | 'MISSING_BOOLEAN_TYPE' | 'MISSING_RESPONSES' | 'MISSING_INFO' | 'EMPTY_PARAMETER' | 'MISSING_PARAMETER_SCHEMA' | 'MISSING_HEADER_SCHEMA' | 'INVALID_EXAMPLE' | 'INVALID_ENUM' | 'INVALID_DEFAULT' | 'INVALID_NULLABLE' | 'UNEXPECTED_FORMAT' | 'INVALID_RESPONSE' | 'INVALID_REQUEST_BODY' | 'INVALID_HEADER' | 'INVALID_FORMAT' | 'INVALID_OPERATION' | 'INVALID_SCHEMA' | 'INVALID_PARAMETER' | 'INVALID_SECURITY_SCHEME' | 'INVALID_DEPENDENCY_REF' | 'EXAMPLE_AND_EXAMPLES_DEFINED' | 'INVALID_TAG_PARENT' | 'INVALID_TAG' | 'INVALID_EXTERNAL_DOCS' | 'UNSUPPORTED_OPERATION_METHOD' | 'WILDCARD_MEDIA_TYPE' | 'NO_JSON_MEDIA_TYPE' | 'ALLOF_CONTRADICTION' | 'ANYOF_AS_UNKNOWN' | 'DANGLING_REF' | 'REF_TYPE_MISMATCH' | 'RUN_FAILED';
|
|
208
208
|
/**
|
|
209
209
|
* Valibot schema for {@link OasIssueType}. Annotation deliberately omitted
|
|
210
210
|
* so the precise literal-union output type flows through to consumers
|
|
@@ -212,7 +212,7 @@ export type OasIssueType = 'UNEXPECTED_PROPERTY' | 'MISSING_OBJECT_TYPE' | 'MISS
|
|
|
212
212
|
* this list and {@link OasIssueType} is caught by `assertSchemaMatchesType`
|
|
213
213
|
* below.
|
|
214
214
|
*/
|
|
215
|
-
export declare const oasIssueType: v.UnionSchema<[v.LiteralSchema<"UNEXPECTED_PROPERTY", undefined>, v.LiteralSchema<"MISSING_OBJECT_TYPE", undefined>, v.LiteralSchema<"MISSING_STRING_TYPE", undefined>, v.LiteralSchema<"MISSING_ARRAY_TYPE", undefined>, v.LiteralSchema<"MISSING_BOOLEAN_TYPE", undefined>, v.LiteralSchema<"MISSING_RESPONSES", undefined>, v.LiteralSchema<"MISSING_INFO", undefined>, v.LiteralSchema<"EMPTY_PARAMETER", undefined>, v.LiteralSchema<"INVALID_EXAMPLE", undefined>, v.LiteralSchema<"INVALID_ENUM", undefined>, v.LiteralSchema<"INVALID_DEFAULT", undefined>, v.LiteralSchema<"INVALID_NULLABLE", undefined>, v.LiteralSchema<"UNEXPECTED_FORMAT", undefined>, v.LiteralSchema<"INVALID_RESPONSE", undefined>, v.LiteralSchema<"INVALID_REQUEST_BODY", undefined>, v.LiteralSchema<"INVALID_HEADER", undefined>, v.LiteralSchema<"INVALID_FORMAT", undefined>, v.LiteralSchema<"INVALID_OPERATION", undefined>, v.LiteralSchema<"INVALID_SCHEMA", undefined>, v.LiteralSchema<"INVALID_PARAMETER", undefined>, v.LiteralSchema<"INVALID_SECURITY_SCHEME", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"EXAMPLE_AND_EXAMPLES_DEFINED", undefined>, v.LiteralSchema<"INVALID_TAG_PARENT", undefined>, v.LiteralSchema<"INVALID_TAG", undefined>, v.LiteralSchema<"INVALID_EXTERNAL_DOCS", undefined>, v.LiteralSchema<"UNSUPPORTED_OPERATION_METHOD", undefined>, v.LiteralSchema<"WILDCARD_MEDIA_TYPE", undefined>, v.LiteralSchema<"NO_JSON_MEDIA_TYPE", undefined>, v.LiteralSchema<"ALLOF_CONTRADICTION", undefined>, v.LiteralSchema<"ANYOF_AS_UNKNOWN", undefined>, v.LiteralSchema<"DANGLING_REF", undefined>, v.LiteralSchema<"REF_TYPE_MISMATCH", undefined>, v.LiteralSchema<"RUN_FAILED", undefined>], undefined>;
|
|
215
|
+
export declare const oasIssueType: v.UnionSchema<[v.LiteralSchema<"UNEXPECTED_PROPERTY", undefined>, v.LiteralSchema<"MISSING_OBJECT_TYPE", undefined>, v.LiteralSchema<"MISSING_STRING_TYPE", undefined>, v.LiteralSchema<"MISSING_ARRAY_TYPE", undefined>, v.LiteralSchema<"MISSING_BOOLEAN_TYPE", undefined>, v.LiteralSchema<"MISSING_RESPONSES", undefined>, v.LiteralSchema<"MISSING_INFO", undefined>, v.LiteralSchema<"EMPTY_PARAMETER", undefined>, v.LiteralSchema<"MISSING_PARAMETER_SCHEMA", undefined>, v.LiteralSchema<"MISSING_HEADER_SCHEMA", undefined>, v.LiteralSchema<"INVALID_EXAMPLE", undefined>, v.LiteralSchema<"INVALID_ENUM", undefined>, v.LiteralSchema<"INVALID_DEFAULT", undefined>, v.LiteralSchema<"INVALID_NULLABLE", undefined>, v.LiteralSchema<"UNEXPECTED_FORMAT", undefined>, v.LiteralSchema<"INVALID_RESPONSE", undefined>, v.LiteralSchema<"INVALID_REQUEST_BODY", undefined>, v.LiteralSchema<"INVALID_HEADER", undefined>, v.LiteralSchema<"INVALID_FORMAT", undefined>, v.LiteralSchema<"INVALID_OPERATION", undefined>, v.LiteralSchema<"INVALID_SCHEMA", undefined>, v.LiteralSchema<"INVALID_PARAMETER", undefined>, v.LiteralSchema<"INVALID_SECURITY_SCHEME", undefined>, v.LiteralSchema<"INVALID_DEPENDENCY_REF", undefined>, v.LiteralSchema<"EXAMPLE_AND_EXAMPLES_DEFINED", undefined>, v.LiteralSchema<"INVALID_TAG_PARENT", undefined>, v.LiteralSchema<"INVALID_TAG", undefined>, v.LiteralSchema<"INVALID_EXTERNAL_DOCS", undefined>, v.LiteralSchema<"UNSUPPORTED_OPERATION_METHOD", undefined>, v.LiteralSchema<"WILDCARD_MEDIA_TYPE", undefined>, v.LiteralSchema<"NO_JSON_MEDIA_TYPE", undefined>, v.LiteralSchema<"ALLOF_CONTRADICTION", undefined>, v.LiteralSchema<"ANYOF_AS_UNKNOWN", undefined>, v.LiteralSchema<"DANGLING_REF", undefined>, v.LiteralSchema<"REF_TYPE_MISMATCH", undefined>, v.LiteralSchema<"RUN_FAILED", undefined>], undefined>;
|
|
216
216
|
export type GenerateResult = {
|
|
217
217
|
files: Map<string, FileBase>;
|
|
218
218
|
previews: Record<string, Preview>;
|
|
@@ -341,7 +341,8 @@ export type FindDefinitionArgs = PickArgs & {
|
|
|
341
341
|
* @template EnrichmentType - Optional enrichment type for the model
|
|
342
342
|
*/
|
|
343
343
|
export type BuildModelSettingsArgs<V extends GeneratedValue, EnrichmentType = undefined, ProjectionOptions = undefined> = {
|
|
344
|
-
|
|
344
|
+
/** The model's ref; an `OasRef` fits it. */
|
|
345
|
+
ref: RefParts;
|
|
345
346
|
projection: ModelProjection<V, EnrichmentType, ProjectionOptions>;
|
|
346
347
|
/**
|
|
347
348
|
* Model variant whose enrichment / identifier / export path
|
|
@@ -475,12 +476,12 @@ export type GenerateContextType = {
|
|
|
475
476
|
addFile: <File extends FileBase>(file: File) => File;
|
|
476
477
|
insertOperation: <V extends GeneratedValue, EnrichmentType = undefined, ProjectionOptions = undefined>(args: InsertOperationArgs<V, EnrichmentType, ProjectionOptions>) => Inserted<V, EnrichmentType>;
|
|
477
478
|
insertNormalizedModel: <V extends GeneratedValue, Schema extends OasSchema | OasRef<'schema'> | OasVoid, EnrichmentType, ProjectionOptions = undefined>(projection: NormalizedModelProjection<V, EnrichmentType, ProjectionOptions>, { schema, fallbackName, destinationPath }: InsertNormalizedModelArgs<Schema>, ...rest: ProjectionOptionsRest<InsertNormalizedModelOptions<ProjectionOptions>, ProjectionOptions>) => InsertNormalizedModelReturn<V, Schema>;
|
|
478
|
-
insertModel: <V extends GeneratedValue, EnrichmentType, ProjectionOptions = undefined>(projection: ModelProjection<V, EnrichmentType, ProjectionOptions>,
|
|
479
|
+
insertModel: <V extends GeneratedValue, EnrichmentType, ProjectionOptions = undefined>(projection: ModelProjection<V, EnrichmentType, ProjectionOptions>, ref: RefParts, ...rest: ProjectionOptionsRest<InsertModelOptions<ProjectionOptions>, ProjectionOptions>) => Inserted<V, EnrichmentType>;
|
|
479
480
|
toOperationContentSettings: <V extends GeneratedValue, EnrichmentType, ProjectionOptions>(args: ToOperationSettingsArgs<V, EnrichmentType, ProjectionOptions>) => ContentSettings<EnrichmentType>;
|
|
480
481
|
insertWebhook: <V extends GeneratedValue, EnrichmentType = undefined, ProjectionOptions = undefined>(args: InsertWebhookArgs<V, EnrichmentType, ProjectionOptions>) => Inserted<V, EnrichmentType>;
|
|
481
482
|
toWebhookContentSettings: <V extends GeneratedValue, EnrichmentType, ProjectionOptions>(args: ToWebhookSettingsArgs<V, EnrichmentType, ProjectionOptions>) => ContentSettings<EnrichmentType>;
|
|
482
483
|
toModelContentSettings: <V extends GeneratedValue, EnrichmentType, ProjectionOptions>(args: BuildModelSettingsArgs<V, EnrichmentType, ProjectionOptions>) => ContentSettings<EnrichmentType>;
|
|
483
|
-
resolveSchemaRefOnce: (
|
|
484
|
+
resolveSchemaRefOnce: (ref: RefParts) => OasSchema | OasRef<'schema'>;
|
|
484
485
|
/** The Definition named `name` in `exportPath` (or inside the declaration `into`), or `undefined`. */
|
|
485
486
|
findDefinition: ({ name, exportPath, into }: FindDefinitionArgs) => DefinitionBase | undefined;
|
|
486
487
|
/**
|
|
@@ -51,6 +51,8 @@ exports.oasIssueType = v.union([
|
|
|
51
51
|
v.literal('MISSING_RESPONSES'),
|
|
52
52
|
v.literal('MISSING_INFO'),
|
|
53
53
|
v.literal('EMPTY_PARAMETER'),
|
|
54
|
+
v.literal('MISSING_PARAMETER_SCHEMA'),
|
|
55
|
+
v.literal('MISSING_HEADER_SCHEMA'),
|
|
54
56
|
v.literal('INVALID_EXAMPLE'),
|
|
55
57
|
v.literal('INVALID_ENUM'),
|
|
56
58
|
v.literal('INVALID_DEFAULT'),
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
*
|
|
57
57
|
* const modelKey = toModelGeneratorKey({
|
|
58
58
|
* generatorId: 'typescript-models',
|
|
59
|
-
* refName: 'User' as RefName,
|
|
59
|
+
* ref: { refName: 'User' as RefName, refPath: '#/components/schemas' },
|
|
60
60
|
* variant: 'main'
|
|
61
61
|
* });
|
|
62
62
|
* ```
|
|
@@ -68,8 +68,8 @@ import type { OasOperation } from '../oas/operation/Operation.js';
|
|
|
68
68
|
import type { OasWebhook } from '../oas/webhook/Webhook.js';
|
|
69
69
|
import type { GqlOperation, GqlRootKind } from '../gql/operation/GqlOperation.js';
|
|
70
70
|
import type { Brand } from '../types/Brand.js';
|
|
71
|
-
import type { RefName } from '../types/RefName.js';
|
|
72
71
|
import { type Method } from '../types/Method.js';
|
|
72
|
+
import { type RefParts } from '../helpers/refFns.js';
|
|
73
73
|
/**
|
|
74
74
|
* Template literal type for OAS operation generator keys before branding.
|
|
75
75
|
* Format: `generatorId|path|method|variant`
|
|
@@ -93,7 +93,8 @@ export type NakedOasOperationGeneratorKey = `${string}|${string}|${Method}|${str
|
|
|
93
93
|
export type NakedGqlOperationGeneratorKey = `${string}|${GqlRootKind}|${string}|${string}`;
|
|
94
94
|
/**
|
|
95
95
|
* Template literal type for model generator keys before branding.
|
|
96
|
-
* Format: `generatorId|
|
|
96
|
+
* Format: `generatorId|modelKey|variant`, where the model key is a component's
|
|
97
|
+
* `refName`, or the whole pointer of a ref into the document's content
|
|
97
98
|
* (e.g., 'typescript-models|User|main',
|
|
98
99
|
* 'zod-schemas|Customer|coercive').
|
|
99
100
|
*
|
|
@@ -207,7 +208,7 @@ export type GeneratorOnlyKey = Brand<string, 'GeneratorOnlyKey'>;
|
|
|
207
208
|
* // Model generator key
|
|
208
209
|
* const modelKey: GeneratorKey = toModelGeneratorKey({
|
|
209
210
|
* generatorId: 'typescript-types',
|
|
210
|
-
* refName: 'User',
|
|
211
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
211
212
|
* variant: 'main'
|
|
212
213
|
* });
|
|
213
214
|
*
|
|
@@ -376,8 +377,12 @@ export declare const toGqlOperationGeneratorKey: ({ generatorId, variant, ...res
|
|
|
376
377
|
type ToModelGeneratorKeyArgs = {
|
|
377
378
|
/** Unique identifier for the generator */
|
|
378
379
|
generatorId: string;
|
|
379
|
-
/**
|
|
380
|
-
|
|
380
|
+
/**
|
|
381
|
+
* The model's ref. A component's key holds its `refName`; any other
|
|
382
|
+
* target's key holds its whole pointer (`toModelKey`), so two targets that
|
|
383
|
+
* share a `refName` get two keys.
|
|
384
|
+
*/
|
|
385
|
+
ref: RefParts;
|
|
381
386
|
/** Model variant name — omitted means `'main'` */
|
|
382
387
|
variant?: string;
|
|
383
388
|
};
|
|
@@ -387,7 +392,8 @@ type ToModelGeneratorKeyArgs = {
|
|
|
387
392
|
*
|
|
388
393
|
* Model generator keys uniquely identify generators processing specific
|
|
389
394
|
* OpenAPI schema models for a given variant. The key format is:
|
|
390
|
-
* `generatorId|
|
|
395
|
+
* `generatorId|modelKey|variant`: a component's `refName`, or the whole
|
|
396
|
+
* pointer of any other target, with `%` and `|` escaped.
|
|
391
397
|
*
|
|
392
398
|
* @param args - Model generator key arguments
|
|
393
399
|
* @returns A branded ModelGeneratorKey
|
|
@@ -396,20 +402,20 @@ type ToModelGeneratorKeyArgs = {
|
|
|
396
402
|
* ```typescript
|
|
397
403
|
* const key = toModelGeneratorKey({
|
|
398
404
|
* generatorId: 'typescript-interfaces',
|
|
399
|
-
* refName: 'User',
|
|
405
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
400
406
|
* variant: 'main'
|
|
401
407
|
* });
|
|
402
408
|
* // Result: 'typescript-interfaces|User|main' (branded)
|
|
403
409
|
*
|
|
404
410
|
* const coercive = toModelGeneratorKey({
|
|
405
411
|
* generatorId: 'zod-schemas',
|
|
406
|
-
* refName: 'CreateUserRequest',
|
|
412
|
+
* ref: { refName: 'CreateUserRequest', refPath: '#/components/schemas' },
|
|
407
413
|
* variant: 'coercive'
|
|
408
414
|
* });
|
|
409
415
|
* // Result: 'zod-schemas|CreateUserRequest|coercive' (branded)
|
|
410
416
|
* ```
|
|
411
417
|
*/
|
|
412
|
-
export declare const toModelGeneratorKey: ({ generatorId,
|
|
418
|
+
export declare const toModelGeneratorKey: ({ generatorId, ref, variant }: ToModelGeneratorKeyArgs) => ModelGeneratorKey;
|
|
413
419
|
/**
|
|
414
420
|
* Arguments for {@link toGeneratorOnlyKey}.
|
|
415
421
|
*/
|
|
@@ -532,7 +538,7 @@ export declare const isGqlOperationGeneratorKey: (arg: unknown) => arg is GqlOpe
|
|
|
532
538
|
* const obj = fromGeneratorKey(key);
|
|
533
539
|
* console.log(obj.type); // 'model'
|
|
534
540
|
* console.log(obj.generatorId); // 'zod-schemas'
|
|
535
|
-
* console.log(obj.refName);
|
|
541
|
+
* console.log(obj.ref.refName); // 'User'
|
|
536
542
|
* console.log(obj.variant); // 'main'
|
|
537
543
|
* }
|
|
538
544
|
* ```
|
|
@@ -582,7 +588,7 @@ export declare const isGeneratorOnlyKey: (arg: unknown) => arg is GeneratorOnlyK
|
|
|
582
588
|
*
|
|
583
589
|
* const modelKey = toModelGeneratorKey({
|
|
584
590
|
* generatorId: 'typescript-types',
|
|
585
|
-
* refName: 'User',
|
|
591
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
586
592
|
* variant: 'main'
|
|
587
593
|
* });
|
|
588
594
|
* console.log(toGeneratorId(modelKey)); // 'typescript-types'
|
|
@@ -650,8 +656,8 @@ export type GeneratorKeyObject = {
|
|
|
650
656
|
type: 'model';
|
|
651
657
|
/** Generator identifier */
|
|
652
658
|
generatorId: string;
|
|
653
|
-
/**
|
|
654
|
-
|
|
659
|
+
/** The model's ref: a component's, or a ref into the document's content */
|
|
660
|
+
ref: RefParts;
|
|
655
661
|
/** Model variant name */
|
|
656
662
|
variant: string;
|
|
657
663
|
} | {
|
|
@@ -689,7 +695,7 @@ export type GeneratorKeyObject = {
|
|
|
689
695
|
*
|
|
690
696
|
* if (parsed.type === 'model') {
|
|
691
697
|
* console.log(parsed.generatorId); // 'zod-schemas'
|
|
692
|
-
* console.log(parsed.refName);
|
|
698
|
+
* console.log(parsed.ref.refName); // 'User'
|
|
693
699
|
* console.log(parsed.variant); // 'main'
|
|
694
700
|
* }
|
|
695
701
|
* ```
|
|
@@ -59,7 +59,7 @@ exports.fromGeneratorKey = exports.toGeneratorId = exports.isGeneratorOnlyKey =
|
|
|
59
59
|
*
|
|
60
60
|
* const modelKey = toModelGeneratorKey({
|
|
61
61
|
* generatorId: 'typescript-models',
|
|
62
|
-
* refName: 'User' as RefName,
|
|
62
|
+
* ref: { refName: 'User' as RefName, refPath: '#/components/schemas' },
|
|
63
63
|
* variant: 'main'
|
|
64
64
|
* });
|
|
65
65
|
* ```
|
|
@@ -69,6 +69,7 @@ exports.fromGeneratorKey = exports.toGeneratorId = exports.isGeneratorOnlyKey =
|
|
|
69
69
|
require("../_dnt.polyfills.js");
|
|
70
70
|
const Method_js_1 = require("../types/Method.js");
|
|
71
71
|
const Variant_js_1 = require("../types/Variant.js");
|
|
72
|
+
const refFns_js_1 = require("../helpers/refFns.js");
|
|
72
73
|
const GQL_ROOT_KINDS = ['query', 'mutation', 'subscription'];
|
|
73
74
|
const isGqlRootKind = (value) => GQL_ROOT_KINDS.includes(value);
|
|
74
75
|
/**
|
|
@@ -176,7 +177,8 @@ exports.toGqlOperationGeneratorKey = toGqlOperationGeneratorKey;
|
|
|
176
177
|
*
|
|
177
178
|
* Model generator keys uniquely identify generators processing specific
|
|
178
179
|
* OpenAPI schema models for a given variant. The key format is:
|
|
179
|
-
* `generatorId|
|
|
180
|
+
* `generatorId|modelKey|variant`: a component's `refName`, or the whole
|
|
181
|
+
* pointer of any other target, with `%` and `|` escaped.
|
|
180
182
|
*
|
|
181
183
|
* @param args - Model generator key arguments
|
|
182
184
|
* @returns A branded ModelGeneratorKey
|
|
@@ -185,21 +187,24 @@ exports.toGqlOperationGeneratorKey = toGqlOperationGeneratorKey;
|
|
|
185
187
|
* ```typescript
|
|
186
188
|
* const key = toModelGeneratorKey({
|
|
187
189
|
* generatorId: 'typescript-interfaces',
|
|
188
|
-
* refName: 'User',
|
|
190
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
189
191
|
* variant: 'main'
|
|
190
192
|
* });
|
|
191
193
|
* // Result: 'typescript-interfaces|User|main' (branded)
|
|
192
194
|
*
|
|
193
195
|
* const coercive = toModelGeneratorKey({
|
|
194
196
|
* generatorId: 'zod-schemas',
|
|
195
|
-
* refName: 'CreateUserRequest',
|
|
197
|
+
* ref: { refName: 'CreateUserRequest', refPath: '#/components/schemas' },
|
|
196
198
|
* variant: 'coercive'
|
|
197
199
|
* });
|
|
198
200
|
* // Result: 'zod-schemas|CreateUserRequest|coercive' (branded)
|
|
199
201
|
* ```
|
|
200
202
|
*/
|
|
201
|
-
const toModelGeneratorKey = ({ generatorId,
|
|
202
|
-
const
|
|
203
|
+
const toModelGeneratorKey = ({ generatorId, ref, variant = Variant_js_1.DEFAULT_VARIANT }) => {
|
|
204
|
+
const modelKey = (0, refFns_js_1.toModelKey)(ref);
|
|
205
|
+
// A pointer can hold `|` (a property named `a|b`). A component's key stays its bare name.
|
|
206
|
+
const segment = (0, refFns_js_1.isPointerKey)(modelKey) ? escapeKeySegment(modelKey) : modelKey;
|
|
207
|
+
const nakedKey = `${generatorId}|${segment}|${variant}`;
|
|
203
208
|
return nakedKey;
|
|
204
209
|
};
|
|
205
210
|
exports.toModelGeneratorKey = toModelGeneratorKey;
|
|
@@ -418,7 +423,7 @@ exports.isGqlOperationGeneratorKey = isGqlOperationGeneratorKey;
|
|
|
418
423
|
* const obj = fromGeneratorKey(key);
|
|
419
424
|
* console.log(obj.type); // 'model'
|
|
420
425
|
* console.log(obj.generatorId); // 'zod-schemas'
|
|
421
|
-
* console.log(obj.refName);
|
|
426
|
+
* console.log(obj.ref.refName); // 'User'
|
|
422
427
|
* console.log(obj.variant); // 'main'
|
|
423
428
|
* }
|
|
424
429
|
* ```
|
|
@@ -494,7 +499,7 @@ exports.isGeneratorOnlyKey = isGeneratorOnlyKey;
|
|
|
494
499
|
*
|
|
495
500
|
* const modelKey = toModelGeneratorKey({
|
|
496
501
|
* generatorId: 'typescript-types',
|
|
497
|
-
* refName: 'User',
|
|
502
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
498
503
|
* variant: 'main'
|
|
499
504
|
* });
|
|
500
505
|
* console.log(toGeneratorId(modelKey)); // 'typescript-types'
|
|
@@ -553,7 +558,7 @@ exports.toGeneratorId = toGeneratorId;
|
|
|
553
558
|
*
|
|
554
559
|
* if (parsed.type === 'model') {
|
|
555
560
|
* console.log(parsed.generatorId); // 'zod-schemas'
|
|
556
|
-
* console.log(parsed.refName);
|
|
561
|
+
* console.log(parsed.ref.refName); // 'User'
|
|
557
562
|
* console.log(parsed.variant); // 'main'
|
|
558
563
|
* }
|
|
559
564
|
* ```
|
|
@@ -598,8 +603,8 @@ const fromGeneratorKey = (generatorKey) => {
|
|
|
598
603
|
};
|
|
599
604
|
}
|
|
600
605
|
if ((0, exports.isModelGeneratorKey)(generatorKey)) {
|
|
601
|
-
const [generatorId,
|
|
602
|
-
return { type: 'model', generatorId,
|
|
606
|
+
const [generatorId, modelKey, variant] = generatorKey.split('|');
|
|
607
|
+
return { type: 'model', generatorId, ref: (0, refFns_js_1.fromModelKey)((0, refFns_js_1.isPointerKey)(modelKey) ? unescapeKeySegment(modelKey) : modelKey), variant };
|
|
603
608
|
}
|
|
604
609
|
return { type: 'generator-only', generatorId: generatorKey };
|
|
605
610
|
};
|
package/script/dsl/Inserted.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ type ConstructorArgs<V extends GeneratedValue, EnrichmentType> = {
|
|
|
53
53
|
* const identifier = userModel.toName(); // 'User'
|
|
54
54
|
*
|
|
55
55
|
* return new Definition({
|
|
56
|
-
* identifier: createType(this.refName),
|
|
56
|
+
* identifier: createType(this.ref.refName),
|
|
57
57
|
* value: {
|
|
58
58
|
* generatorKey: this.generatorKey,
|
|
59
59
|
* content: `export interface Order { user: ${userTypeName}; }`
|
package/script/dsl/Inserted.js
CHANGED
|
@@ -41,7 +41,7 @@ exports.Inserted = void 0;
|
|
|
41
41
|
* const identifier = userModel.toName(); // 'User'
|
|
42
42
|
*
|
|
43
43
|
* return new Definition({
|
|
44
|
-
* identifier: createType(this.refName),
|
|
44
|
+
* identifier: createType(this.ref.refName),
|
|
45
45
|
* value: {
|
|
46
46
|
* generatorKey: this.generatorKey,
|
|
47
47
|
* content: `export interface Order { user: ${userTypeName}; }`
|