@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
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
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");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
1
6
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
7
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
8
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
11
|
};
|
|
7
|
-
var
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
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
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _ParseContext_instances, _ParseContext_refConsumers, _ParseContext_refErrors, _ParseContext_oasRefs, _ParseContext_rootFrames, _ParseContext_removeComponent, _ParseContext_removeConsumer, _ParseContext_removePathParameterConsumer, _ParseContext_toRawComponentParameter, _ParseContext_logDependencyIssue, _ParseContext_toDocumentTrail, _ParseContext_checkRefs, _ParseContext_toRefError, _ParseContext_toLoopOf, _ParseContext_removeHolder;
|
|
12
|
+
var _ParseContext_instances, _ParseContext_refConsumers, _ParseContext_refErrors, _ParseContext_oasRefs, _ParseContext_refTargets, _ParseContext_refTarget, _ParseContext_keptRefs, _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;
|
|
13
13
|
/**
|
|
14
14
|
* Unified parse context for both OAS and GraphQL inputs.
|
|
15
15
|
*
|
|
@@ -39,22 +39,55 @@ import { GqlDocument } from '../gql/document/GqlDocument.js';
|
|
|
39
39
|
import { parseGqlDocument } from '../gql/document/parseGqlDocument.js';
|
|
40
40
|
import { StackTrail } from './StackTrail.js';
|
|
41
41
|
import { isPlainObject } from '../parse/isPlainObject.js';
|
|
42
|
+
import { toKeptRefs } from '../parse/keptRefs.js';
|
|
42
43
|
import { toApplyingBrokenParameter, toNameAndIn } from '../parse/pathParameters.js';
|
|
43
44
|
import { toSerializedError } from '../types/SerializedError.js';
|
|
45
|
+
import { tryParseAt } from './tryParseAt.js';
|
|
44
46
|
import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
|
|
45
|
-
import {
|
|
47
|
+
import { toRawRefTarget, toRefParts, toRefPathBucket, toRefPathSegments, toRefPointer } from '../helpers/refFns.js';
|
|
48
|
+
import { toRefTargetV3 } from '../parse/v3-0/ref/toRefTargetV3.js';
|
|
49
|
+
import { toRefTargetV3 as toRefTargetV31 } from '../parse/v3-1/ref/toRefTargetV3.js';
|
|
50
|
+
import { toRefTargetV3 as toRefTargetV32 } from '../parse/v3-2/ref/toRefTargetV3.js';
|
|
46
51
|
/**
|
|
47
|
-
* The key a `$ref`'s consumers and errors are kept under. A
|
|
48
|
-
* `#/components/<bucket
|
|
49
|
-
*
|
|
52
|
+
* The key a `$ref`'s consumers and errors are kept under. A component ref
|
|
53
|
+
* (`#/components/<bucket>/<name>`) is keyed by the name it resolves,
|
|
54
|
+
* unescaped, which is the key `StackTrail.toStackRef()` gives that
|
|
50
55
|
* component's own errors: `#/components/schemas/Foo%20Bar` is kept under
|
|
51
|
-
* `#/components/schemas/Foo Bar`. Any other
|
|
56
|
+
* `#/components/schemas/Foo Bar`. Any other ref is keyed by its whole
|
|
57
|
+
* pointer in one spelling (`toRefPointer`), which is also the key its
|
|
58
|
+
* parsed target is kept under.
|
|
52
59
|
*/
|
|
53
|
-
const toRefKey = (
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return bucket === undefined ? $ref : `#/components/${bucket}/${toRefName($ref)}`;
|
|
60
|
+
const toRefKey = ({ refName, refPath }) => {
|
|
61
|
+
const bucket = toRefPathBucket(refPath);
|
|
62
|
+
return bucket === undefined ? toRefPointer({ refName, refPath }) : `#/components/${bucket}/${refName}`;
|
|
57
63
|
};
|
|
64
|
+
/** The issue logged when a ref target's parser throws. */
|
|
65
|
+
const toInvalidType = (refType) => {
|
|
66
|
+
switch (refType) {
|
|
67
|
+
case 'schema':
|
|
68
|
+
return 'INVALID_SCHEMA';
|
|
69
|
+
case 'requestBody':
|
|
70
|
+
return 'INVALID_REQUEST_BODY';
|
|
71
|
+
case 'parameter':
|
|
72
|
+
return 'INVALID_PARAMETER';
|
|
73
|
+
case 'response':
|
|
74
|
+
case 'link':
|
|
75
|
+
// A link has no type of its own: in the document's walk its response reports it.
|
|
76
|
+
return 'INVALID_RESPONSE';
|
|
77
|
+
case 'example':
|
|
78
|
+
return 'INVALID_EXAMPLE';
|
|
79
|
+
case 'header':
|
|
80
|
+
return 'INVALID_HEADER';
|
|
81
|
+
case 'securityScheme':
|
|
82
|
+
return 'INVALID_SECURITY_SCHEME';
|
|
83
|
+
default: {
|
|
84
|
+
const _exhaustive = refType;
|
|
85
|
+
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
/** Two issues with the same level, type, location and message are the same issue. */
|
|
90
|
+
const toIssueIdentity = (issue) => [issue.level, issue.type, issue.location, issue.message].join('\u0000');
|
|
58
91
|
/** The stored form of an issue: an error's `cause` as a `SerializedError`. */
|
|
59
92
|
const toParseIssue = (issue) => {
|
|
60
93
|
if (issue.level !== 'error') {
|
|
@@ -131,6 +164,18 @@ export class ParseContext {
|
|
|
131
164
|
);
|
|
132
165
|
/** Each OAS ref and the place it is written, which `#checkRefs` resolves once the document is parsed. */
|
|
133
166
|
_ParseContext_oasRefs.set(this, []
|
|
167
|
+
/** The key (`toRefKey`) of each ref target `#parseRefTargets` parsed. */
|
|
168
|
+
);
|
|
169
|
+
/** The key (`toRefKey`) of each ref target `#parseRefTargets` parsed. */
|
|
170
|
+
_ParseContext_refTargets.set(this, new Set()
|
|
171
|
+
/** The key of the ref target `#inRefTarget` runs for; `undefined` in the document's own walk. */
|
|
172
|
+
);
|
|
173
|
+
/** The key of the ref target `#inRefTarget` runs for; `undefined` in the document's own walk. */
|
|
174
|
+
_ParseContext_refTarget.set(this, void 0);
|
|
175
|
+
/** {@link keptRefs}, once a merge has asked for it. */
|
|
176
|
+
_ParseContext_keptRefs.set(this, void 0);
|
|
177
|
+
/** What identifies each issue logged so far (`toIssueIdentity`). */
|
|
178
|
+
_ParseContext_issueIdentities.set(this, new Set()
|
|
134
179
|
/**
|
|
135
180
|
* Frames of the trail `parse()` was called with (`[traceId, spanId,
|
|
136
181
|
* 'parse']` through `toArtifacts`). Every trail built during the walk
|
|
@@ -194,6 +239,13 @@ export class ParseContext {
|
|
|
194
239
|
}
|
|
195
240
|
return this.protocol.documentObject;
|
|
196
241
|
}
|
|
242
|
+
/** The refs of the document that a merge keeps as refs (`system.intersections`); `undefined` under `merge`. */
|
|
243
|
+
get keptRefs() {
|
|
244
|
+
__classPrivateFieldSet(this, _ParseContext_keptRefs, __classPrivateFieldGet(this, _ParseContext_keptRefs, "f") ?? {
|
|
245
|
+
value: toKeptRefs({ documentObject: this.documentObject, setting: this.system.intersections })
|
|
246
|
+
}, "f");
|
|
247
|
+
return __classPrivateFieldGet(this, _ParseContext_keptRefs, "f").value;
|
|
248
|
+
}
|
|
197
249
|
/** GQL-only accessor; throws if called on an OAS context. */
|
|
198
250
|
get schema() {
|
|
199
251
|
if (this.protocol.type !== 'gql') {
|
|
@@ -260,6 +312,7 @@ export class ParseContext {
|
|
|
260
312
|
stackTrail,
|
|
261
313
|
context: this
|
|
262
314
|
});
|
|
315
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_parseRefTargets).call(this, toRefTargetV3);
|
|
263
316
|
break;
|
|
264
317
|
case '3.1':
|
|
265
318
|
oasState.oasDocument.fields = toDocumentFieldsV31({
|
|
@@ -267,6 +320,7 @@ export class ParseContext {
|
|
|
267
320
|
stackTrail,
|
|
268
321
|
context: this
|
|
269
322
|
});
|
|
323
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_parseRefTargets).call(this, toRefTargetV31);
|
|
270
324
|
break;
|
|
271
325
|
case '3.2':
|
|
272
326
|
oasState.oasDocument.fields = toDocumentFieldsV32({
|
|
@@ -274,6 +328,7 @@ export class ParseContext {
|
|
|
274
328
|
stackTrail,
|
|
275
329
|
context: this
|
|
276
330
|
});
|
|
331
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_parseRefTargets).call(this, toRefTargetV32);
|
|
277
332
|
break;
|
|
278
333
|
default: {
|
|
279
334
|
const _exhaustive = dialect;
|
|
@@ -327,7 +382,15 @@ export class ParseContext {
|
|
|
327
382
|
pending.forEach(({ refKey }) => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeComponent).call(this, refKey));
|
|
328
383
|
// `pending` grows while it is walked: each removed component queues its own consumers.
|
|
329
384
|
for (const { refKey, rootCause } of pending) {
|
|
330
|
-
for (const consumer of __classPrivateFieldGet(this, _ParseContext_refConsumers, "f").get(refKey) ?? []) {
|
|
385
|
+
for (const { consumer, refTarget } of __classPrivateFieldGet(this, _ParseContext_refConsumers, "f").get(refKey) ?? []) {
|
|
386
|
+
// The ref is inside a ref target: the target is removed, and what refers to it next.
|
|
387
|
+
if (refTarget !== undefined) {
|
|
388
|
+
if (this.oasDocument.removeRefTarget(refTarget) !== undefined) {
|
|
389
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_inRefTarget).call(this, refTarget, () => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_logDependencyIssue).call(this, { location: consumer.toString(), refKey, rootCause }));
|
|
390
|
+
pending.push({ refKey: refTarget, rootCause });
|
|
391
|
+
}
|
|
392
|
+
continue;
|
|
393
|
+
}
|
|
331
394
|
const documentTrail = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentTrail).call(this, consumer);
|
|
332
395
|
const removedLocations = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeConsumer).call(this, consumer, documentTrail);
|
|
333
396
|
removedLocations.forEach(location => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_logDependencyIssue).call(this, { location, refKey, rootCause }));
|
|
@@ -372,12 +435,13 @@ export class ParseContext {
|
|
|
372
435
|
* would use type names or qualified field paths.
|
|
373
436
|
*/
|
|
374
437
|
registerRef(consumer, refKey) {
|
|
438
|
+
const refConsumer = { consumer, refTarget: __classPrivateFieldGet(this, _ParseContext_refTarget, "f") };
|
|
375
439
|
const existing = __classPrivateFieldGet(this, _ParseContext_refConsumers, "f").get(refKey);
|
|
376
440
|
if (existing) {
|
|
377
|
-
existing.push(
|
|
441
|
+
existing.push(refConsumer);
|
|
378
442
|
}
|
|
379
443
|
else {
|
|
380
|
-
__classPrivateFieldGet(this, _ParseContext_refConsumers, "f").set(refKey, [
|
|
444
|
+
__classPrivateFieldGet(this, _ParseContext_refConsumers, "f").set(refKey, [refConsumer]);
|
|
381
445
|
}
|
|
382
446
|
}
|
|
383
447
|
/**
|
|
@@ -387,8 +451,8 @@ export class ParseContext {
|
|
|
387
451
|
* resolve it there.
|
|
388
452
|
*/
|
|
389
453
|
registerOasRef(consumer, ref) {
|
|
390
|
-
this.registerRef(consumer, toRefKey(ref
|
|
391
|
-
__classPrivateFieldGet(this, _ParseContext_oasRefs, "f").push({ consumer, ref });
|
|
454
|
+
this.registerRef(consumer, toRefKey(ref));
|
|
455
|
+
__classPrivateFieldGet(this, _ParseContext_oasRefs, "f").push({ consumer, ref, refTarget: __classPrivateFieldGet(this, _ParseContext_refTarget, "f") });
|
|
392
456
|
}
|
|
393
457
|
/**
|
|
394
458
|
* What a merge reads in place of a `$ref` that names nothing: an `allOf`
|
|
@@ -448,8 +512,8 @@ export class ParseContext {
|
|
|
448
512
|
* manifest).
|
|
449
513
|
*/
|
|
450
514
|
logIssueAt(issue, parent) {
|
|
451
|
-
this.
|
|
452
|
-
if (!this.silent) {
|
|
515
|
+
const added = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, toParseIssue(issue));
|
|
516
|
+
if (added && !this.silent) {
|
|
453
517
|
this.logger.warn({
|
|
454
518
|
protocol: issue.protocol,
|
|
455
519
|
level: issue.level,
|
|
@@ -483,7 +547,7 @@ export class ParseContext {
|
|
|
483
547
|
// points at. No-op for non-component trails (and for GQL
|
|
484
548
|
// trails) because `toStackRef` returns `undefined` and
|
|
485
549
|
// `registerRefError` ignores undefined refs.
|
|
486
|
-
this.registerRefError(issue.cause ?? issue.message, __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentTrail).call(this, stackTrail).toStackRef(), location);
|
|
550
|
+
this.registerRefError(issue.cause ?? issue.message, __classPrivateFieldGet(this, _ParseContext_refTarget, "f") ?? __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentTrail).call(this, stackTrail).toStackRef(), location);
|
|
487
551
|
this.logIssueAt({
|
|
488
552
|
protocol,
|
|
489
553
|
level: 'error',
|
|
@@ -565,14 +629,65 @@ export class ParseContext {
|
|
|
565
629
|
});
|
|
566
630
|
}
|
|
567
631
|
}
|
|
568
|
-
_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) {
|
|
632
|
+
_ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMap(), _ParseContext_oasRefs = new WeakMap(), _ParseContext_refTargets = new WeakMap(), _ParseContext_refTarget = new WeakMap(), _ParseContext_keptRefs = new WeakMap(), _ParseContext_issueIdentities = new WeakMap(), _ParseContext_rootFrames = new WeakMap(), _ParseContext_instances = new WeakSet(), _ParseContext_removeComponent = function _ParseContext_removeComponent(refKey) {
|
|
569
633
|
if (this.protocol.type !== 'oas') {
|
|
570
634
|
return;
|
|
571
635
|
}
|
|
636
|
+
if (__classPrivateFieldGet(this, _ParseContext_refTargets, "f").has(refKey)) {
|
|
637
|
+
this.protocol.oasDocument.removeRefTarget(refKey);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
572
640
|
const match = /^#\/components\/([^/]+)\/(.+)$/.exec(refKey);
|
|
573
641
|
if (match) {
|
|
574
642
|
this.protocol.oasDocument.removeItem(new StackTrail(['components', match[1], match[2]]));
|
|
575
643
|
}
|
|
644
|
+
}, _ParseContext_parseRefTargets = function _ParseContext_parseRefTargets(toRefTarget) {
|
|
645
|
+
if (this.protocol.type !== 'oas') {
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
648
|
+
const { oasDocument, documentObject } = this.protocol;
|
|
649
|
+
for (const { ref } of __classPrivateFieldGet(this, _ParseContext_oasRefs, "f")) {
|
|
650
|
+
const key = toRefKey(ref);
|
|
651
|
+
// A ref to a component, of its own kind or not, is resolved in
|
|
652
|
+
// `components`; `#checkRefs` reports one of the wrong kind.
|
|
653
|
+
if (ref.refName === '' || toRefPathBucket(ref.refPath) !== undefined || __classPrivateFieldGet(this, _ParseContext_refTargets, "f").has(key)) {
|
|
654
|
+
continue;
|
|
655
|
+
}
|
|
656
|
+
const value = toRawRefTarget(documentObject, ref);
|
|
657
|
+
if (!isPlainObject(value)) {
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
__classPrivateFieldGet(this, _ParseContext_refTargets, "f").add(key);
|
|
661
|
+
const parent = new StackTrail([...__classPrivateFieldGet(this, _ParseContext_rootFrames, "f"), ...toRefPathSegments(ref.refPath)]);
|
|
662
|
+
const target = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_inRefTarget).call(this, key, () => tryParseAt({
|
|
663
|
+
stackTrail: parent,
|
|
664
|
+
key: ref.refName,
|
|
665
|
+
context: this,
|
|
666
|
+
type: toInvalidType(ref.refType),
|
|
667
|
+
parent: value,
|
|
668
|
+
fn: () => toRefTarget({ refType: ref.refType, name: ref.refName, value, stackTrail: parent, context: this })
|
|
669
|
+
}));
|
|
670
|
+
if (target !== undefined) {
|
|
671
|
+
oasDocument.setRefTarget(key, target);
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}, _ParseContext_inRefTarget = function _ParseContext_inRefTarget(key, fn) {
|
|
675
|
+
const previous = __classPrivateFieldGet(this, _ParseContext_refTarget, "f");
|
|
676
|
+
__classPrivateFieldSet(this, _ParseContext_refTarget, key, "f");
|
|
677
|
+
try {
|
|
678
|
+
return fn();
|
|
679
|
+
}
|
|
680
|
+
finally {
|
|
681
|
+
__classPrivateFieldSet(this, _ParseContext_refTarget, previous, "f");
|
|
682
|
+
}
|
|
683
|
+
}, _ParseContext_addIssue = function _ParseContext_addIssue(issue) {
|
|
684
|
+
const identity = toIssueIdentity(issue);
|
|
685
|
+
if (__classPrivateFieldGet(this, _ParseContext_refTarget, "f") !== undefined && __classPrivateFieldGet(this, _ParseContext_issueIdentities, "f").has(identity)) {
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
__classPrivateFieldGet(this, _ParseContext_issueIdentities, "f").add(identity);
|
|
689
|
+
this.issues.push(issue);
|
|
690
|
+
return true;
|
|
576
691
|
}, _ParseContext_removeConsumer = function _ParseContext_removeConsumer(consumer, documentTrail) {
|
|
577
692
|
switch (this.protocol.type) {
|
|
578
693
|
case 'oas': {
|
|
@@ -611,7 +726,9 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
611
726
|
: [];
|
|
612
727
|
const rawEntry = rawEntries[Number(index)];
|
|
613
728
|
const entryRef = isPlainObject(rawEntry) && typeof rawEntry.$ref === 'string' ? rawEntry.$ref : undefined;
|
|
614
|
-
const nameAndIn = toNameAndIn(entryRef === undefined
|
|
729
|
+
const nameAndIn = toNameAndIn(entryRef === undefined
|
|
730
|
+
? rawEntry
|
|
731
|
+
: toRawRefTarget(documentObject, toRefParts({ $ref: entryRef })));
|
|
615
732
|
const broken = [{ location: documentTrail.toString(), message: '', ...nameAndIn }];
|
|
616
733
|
const operations = first === 'paths'
|
|
617
734
|
? oasDocument.operations.filter(({ path }) => path === second)
|
|
@@ -633,13 +750,6 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
633
750
|
: [new StackTrail([...prefix, first, second, method]).toString()];
|
|
634
751
|
});
|
|
635
752
|
return removedLocations;
|
|
636
|
-
}, _ParseContext_toRawComponentParameter = function _ParseContext_toRawComponentParameter($ref) {
|
|
637
|
-
if (this.protocol.type !== 'oas') {
|
|
638
|
-
return undefined;
|
|
639
|
-
}
|
|
640
|
-
const match = /^#\/components\/parameters\/(.+)$/.exec($ref);
|
|
641
|
-
const parameters = this.protocol.documentObject.components?.parameters;
|
|
642
|
-
return match && isPlainObject(parameters) ? parameters[match[1]] : undefined;
|
|
643
753
|
}, _ParseContext_logDependencyIssue = function _ParseContext_logDependencyIssue({ location, refKey, rootCause }) {
|
|
644
754
|
const { error } = rootCause;
|
|
645
755
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -647,7 +757,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
647
757
|
const message = `Depends on '${refKey}', removed because of the error${at}: ${errorMessage}`;
|
|
648
758
|
switch (this.protocol.type) {
|
|
649
759
|
case 'oas':
|
|
650
|
-
this.
|
|
760
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, {
|
|
651
761
|
protocol: 'oas',
|
|
652
762
|
level: 'error',
|
|
653
763
|
type: 'INVALID_DEPENDENCY_REF',
|
|
@@ -657,7 +767,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
657
767
|
});
|
|
658
768
|
break;
|
|
659
769
|
case 'gql':
|
|
660
|
-
this.
|
|
770
|
+
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_addIssue).call(this, {
|
|
661
771
|
protocol: 'gql',
|
|
662
772
|
level: 'error',
|
|
663
773
|
type: 'INVALID_DEPENDENCY_REF',
|
|
@@ -679,8 +789,8 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
679
789
|
rootFrames.every((frame, index) => frames[index] === frame);
|
|
680
790
|
return startsWithRoot ? new StackTrail(frames.slice(rootFrames.length)) : stackTrail;
|
|
681
791
|
}, _ParseContext_checkRefs = function _ParseContext_checkRefs() {
|
|
682
|
-
__classPrivateFieldGet(this, _ParseContext_oasRefs, "f").forEach(({ consumer, ref }) => {
|
|
683
|
-
if (__classPrivateFieldGet(this, _ParseContext_refErrors, "f").has(toRefKey(ref
|
|
792
|
+
__classPrivateFieldGet(this, _ParseContext_oasRefs, "f").forEach(({ consumer, ref, refTarget }) => __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_inRefTarget).call(this, refTarget, () => {
|
|
793
|
+
if (__classPrivateFieldGet(this, _ParseContext_refErrors, "f").has(toRefKey(ref))) {
|
|
684
794
|
return;
|
|
685
795
|
}
|
|
686
796
|
const error = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toRefError).call(this, ref);
|
|
@@ -690,6 +800,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
690
800
|
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
|
|
691
801
|
consumer,
|
|
692
802
|
ref,
|
|
803
|
+
refTarget,
|
|
693
804
|
error,
|
|
694
805
|
type: 'REF_TYPE_MISMATCH',
|
|
695
806
|
message: `${message}, so what holds it is removed.`
|
|
@@ -708,13 +819,14 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
708
819
|
__classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_removeHolder).call(this, {
|
|
709
820
|
consumer,
|
|
710
821
|
ref,
|
|
822
|
+
refTarget,
|
|
711
823
|
error,
|
|
712
824
|
type: 'DANGLING_REF',
|
|
713
825
|
message: `${error.message}, so what holds it is removed. To keep it, list '${ref.refType}' in system.danglingRefs.`
|
|
714
826
|
});
|
|
715
827
|
}
|
|
716
828
|
}
|
|
717
|
-
});
|
|
829
|
+
}));
|
|
718
830
|
}, _ParseContext_toRefError = function _ParseContext_toRefError(ref) {
|
|
719
831
|
try {
|
|
720
832
|
ref.resolveOnce();
|
|
@@ -733,7 +845,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
733
845
|
// A ref further on names nothing or the wrong kind: it reports that itself.
|
|
734
846
|
return undefined;
|
|
735
847
|
}
|
|
736
|
-
}, _ParseContext_removeHolder = function _ParseContext_removeHolder({ consumer, ref, error, type, message }) {
|
|
848
|
+
}, _ParseContext_removeHolder = function _ParseContext_removeHolder({ consumer, ref, refTarget, error, type, message }) {
|
|
737
849
|
this.logIssueNoKey({
|
|
738
850
|
level: 'error',
|
|
739
851
|
message,
|
|
@@ -743,7 +855,7 @@ _ParseContext_refConsumers = new WeakMap(), _ParseContext_refErrors = new WeakMa
|
|
|
743
855
|
type
|
|
744
856
|
});
|
|
745
857
|
const documentTrail = __classPrivateFieldGet(this, _ParseContext_instances, "m", _ParseContext_toDocumentTrail).call(this, consumer);
|
|
746
|
-
if (documentTrail.toStackRef() !== undefined) {
|
|
858
|
+
if (refTarget !== undefined || documentTrail.toStackRef() !== undefined) {
|
|
747
859
|
return;
|
|
748
860
|
}
|
|
749
861
|
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';
|
|
@@ -170,8 +170,8 @@ export type AnyOasDocument = OpenAPIV2.Document | OpenAPIV3.Document | OpenAPIV3
|
|
|
170
170
|
*
|
|
171
171
|
* - `WILDCARD_MEDIA_TYPE` (`warning`) — the body has no JSON media type
|
|
172
172
|
* (see `isJsonMediaType`) and is read from `*\/*` as JSON, since its schema
|
|
173
|
-
* there is an object, array, union or `$ref`. The document
|
|
174
|
-
* format; springdoc writes `*\/*` for every response.
|
|
173
|
+
* there is an object, array, union, intersection or `$ref`. The document
|
|
174
|
+
* does not say the format; springdoc writes `*\/*` for every response.
|
|
175
175
|
* - `NO_JSON_MEDIA_TYPE` (`debug`) — no lookup without a media type reads the
|
|
176
176
|
* body, and its keys include a range: `application/*`, or `*\/*` with a
|
|
177
177
|
* scalar schema (a text body or a file). A body with only specific
|
|
@@ -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
|
/**
|
|
@@ -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
|
* ```
|
package/esm/dsl/GeneratorKeys.js
CHANGED
|
@@ -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
|
* ```
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
import "../_dnt.polyfills.js";
|
|
67
67
|
import { isMethod } from '../types/Method.js';
|
|
68
68
|
import { DEFAULT_VARIANT } from '../types/Variant.js';
|
|
69
|
+
import { fromModelKey, isPointerKey, toModelKey } from '../helpers/refFns.js';
|
|
69
70
|
const GQL_ROOT_KINDS = ['query', 'mutation', 'subscription'];
|
|
70
71
|
const isGqlRootKind = (value) => GQL_ROOT_KINDS.includes(value);
|
|
71
72
|
/**
|
|
@@ -169,7 +170,8 @@ export const toGqlOperationGeneratorKey = ({ generatorId, variant = DEFAULT_VARI
|
|
|
169
170
|
*
|
|
170
171
|
* Model generator keys uniquely identify generators processing specific
|
|
171
172
|
* OpenAPI schema models for a given variant. The key format is:
|
|
172
|
-
* `generatorId|
|
|
173
|
+
* `generatorId|modelKey|variant`: a component's `refName`, or the whole
|
|
174
|
+
* pointer of any other target, with `%` and `|` escaped.
|
|
173
175
|
*
|
|
174
176
|
* @param args - Model generator key arguments
|
|
175
177
|
* @returns A branded ModelGeneratorKey
|
|
@@ -178,21 +180,24 @@ export const toGqlOperationGeneratorKey = ({ generatorId, variant = DEFAULT_VARI
|
|
|
178
180
|
* ```typescript
|
|
179
181
|
* const key = toModelGeneratorKey({
|
|
180
182
|
* generatorId: 'typescript-interfaces',
|
|
181
|
-
* refName: 'User',
|
|
183
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
182
184
|
* variant: 'main'
|
|
183
185
|
* });
|
|
184
186
|
* // Result: 'typescript-interfaces|User|main' (branded)
|
|
185
187
|
*
|
|
186
188
|
* const coercive = toModelGeneratorKey({
|
|
187
189
|
* generatorId: 'zod-schemas',
|
|
188
|
-
* refName: 'CreateUserRequest',
|
|
190
|
+
* ref: { refName: 'CreateUserRequest', refPath: '#/components/schemas' },
|
|
189
191
|
* variant: 'coercive'
|
|
190
192
|
* });
|
|
191
193
|
* // Result: 'zod-schemas|CreateUserRequest|coercive' (branded)
|
|
192
194
|
* ```
|
|
193
195
|
*/
|
|
194
|
-
export const toModelGeneratorKey = ({ generatorId,
|
|
195
|
-
const
|
|
196
|
+
export const toModelGeneratorKey = ({ generatorId, ref, variant = DEFAULT_VARIANT }) => {
|
|
197
|
+
const modelKey = toModelKey(ref);
|
|
198
|
+
// A pointer can hold `|` (a property named `a|b`). A component's key stays its bare name.
|
|
199
|
+
const segment = isPointerKey(modelKey) ? escapeKeySegment(modelKey) : modelKey;
|
|
200
|
+
const nakedKey = `${generatorId}|${segment}|${variant}`;
|
|
196
201
|
return nakedKey;
|
|
197
202
|
};
|
|
198
203
|
/**
|
|
@@ -404,7 +409,7 @@ export const isGqlOperationGeneratorKey = (arg) => {
|
|
|
404
409
|
* const obj = fromGeneratorKey(key);
|
|
405
410
|
* console.log(obj.type); // 'model'
|
|
406
411
|
* console.log(obj.generatorId); // 'zod-schemas'
|
|
407
|
-
* console.log(obj.refName);
|
|
412
|
+
* console.log(obj.ref.refName); // 'User'
|
|
408
413
|
* console.log(obj.variant); // 'main'
|
|
409
414
|
* }
|
|
410
415
|
* ```
|
|
@@ -478,7 +483,7 @@ export const isGeneratorOnlyKey = (arg) => {
|
|
|
478
483
|
*
|
|
479
484
|
* const modelKey = toModelGeneratorKey({
|
|
480
485
|
* generatorId: 'typescript-types',
|
|
481
|
-
* refName: 'User',
|
|
486
|
+
* ref: { refName: 'User', refPath: '#/components/schemas' },
|
|
482
487
|
* variant: 'main'
|
|
483
488
|
* });
|
|
484
489
|
* console.log(toGeneratorId(modelKey)); // 'typescript-types'
|
|
@@ -536,7 +541,7 @@ export const toGeneratorId = (generatorKey) => {
|
|
|
536
541
|
*
|
|
537
542
|
* if (parsed.type === 'model') {
|
|
538
543
|
* console.log(parsed.generatorId); // 'zod-schemas'
|
|
539
|
-
* console.log(parsed.refName);
|
|
544
|
+
* console.log(parsed.ref.refName); // 'User'
|
|
540
545
|
* console.log(parsed.variant); // 'main'
|
|
541
546
|
* }
|
|
542
547
|
* ```
|
|
@@ -581,8 +586,8 @@ export const fromGeneratorKey = (generatorKey) => {
|
|
|
581
586
|
};
|
|
582
587
|
}
|
|
583
588
|
if (isModelGeneratorKey(generatorKey)) {
|
|
584
|
-
const [generatorId,
|
|
585
|
-
return { type: 'model', generatorId,
|
|
589
|
+
const [generatorId, modelKey, variant] = generatorKey.split('|');
|
|
590
|
+
return { type: 'model', generatorId, ref: fromModelKey(isPointerKey(modelKey) ? unescapeKeySegment(modelKey) : modelKey), variant };
|
|
586
591
|
}
|
|
587
592
|
return { type: 'generator-only', generatorId: generatorKey };
|
|
588
593
|
};
|
package/esm/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/esm/dsl/Inserted.js
CHANGED
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
* const identifier = userModel.toName(); // 'User'
|
|
39
39
|
*
|
|
40
40
|
* return new Definition({
|
|
41
|
-
* identifier: createType(this.refName),
|
|
41
|
+
* identifier: createType(this.ref.refName),
|
|
42
42
|
* value: {
|
|
43
43
|
* generatorKey: this.generatorKey,
|
|
44
44
|
* content: `export interface Order { user: ${userTypeName}; }`
|