@skmtc/core 0.45.0 → 0.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/anchors/attribute.js +3 -2
- package/esm/context/CoreContext.d.ts +1 -1
- package/esm/context/CoreContext.js +1 -1
- package/esm/context/GenerateContext.d.ts +13 -10
- package/esm/context/GenerateContext.js +36 -25
- package/esm/context/ParseContext.d.ts +3 -0
- package/esm/context/ParseContext.js +151 -39
- package/esm/context/generateTypes.d.ts +7 -6
- package/esm/dsl/GeneratorKeys.d.ts +21 -15
- package/esm/dsl/GeneratorKeys.js +16 -11
- package/esm/dsl/Inserted.d.ts +1 -1
- package/esm/dsl/Inserted.js +1 -1
- package/esm/dsl/model/ModelDriver.d.ts +6 -5
- package/esm/dsl/model/ModelDriver.js +22 -20
- package/esm/dsl/model/toModelEntry.d.ts +18 -18
- package/esm/dsl/model/toModelEntry.js +9 -9
- package/esm/dsl/model/toModelProjectionBase.d.ts +17 -16
- package/esm/dsl/model/toModelProjectionBase.js +12 -8
- package/esm/dsl/model/types.d.ts +26 -17
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
- package/esm/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
- package/esm/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
- package/esm/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
- package/esm/dsl/webhook/toWebhookProjectionBase.js +2 -2
- package/esm/helpers/collateExamples.js +35 -17
- package/esm/helpers/refFns.d.ts +108 -43
- package/esm/helpers/refFns.js +166 -57
- package/esm/mod.d.ts +1 -0
- package/esm/mod.js +1 -0
- package/esm/oas/document/Document.d.ts +6 -0
- package/esm/oas/document/Document.js +44 -2
- package/esm/oas/intersection/Intersection.d.ts +122 -0
- package/esm/oas/intersection/Intersection.js +266 -0
- package/esm/oas/mediaType/jsonMediaType.d.ts +1 -1
- package/esm/oas/mediaType/jsonMediaType.js +3 -3
- package/esm/oas/ref/DanglingRefError.d.ts +5 -2
- package/esm/oas/ref/DanglingRefError.js +4 -3
- package/esm/oas/ref/Ref.d.ts +23 -12
- package/esm/oas/ref/Ref.js +68 -72
- package/esm/oas/requestBody/RequestBody.d.ts +1 -1
- package/esm/oas/requestBody/RequestBody.js +1 -1
- package/esm/oas/response/Response.d.ts +1 -1
- package/esm/oas/response/Response.js +1 -1
- package/esm/oas/schema/Schema.d.ts +4 -2
- package/esm/oas/schema/siblings.d.ts +10 -2
- package/esm/oas/schema/siblings.js +87 -22
- package/esm/oas/schemaPath/traverseSchema.d.ts +2 -0
- package/esm/oas/schemaPath/traverseSchema.js +51 -5
- package/esm/parse/allOfSystem.d.ts +3 -0
- package/esm/parse/allOfSystem.js +2 -1
- package/esm/parse/keptIntersection.d.ts +53 -0
- package/esm/parse/keptIntersection.js +155 -0
- package/esm/parse/keptRefs.d.ts +23 -0
- package/esm/parse/keptRefs.js +59 -0
- package/esm/parse/toCyclicRefs.d.ts +8 -0
- package/esm/parse/toCyclicRefs.js +126 -0
- package/esm/parse/toDeclaredTypes.d.ts +20 -0
- package/esm/parse/toDeclaredTypes.js +43 -0
- package/esm/parse/v3-0/_merge-all-of/merge-intersection.js +8 -4
- package/esm/parse/v3-0/_merge-all-of/merge-union.js +7 -1
- package/esm/parse/v3-0/_merge-all-of/merge.js +13 -0
- package/esm/parse/v3-0/_merge-all-of/types.d.ts +3 -0
- package/esm/parse/v3-0/intersection/toIntersection.d.ts +12 -0
- package/esm/parse/v3-0/intersection/toIntersection.js +61 -0
- package/esm/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-0/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-0/schema/toSchemasV3.js +13 -1
- package/esm/parse/v3-1/_merge-all-of/merge-intersection.js +8 -4
- package/esm/parse/v3-1/_merge-all-of/merge-union.js +7 -1
- package/esm/parse/v3-1/_merge-all-of/merge.js +13 -0
- package/esm/parse/v3-1/_merge-all-of/types.d.ts +3 -0
- package/esm/parse/v3-1/intersection/toIntersection.d.ts +12 -0
- package/esm/parse/v3-1/intersection/toIntersection.js +61 -0
- package/esm/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-1/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-1/schema/toSchemasV3.js +15 -2
- package/esm/parse/v3-2/_merge-all-of/merge-intersection.js +8 -4
- package/esm/parse/v3-2/_merge-all-of/merge-union.js +7 -1
- package/esm/parse/v3-2/_merge-all-of/merge.js +13 -0
- package/esm/parse/v3-2/_merge-all-of/types.d.ts +3 -0
- package/esm/parse/v3-2/intersection/toIntersection.d.ts +12 -0
- package/esm/parse/v3-2/intersection/toIntersection.js +61 -0
- package/esm/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
- package/esm/parse/v3-2/ref/toRefTargetV3.js +70 -0
- package/esm/parse/v3-2/schema/toSchemasV3.js +15 -2
- package/esm/types/GeneratorType.d.ts +1 -1
- package/esm/types/ProjectionOptions.d.ts +1 -1
- package/esm/types/ProjectionOptions.js +1 -1
- package/esm/types/RefName.d.ts +3 -3
- package/esm/types/Settings.d.ts +9 -0
- package/esm/types/Settings.js +2 -1
- package/esm/types/TypeSystem.d.ts +20 -5
- package/package.json +1 -1
- package/script/anchors/attribute.js +3 -2
- package/script/context/CoreContext.d.ts +1 -1
- package/script/context/CoreContext.js +1 -1
- package/script/context/GenerateContext.d.ts +13 -10
- package/script/context/GenerateContext.js +36 -25
- package/script/context/ParseContext.d.ts +3 -0
- package/script/context/ParseContext.js +150 -38
- package/script/context/generateTypes.d.ts +7 -6
- package/script/dsl/GeneratorKeys.d.ts +21 -15
- package/script/dsl/GeneratorKeys.js +16 -11
- package/script/dsl/Inserted.d.ts +1 -1
- package/script/dsl/Inserted.js +1 -1
- package/script/dsl/model/ModelDriver.d.ts +6 -5
- package/script/dsl/model/ModelDriver.js +22 -20
- package/script/dsl/model/toModelEntry.d.ts +18 -18
- package/script/dsl/model/toModelEntry.js +9 -9
- package/script/dsl/model/toModelProjectionBase.d.ts +17 -16
- package/script/dsl/model/toModelProjectionBase.js +12 -8
- package/script/dsl/model/types.d.ts +26 -17
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.d.ts +2 -2
- package/script/dsl/operation/gql/toGqlOperationProjectionBase.js +2 -2
- package/script/dsl/operation/oas/toOasOperationProjectionBase.d.ts +2 -2
- package/script/dsl/operation/oas/toOasOperationProjectionBase.js +2 -2
- package/script/dsl/webhook/toWebhookProjectionBase.d.ts +2 -2
- package/script/dsl/webhook/toWebhookProjectionBase.js +2 -2
- package/script/helpers/collateExamples.js +35 -17
- package/script/helpers/refFns.d.ts +108 -43
- package/script/helpers/refFns.js +180 -59
- package/script/mod.d.ts +1 -0
- package/script/mod.js +1 -0
- package/script/oas/document/Document.d.ts +6 -0
- package/script/oas/document/Document.js +44 -2
- package/script/oas/intersection/Intersection.d.ts +122 -0
- package/script/oas/intersection/Intersection.js +270 -0
- package/script/oas/mediaType/jsonMediaType.d.ts +1 -1
- package/script/oas/mediaType/jsonMediaType.js +3 -3
- package/script/oas/ref/DanglingRefError.d.ts +5 -2
- package/script/oas/ref/DanglingRefError.js +4 -3
- package/script/oas/ref/Ref.d.ts +23 -12
- package/script/oas/ref/Ref.js +67 -71
- package/script/oas/requestBody/RequestBody.d.ts +1 -1
- package/script/oas/requestBody/RequestBody.js +1 -1
- package/script/oas/response/Response.d.ts +1 -1
- package/script/oas/response/Response.js +1 -1
- package/script/oas/schema/Schema.d.ts +4 -2
- package/script/oas/schema/siblings.d.ts +10 -2
- package/script/oas/schema/siblings.js +89 -23
- package/script/oas/schemaPath/traverseSchema.d.ts +2 -0
- package/script/oas/schemaPath/traverseSchema.js +50 -4
- package/script/parse/allOfSystem.d.ts +3 -0
- package/script/parse/allOfSystem.js +2 -1
- package/script/parse/keptIntersection.d.ts +53 -0
- package/script/parse/keptIntersection.js +164 -0
- package/script/parse/keptRefs.d.ts +23 -0
- package/script/parse/keptRefs.js +63 -0
- package/script/parse/toCyclicRefs.d.ts +8 -0
- package/script/parse/toCyclicRefs.js +130 -0
- package/script/parse/toDeclaredTypes.d.ts +20 -0
- package/script/parse/toDeclaredTypes.js +48 -0
- package/script/parse/v3-0/_merge-all-of/merge-intersection.js +8 -4
- package/script/parse/v3-0/_merge-all-of/merge-union.js +7 -1
- package/script/parse/v3-0/_merge-all-of/merge.js +13 -0
- package/script/parse/v3-0/_merge-all-of/types.d.ts +3 -0
- package/script/parse/v3-0/intersection/toIntersection.d.ts +12 -0
- package/script/parse/v3-0/intersection/toIntersection.js +65 -0
- package/script/parse/v3-0/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-0/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-0/schema/toSchemasV3.js +13 -1
- package/script/parse/v3-1/_merge-all-of/merge-intersection.js +8 -4
- package/script/parse/v3-1/_merge-all-of/merge-union.js +7 -1
- package/script/parse/v3-1/_merge-all-of/merge.js +13 -0
- package/script/parse/v3-1/_merge-all-of/types.d.ts +3 -0
- package/script/parse/v3-1/intersection/toIntersection.d.ts +12 -0
- package/script/parse/v3-1/intersection/toIntersection.js +65 -0
- package/script/parse/v3-1/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-1/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-1/schema/toSchemasV3.js +15 -2
- package/script/parse/v3-2/_merge-all-of/merge-intersection.js +8 -4
- package/script/parse/v3-2/_merge-all-of/merge-union.js +7 -1
- package/script/parse/v3-2/_merge-all-of/merge.js +13 -0
- package/script/parse/v3-2/_merge-all-of/types.d.ts +3 -0
- package/script/parse/v3-2/intersection/toIntersection.d.ts +12 -0
- package/script/parse/v3-2/intersection/toIntersection.js +65 -0
- package/script/parse/v3-2/ref/toRefTargetV3.d.ts +23 -0
- package/script/parse/v3-2/ref/toRefTargetV3.js +74 -0
- package/script/parse/v3-2/schema/toSchemasV3.js +15 -2
- package/script/types/GeneratorType.d.ts +1 -1
- package/script/types/ProjectionOptions.d.ts +1 -1
- package/script/types/ProjectionOptions.js +1 -1
- package/script/types/RefName.d.ts +3 -3
- package/script/types/Settings.d.ts +9 -0
- package/script/types/Settings.js +2 -1
- package/script/types/TypeSystem.d.ts +20 -5
package/esm/anchors/attribute.js
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { fromGeneratorKey, toGeneratorId } from '../dsl/GeneratorKeys.js';
|
|
16
16
|
import { DefinitionBase } from '../dsl/Definition.js';
|
|
17
|
+
import { toRefPointer } from '../helpers/refFns.js';
|
|
17
18
|
/**
|
|
18
19
|
* Derive the attribution tuple for a producer.
|
|
19
20
|
*
|
|
@@ -53,7 +54,7 @@ export const attribute = (producer) => {
|
|
|
53
54
|
*
|
|
54
55
|
* - OAS operation → `#/paths/<escaped-path>/<method>`
|
|
55
56
|
* - GQL operation → `<rootKind>.<fieldName>`
|
|
56
|
-
* - Model → `#/components/schemas/<refName>`
|
|
57
|
+
* - Model → its ref's pointer: `#/components/schemas/<refName>` for a component
|
|
57
58
|
* - Container / generator-only / no key → `''` (no schema location to point
|
|
58
59
|
* at — a container is a place many subjects insert into, so it has no
|
|
59
60
|
* position of its own; its MEMBERS carry their subjects' keys)
|
|
@@ -69,7 +70,7 @@ const schemaPointerFromKey = (parsed) => {
|
|
|
69
70
|
case 'gqlOperation':
|
|
70
71
|
return `${parsed.rootKind}.${parsed.fieldName}`;
|
|
71
72
|
case 'model':
|
|
72
|
-
return
|
|
73
|
+
return toRefPointer(parsed.ref);
|
|
73
74
|
case 'container':
|
|
74
75
|
case 'generator-only':
|
|
75
76
|
return '';
|
|
@@ -264,7 +264,7 @@ export declare class CoreContext {
|
|
|
264
264
|
* toGeneratorConfigMap: () => ({
|
|
265
265
|
* 'typescript-models': toModelEntry({
|
|
266
266
|
* id: 'typescript-models',
|
|
267
|
-
* transform: ({ context,
|
|
267
|
+
* transform: ({ context, ref }) => {}
|
|
268
268
|
* }),
|
|
269
269
|
* 'api-client': toOasOperationEntry({
|
|
270
270
|
* id: 'api-client',
|
|
@@ -261,7 +261,7 @@ export class CoreContext {
|
|
|
261
261
|
* toGeneratorConfigMap: () => ({
|
|
262
262
|
* 'typescript-models': toModelEntry({
|
|
263
263
|
* id: 'typescript-models',
|
|
264
|
-
* transform: ({ context,
|
|
264
|
+
* transform: ({ context, ref }) => {}
|
|
265
265
|
* }),
|
|
266
266
|
* 'api-client': toOasOperationEntry({
|
|
267
267
|
* id: 'api-client',
|
|
@@ -2,6 +2,7 @@ import type { DefinitionBase } from '../dsl/Definition.js';
|
|
|
2
2
|
import type { PendingDefinition } from '../dsl/PendingDefinition.js';
|
|
3
3
|
import type { OasSchema } from '../oas/schema/Schema.js';
|
|
4
4
|
import type { OasRef } from '../oas/ref/Ref.js';
|
|
5
|
+
import { type RefParts } from '../helpers/refFns.js';
|
|
5
6
|
import type { SkmtcParsedDocument } from '../types/SkmtcDocument.js';
|
|
6
7
|
import type { SupportedSubjects } from '../types/SupportedSubjects.js';
|
|
7
8
|
import type { EnrichmentDefaults } from '../types/EnrichmentDefaults.js';
|
|
@@ -78,8 +79,8 @@ export type CreateAndRegisterDefinition<Schema extends SchemaType> = {
|
|
|
78
79
|
destinationPath: string;
|
|
79
80
|
/** Function to transform the schema into a generated value */
|
|
80
81
|
schemaToValueFn: SchemaToValueFn;
|
|
81
|
-
/**
|
|
82
|
-
rootRef?:
|
|
82
|
+
/** The ref of the model whose value tree holds the schema */
|
|
83
|
+
rootRef?: RefParts;
|
|
83
84
|
/** Whether to exclude this definition from exports */
|
|
84
85
|
noExport?: boolean;
|
|
85
86
|
};
|
|
@@ -120,8 +121,8 @@ export type AddRenderDependencyArgs = {
|
|
|
120
121
|
export type ToModelSettingsArgs = {
|
|
121
122
|
/** The ID of the generator requesting model settings */
|
|
122
123
|
generatorId: string;
|
|
123
|
-
/** The
|
|
124
|
-
|
|
124
|
+
/** The model's ref */
|
|
125
|
+
ref: RefParts;
|
|
125
126
|
};
|
|
126
127
|
/**
|
|
127
128
|
* Return type for insert operations in the generation context.
|
|
@@ -301,7 +302,7 @@ export declare class GenerateContext implements GenerateContextType {
|
|
|
301
302
|
*
|
|
302
303
|
* @mutates this.files
|
|
303
304
|
*/
|
|
304
|
-
insertModel<V extends GeneratedValue, EnrichmentType, ProjectionOptions = undefined>(projection: ModelProjection<V, EnrichmentType, ProjectionOptions>,
|
|
305
|
+
insertModel<V extends GeneratedValue, EnrichmentType, ProjectionOptions = undefined>(projection: ModelProjection<V, EnrichmentType, ProjectionOptions>, ref: RefParts, ...rest: ProjectionOptionsRest<InsertModelOptions<ProjectionOptions>, ProjectionOptions>): Inserted<V, EnrichmentType>;
|
|
305
306
|
/**
|
|
306
307
|
* Build content settings for an operation projection by calling its
|
|
307
308
|
* statics `toIdentifierName` + `toIdentifierType`, `toExportPath`, and
|
|
@@ -319,18 +320,20 @@ export declare class GenerateContext implements GenerateContextType {
|
|
|
319
320
|
* Build content settings for a model projection by calling its statics
|
|
320
321
|
* `toIdentifierName` (pure, for the name) + `toIdentifierType`
|
|
321
322
|
* (context-aware, for type/typeName/exported), `toExportPath`, and
|
|
322
|
-
* `toEnrichments` against the given `
|
|
323
|
+
* `toEnrichments` against the given `ref` and `variant`. The full
|
|
323
324
|
* identifier is assembled through the projection's language
|
|
324
325
|
* (`lang.toIdentifier`).
|
|
325
326
|
*/
|
|
326
327
|
toModelContentSettings<V extends GeneratedValue, EnrichmentType, ProjectionOptions>(args: BuildModelSettingsArgs<V, EnrichmentType, ProjectionOptions>): ContentSettings<EnrichmentType>;
|
|
327
328
|
/**
|
|
328
|
-
* Perform one lookup of schema by `refName
|
|
329
|
-
*
|
|
329
|
+
* Perform one lookup of a model's schema: a component by `refName`, or,
|
|
330
|
+
* with a `refPath` other than `#/components/schemas`, the ref target the
|
|
331
|
+
* parser kept under its whole pointer.
|
|
332
|
+
* @param ref - The model's ref; an `OasRef<'schema'>` fits as it is
|
|
330
333
|
* @returns Matching schema or ref
|
|
331
|
-
* @throws {DanglingRefError} when no schema
|
|
334
|
+
* @throws {DanglingRefError} when no schema is found there
|
|
332
335
|
*/
|
|
333
|
-
resolveSchemaRefOnce(
|
|
336
|
+
resolveSchemaRefOnce(ref: RefParts): OasSchema | OasRef<'schema'>;
|
|
334
337
|
/**
|
|
335
338
|
* Check if definition name `name` in file with path `exportPath`
|
|
336
339
|
* has already been created and registered.
|
|
@@ -13,6 +13,7 @@ var _GenerateContext_instances, _GenerateContext_files, _GenerateContext_failedI
|
|
|
13
13
|
import { normalizeWorkspacePath } from '../helpers/normalizeWorkspacePath.js';
|
|
14
14
|
import { applyGeneratedSuffix, DEFAULT_GENERATED_SUFFIX } from '../helpers/applyGeneratedSuffix.js';
|
|
15
15
|
import { DanglingRefError } from '../oas/ref/DanglingRefError.js';
|
|
16
|
+
import { isDefaultRefPath, isRemoteRefPath, toModelKey, toRefPointer, toSchemaComponentRef } from '../helpers/refFns.js';
|
|
16
17
|
import { isMethod } from '../types/Method.js';
|
|
17
18
|
import { OasOperationDriver } from '../dsl/operation/oas/OasOperationDriver.js';
|
|
18
19
|
import { WebhookDriver } from '../dsl/webhook/WebhookDriver.js';
|
|
@@ -62,11 +63,11 @@ import { formatEnrichmentPath } from '../enrichments/EnrichmentWarning.js';
|
|
|
62
63
|
*
|
|
63
64
|
* class TypeScriptInterface extends ModelProjectionBase {
|
|
64
65
|
* generate(): Definition {
|
|
65
|
-
* const schema = this.context.
|
|
66
|
+
* const schema = this.context.resolveSchemaRefOnce(this.ref);
|
|
66
67
|
*
|
|
67
68
|
* return new Definition({
|
|
68
69
|
* context: this.context,
|
|
69
|
-
* identifier: createType(this.refName),
|
|
70
|
+
* identifier: createType(this.ref.refName),
|
|
70
71
|
* description: schema.description,
|
|
71
72
|
* value: {
|
|
72
73
|
* generatorKey: this.generatorKey,
|
|
@@ -363,7 +364,7 @@ export class GenerateContext {
|
|
|
363
364
|
break;
|
|
364
365
|
}
|
|
365
366
|
case 'model': {
|
|
366
|
-
const models = __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_schemaRefNames).call(this).filter(refName => generatorConfig.isSupported({ refName, context: this, variant: DEFAULT_VARIANT }));
|
|
367
|
+
const models = __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_schemaRefNames).call(this).filter(refName => generatorConfig.isSupported({ ref: toSchemaComponentRef(refName), context: this, variant: DEFAULT_VARIANT }));
|
|
367
368
|
out[generatorConfig.id] = { type: 'model', models };
|
|
368
369
|
break;
|
|
369
370
|
}
|
|
@@ -444,10 +445,10 @@ export class GenerateContext {
|
|
|
444
445
|
// `undefined` for schemas it doesn't seed.
|
|
445
446
|
const models = {};
|
|
446
447
|
for (const refName of __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_schemaRefNames).call(this)) {
|
|
447
|
-
if (!generatorConfig.isSupported({ refName, context: this, variant: DEFAULT_VARIANT })) {
|
|
448
|
+
if (!generatorConfig.isSupported({ ref: toSchemaComponentRef(refName), context: this, variant: DEFAULT_VARIANT })) {
|
|
448
449
|
continue;
|
|
449
450
|
}
|
|
450
|
-
const leaf = __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_subjectDefaults).call(this, () => toDefaults({ refName, context: this, variant: DEFAULT_VARIANT }));
|
|
451
|
+
const leaf = __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_subjectDefaults).call(this, () => toDefaults({ ref: toSchemaComponentRef(refName), context: this, variant: DEFAULT_VARIANT }));
|
|
451
452
|
if (leaf === undefined)
|
|
452
453
|
continue;
|
|
453
454
|
models[refName] = { [DEFAULT_VARIANT]: leaf };
|
|
@@ -648,7 +649,7 @@ export class GenerateContext {
|
|
|
648
649
|
insertNormalizedModel(projection, { schema, fallbackName, destinationPath }, ...rest) {
|
|
649
650
|
const insertOptions = toPeerInsertOptions(rest);
|
|
650
651
|
if (schema.isRef()) {
|
|
651
|
-
const { definition } = this.insertModel(projection, schema
|
|
652
|
+
const { definition } = this.insertModel(projection, schema, {
|
|
652
653
|
...insertOptions,
|
|
653
654
|
destinationPath
|
|
654
655
|
});
|
|
@@ -695,14 +696,14 @@ export class GenerateContext {
|
|
|
695
696
|
*
|
|
696
697
|
* @mutates this.files
|
|
697
698
|
*/
|
|
698
|
-
insertModel(projection,
|
|
699
|
+
insertModel(projection, ref, ...rest) {
|
|
699
700
|
// The Driver defaults `variant` and `noExport` and reads the caller's
|
|
700
701
|
// options off the call.
|
|
701
702
|
const { settings, definition } = new ModelDriver({
|
|
702
703
|
context: this,
|
|
703
704
|
projection,
|
|
704
|
-
|
|
705
|
-
rootRef:
|
|
705
|
+
ref,
|
|
706
|
+
rootRef: ref,
|
|
706
707
|
...toInsertOptions(rest)
|
|
707
708
|
});
|
|
708
709
|
return new Inserted({ settings, definition });
|
|
@@ -809,36 +810,43 @@ export class GenerateContext {
|
|
|
809
810
|
* Build content settings for a model projection by calling its statics
|
|
810
811
|
* `toIdentifierName` (pure, for the name) + `toIdentifierType`
|
|
811
812
|
* (context-aware, for type/typeName/exported), `toExportPath`, and
|
|
812
|
-
* `toEnrichments` against the given `
|
|
813
|
+
* `toEnrichments` against the given `ref` and `variant`. The full
|
|
813
814
|
* identifier is assembled through the projection's language
|
|
814
815
|
* (`lang.toIdentifier`).
|
|
815
816
|
*/
|
|
816
817
|
toModelContentSettings(args) {
|
|
817
|
-
const {
|
|
818
|
+
const { ref, projection, variant = DEFAULT_VARIANT } = args;
|
|
818
819
|
const options = readProjectionOptions(args);
|
|
819
|
-
const enrichments = projection.toEnrichments({
|
|
820
|
+
const enrichments = projection.toEnrichments({ ref, context: this, variant });
|
|
820
821
|
return new ContentSettings({
|
|
821
822
|
identifier: projection.lang.toIdentifier({
|
|
822
|
-
name: projection.toIdentifierName({
|
|
823
|
-
...projection.toIdentifierType(
|
|
823
|
+
name: projection.toIdentifierName({ ref, enrichments, variant, options }),
|
|
824
|
+
...projection.toIdentifierType(ref, this)
|
|
824
825
|
}),
|
|
825
|
-
exportPath: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, projection.toExportPath({
|
|
826
|
+
exportPath: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, projection.toExportPath({ ref, enrichments, variant, options }), projection.id),
|
|
826
827
|
enrichments,
|
|
827
828
|
variant
|
|
828
829
|
});
|
|
829
830
|
}
|
|
830
831
|
/**
|
|
831
|
-
* Perform one lookup of schema by `refName
|
|
832
|
-
*
|
|
832
|
+
* Perform one lookup of a model's schema: a component by `refName`, or,
|
|
833
|
+
* with a `refPath` other than `#/components/schemas`, the ref target the
|
|
834
|
+
* parser kept under its whole pointer.
|
|
835
|
+
* @param ref - The model's ref; an `OasRef<'schema'>` fits as it is
|
|
833
836
|
* @returns Matching schema or ref
|
|
834
|
-
* @throws {DanglingRefError} when no schema
|
|
837
|
+
* @throws {DanglingRefError} when no schema is found there
|
|
835
838
|
*/
|
|
836
|
-
resolveSchemaRefOnce(
|
|
839
|
+
resolveSchemaRefOnce(ref) {
|
|
840
|
+
const { refName, refPath } = ref;
|
|
837
841
|
switch (this.document.type) {
|
|
838
842
|
case 'oas': {
|
|
839
|
-
const
|
|
840
|
-
|
|
841
|
-
|
|
843
|
+
const document = this.document.value;
|
|
844
|
+
const component = isDefaultRefPath({ refPath, refType: 'schema' })
|
|
845
|
+
? document.components?.schemas?.[refName]
|
|
846
|
+
: document.toRefTarget(toRefPointer({ refName, refPath }));
|
|
847
|
+
// The parser keeps ref targets of every kind; a model is built only from a schema.
|
|
848
|
+
if (component === undefined || !isSchemaEntry(component)) {
|
|
849
|
+
throw new DanglingRefError(toModelKey(ref), { remote: isRemoteRefPath(refPath) });
|
|
842
850
|
}
|
|
843
851
|
const target = component.resolveOnce();
|
|
844
852
|
// One step, with what the component adds next to its reference
|
|
@@ -1141,6 +1149,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
|
|
|
1141
1149
|
? (document.value.components?.toSchemasRefNames() ?? [])
|
|
1142
1150
|
: document.value.registry.toSchemasRefNames();
|
|
1143
1151
|
refNames.forEach(refName => {
|
|
1152
|
+
const ref = toSchemaComponentRef(refName);
|
|
1144
1153
|
stackTrail.trace(refName, refTrail => {
|
|
1145
1154
|
// Resolve the variant list to fan out over. The consumer's
|
|
1146
1155
|
// enrichments are keyed `[generatorId][refName][variant]`; the
|
|
@@ -1163,7 +1172,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
|
|
|
1163
1172
|
refTrail.trace(['variant', variant], st => this.withSubjectTrail(st, () => {
|
|
1164
1173
|
try {
|
|
1165
1174
|
if (typeof generatorConfig.isSupported === 'function' &&
|
|
1166
|
-
!generatorConfig.isSupported({
|
|
1175
|
+
!generatorConfig.isSupported({ ref, context: this, variant })) {
|
|
1167
1176
|
this.captureCurrentResult('notSupported', st);
|
|
1168
1177
|
return;
|
|
1169
1178
|
}
|
|
@@ -1192,7 +1201,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
|
|
|
1192
1201
|
}
|
|
1193
1202
|
generatorConfig.transform({
|
|
1194
1203
|
context: this,
|
|
1195
|
-
|
|
1204
|
+
ref,
|
|
1196
1205
|
variant
|
|
1197
1206
|
});
|
|
1198
1207
|
const source = toModelSource({
|
|
@@ -1200,7 +1209,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
|
|
|
1200
1209
|
generatorId: generatorConfig.id,
|
|
1201
1210
|
variant
|
|
1202
1211
|
});
|
|
1203
|
-
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_addPreview).call(this, source, generatorConfig.toPreviewModule?.({ context: this,
|
|
1212
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_addPreview).call(this, source, generatorConfig.toPreviewModule?.({ context: this, ref, variant }));
|
|
1204
1213
|
this.captureCurrentResult('success', st);
|
|
1205
1214
|
}
|
|
1206
1215
|
catch (error) {
|
|
@@ -1477,3 +1486,5 @@ const toIncludeModels = (include, generatorId) => {
|
|
|
1477
1486
|
}
|
|
1478
1487
|
return undefined;
|
|
1479
1488
|
};
|
|
1489
|
+
/** Whether a ref target is a schema, or a ref to one: what a model is built from. */
|
|
1490
|
+
const isSchemaEntry = (entry) => entry.isRef() ? entry.isSchemaRef() : entry.oasType === 'schema';
|
|
@@ -25,6 +25,7 @@ import { GqlDocument } from '../gql/document/GqlDocument.js';
|
|
|
25
25
|
import type { Logger } from '../types/Logger.js';
|
|
26
26
|
export type { AttributionState } from '../types/AttributionState.js';
|
|
27
27
|
import { StackTrail } from './StackTrail.js';
|
|
28
|
+
import { type KeptRefs } from '../parse/keptRefs.js';
|
|
28
29
|
import type { SkmtcDocumentInput, SkmtcParsedDocument } from '../types/SkmtcDocument.js';
|
|
29
30
|
import type { GqlParseOptions, LogAtArgs, LogIssueArgs, LogIssueAtArgs, LogIssueNoKeyArgs, LogSkippedValuesArgs } from './parseTypes.js';
|
|
30
31
|
import type { ParseIssue } from './ParseIssue.js';
|
|
@@ -101,6 +102,8 @@ export declare class ParseContext {
|
|
|
101
102
|
get oasDocument(): OasDocument;
|
|
102
103
|
/** OAS-only accessor; symmetric reason to {@link oasDocument}. */
|
|
103
104
|
get documentObject(): OpenAPIV3.Document;
|
|
105
|
+
/** The refs of the document that a merge keeps as refs (`system.intersections`); `undefined` under `merge`. */
|
|
106
|
+
get keptRefs(): KeptRefs | undefined;
|
|
104
107
|
/** GQL-only accessor; throws if called on an OAS context. */
|
|
105
108
|
get schema(): GraphQLSchema;
|
|
106
109
|
/** GQL-only accessor; throws if called on an OAS context. */
|