@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
|
@@ -9,6 +9,7 @@ import { OasParameter } from '../../../oas/parameter/Parameter.js';
|
|
|
9
9
|
import { toSpecificationExtensionsV3 } from '../specificationExtensions/toSpecificationExtensionsV3.js';
|
|
10
10
|
import * as v from 'valibot';
|
|
11
11
|
import { isEmptyParameter, logEmptyParameter } from '../../emptyParameter.js';
|
|
12
|
+
import { toMissingParameterSchema } from '../../missingSchema.js';
|
|
12
13
|
import { toParameterEntries, toPathParameterList } from '../../pathParameters.js';
|
|
13
14
|
export const toParameterListV3 = ({ parameters, stackTrail, context }) => toParameterEntries({ parameters, stackTrail, context })?.flatMap((parameter, index) => toParameterEntryV3({ parameter, index, stackTrail, context }));
|
|
14
15
|
/**
|
|
@@ -129,6 +130,16 @@ const toParameterV3 = ({ parameter, stackTrail, context }) => {
|
|
|
129
130
|
content: stackTrail.trace('content', st => toOptionalMediaTypeItemsV3({ content, stackTrail: st, context })),
|
|
130
131
|
extensionFields
|
|
131
132
|
};
|
|
133
|
+
// A `null` schema or content reads as absent; a boolean schema does not.
|
|
134
|
+
if (typeof schema !== 'boolean' && fields.schema === undefined && fields.content === undefined) {
|
|
135
|
+
fields.schema = toMissingParameterSchema({
|
|
136
|
+
parameter,
|
|
137
|
+
name,
|
|
138
|
+
location: parsedLocation,
|
|
139
|
+
stackTrail,
|
|
140
|
+
context
|
|
141
|
+
});
|
|
142
|
+
}
|
|
132
143
|
return context.withStackTrail(stackTrail, () => new OasParameter(fields, context));
|
|
133
144
|
};
|
|
134
145
|
const toStyle = ({ style, location, stackTrail }) => {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { ParseContextType } from '../../../context/parseTypes.js';
|
|
2
|
+
import type { StackTrail } from '../../../context/StackTrail.js';
|
|
3
|
+
import type { ComponentsEntry } from '../../../oas/components/Components.js';
|
|
4
|
+
import type { OasRefData } from '../../../oas/ref/ref-types.js';
|
|
5
|
+
/** What {@link toRefTargetV3} parses. */
|
|
6
|
+
export type ToRefTargetArgs = {
|
|
7
|
+
/** The kind of component the ref is written for. */
|
|
8
|
+
refType: OasRefData['refType'];
|
|
9
|
+
/** The last segment of the target's pointer, unescaped: the key it parses under. */
|
|
10
|
+
name: string;
|
|
11
|
+
/** The raw value at the pointer. */
|
|
12
|
+
value: Record<string, unknown>;
|
|
13
|
+
/** The trail of the target's parent, so the target parses at its own position. */
|
|
14
|
+
stackTrail: StackTrail;
|
|
15
|
+
context: ParseContextType;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Parses the target of a ref that does not point at a component
|
|
19
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
20
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
21
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
22
|
+
*/
|
|
23
|
+
export declare const toRefTargetV3: ({ refType, name, value, stackTrail, context }: ToRefTargetArgs) => ComponentsEntry | undefined;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isPlainObject } from '../../isPlainObject.js';
|
|
2
|
+
import { toOptionalSchemasV3 } from '../schema/toSchemasV3.js';
|
|
3
|
+
import { toOptionalParametersV3 } from '../parameter/toParameterV3.js';
|
|
4
|
+
import { toOptionalResponsesV3 } from '../response/toResponseV3.js';
|
|
5
|
+
import { toRequestBodiesV3 } from '../requestBody/toRequestBodiesV3.js';
|
|
6
|
+
import { toComponentHeadersV3 } from '../header/toHeadersV3.js';
|
|
7
|
+
import { toLinksV3 } from '../link/toLinksV3.js';
|
|
8
|
+
import { toExampleV3 } from '../example/toExamplesV3.js';
|
|
9
|
+
import { toSecuritySchemesV3 } from '../securitySchemes/toSecuritySchemes.js';
|
|
10
|
+
import { tryParseAt } from '../../../context/tryParseAt.js';
|
|
11
|
+
/**
|
|
12
|
+
* The raw value read as the OpenAPI type its parser takes, as the components
|
|
13
|
+
* parser reads `documentObject.components`: the parser checks what it reads.
|
|
14
|
+
*/
|
|
15
|
+
const isRawEntry = (value) => isPlainObject(value);
|
|
16
|
+
/**
|
|
17
|
+
* Parses the target of a ref that does not point at a component
|
|
18
|
+
* (`#/components/schemas/Pet/properties/tag`, `#/paths/~1pets/get/parameters/0`)
|
|
19
|
+
* at its own position, with the parser that components of its kind use. Gives
|
|
20
|
+
* `undefined` when the target does not parse (the parser has logged why).
|
|
21
|
+
*/
|
|
22
|
+
export const toRefTargetV3 = ({ refType, name, value, stackTrail, context }) => {
|
|
23
|
+
switch (refType) {
|
|
24
|
+
case 'schema':
|
|
25
|
+
return isRawEntry(value)
|
|
26
|
+
? toOptionalSchemasV3({ schemas: { [name]: value }, stackTrail, context })?.[name]
|
|
27
|
+
: undefined;
|
|
28
|
+
case 'parameter':
|
|
29
|
+
return isRawEntry(value)
|
|
30
|
+
? toOptionalParametersV3({ parameters: { [name]: value }, stackTrail, context })?.[name]
|
|
31
|
+
: undefined;
|
|
32
|
+
case 'response':
|
|
33
|
+
return isRawEntry(value)
|
|
34
|
+
? toOptionalResponsesV3({ responses: { [name]: value }, stackTrail, context })?.[name]
|
|
35
|
+
: undefined;
|
|
36
|
+
case 'requestBody':
|
|
37
|
+
return isRawEntry(value)
|
|
38
|
+
? toRequestBodiesV3({ requestBodies: { [name]: value }, stackTrail, context })?.[name]
|
|
39
|
+
: undefined;
|
|
40
|
+
case 'header':
|
|
41
|
+
return isRawEntry(value)
|
|
42
|
+
? toComponentHeadersV3({ headers: { [name]: value }, stackTrail, context })?.[name]
|
|
43
|
+
: undefined;
|
|
44
|
+
case 'link':
|
|
45
|
+
return isRawEntry(value)
|
|
46
|
+
? toLinksV3({ links: { [name]: value }, stackTrail, context })?.[name]
|
|
47
|
+
: undefined;
|
|
48
|
+
case 'example':
|
|
49
|
+
// No components parser reads a single example by key, so the target
|
|
50
|
+
// is parsed as `toExamplesV3` parses each entry, under `tryParseAt`.
|
|
51
|
+
return isRawEntry(value)
|
|
52
|
+
? tryParseAt({
|
|
53
|
+
stackTrail,
|
|
54
|
+
key: name,
|
|
55
|
+
context,
|
|
56
|
+
type: 'INVALID_EXAMPLE',
|
|
57
|
+
parent: value,
|
|
58
|
+
fn: st => toExampleV3({ example: value, stackTrail: st, context })
|
|
59
|
+
})
|
|
60
|
+
: undefined;
|
|
61
|
+
case 'securityScheme':
|
|
62
|
+
return isRawEntry(value)
|
|
63
|
+
? toSecuritySchemesV3({ securitySchemes: { [name]: value }, stackTrail, context })?.[name]
|
|
64
|
+
: undefined;
|
|
65
|
+
default: {
|
|
66
|
+
const _exhaustive = refType;
|
|
67
|
+
throw new Error(`Unhandled ref type: ${_exhaustive}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
@@ -43,7 +43,7 @@ import type { ModelEntry } from '../dsl/model/toModelEntry.js';
|
|
|
43
43
|
*
|
|
44
44
|
* const modelEntry = toModelEntry({
|
|
45
45
|
* id: 'typescript-models',
|
|
46
|
-
* transform: ({ context,
|
|
46
|
+
* transform: ({ context, ref }) => {}
|
|
47
47
|
* });
|
|
48
48
|
* // modelEntry.type === 'model'
|
|
49
49
|
* ```
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @fileoverview Caller options for projections.
|
|
3
3
|
*
|
|
4
4
|
* Options are typed data the CALLING generator passes when it inserts a
|
|
5
|
-
* peer: `context.insertModel(Peer,
|
|
5
|
+
* peer: `context.insertModel(Peer, ref, { options })`. Enrichments are
|
|
6
6
|
* the user's per-subject configuration and a variant selects one of them;
|
|
7
7
|
* options belong to the caller.
|
|
8
8
|
*
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @fileoverview Caller options for projections.
|
|
3
3
|
*
|
|
4
4
|
* Options are typed data the CALLING generator passes when it inserts a
|
|
5
|
-
* peer: `context.insertModel(Peer,
|
|
5
|
+
* peer: `context.insertModel(Peer, ref, { options })`. Enrichments are
|
|
6
6
|
* the user's per-subject configuration and a variant selects one of them;
|
|
7
7
|
* options belong to the caller.
|
|
8
8
|
*
|
package/esm/types/RefName.d.ts
CHANGED
|
@@ -99,14 +99,14 @@ import type { Brand } from './Brand.js';
|
|
|
99
99
|
* @example In generator contexts
|
|
100
100
|
* ```typescript
|
|
101
101
|
* class ModelGenerator extends ModelProjectionBase {
|
|
102
|
-
* constructor(args: {
|
|
102
|
+
* constructor(args: { ref: RefParts; ... }) {
|
|
103
103
|
* super(args);
|
|
104
|
-
* // this.refName is
|
|
104
|
+
* // this.ref.refName is the name of the model's ref
|
|
105
105
|
* }
|
|
106
106
|
*
|
|
107
107
|
* toDefinition(): Definition {
|
|
108
108
|
* // RefName ensures we're working with valid schema identifiers
|
|
109
|
-
* const schemaName = this.refName; // Type: RefName
|
|
109
|
+
* const schemaName = this.ref.refName; // Type: RefName
|
|
110
110
|
* return new Definition({
|
|
111
111
|
* identifier: createType(schemaName),
|
|
112
112
|
* // ...
|
|
@@ -7,7 +7,7 @@ import type { GenerateContextType } from '../context/generateTypes.js';
|
|
|
7
7
|
import type { CustomValue } from '../dsl/CustomValue.js';
|
|
8
8
|
import type { OasVoid } from '../oas/void/Void.js';
|
|
9
9
|
import type { GeneratorKey } from '../dsl/GeneratorKeys.js';
|
|
10
|
-
import type {
|
|
10
|
+
import type { RefParts } from '../helpers/refFns.js';
|
|
11
11
|
/**
|
|
12
12
|
* Union type representing all possible type system values in the SKMTC code generation system.
|
|
13
13
|
*
|
|
@@ -539,8 +539,8 @@ export type TypeSystemArgs<Schema extends SchemaType> = {
|
|
|
539
539
|
destinationPath: string;
|
|
540
540
|
/** The schema to transform */
|
|
541
541
|
schema: Schema;
|
|
542
|
-
/**
|
|
543
|
-
rootRef?:
|
|
542
|
+
/** The ref of the model whose value tree holds the schema */
|
|
543
|
+
rootRef?: RefParts;
|
|
544
544
|
/** Whether the schema field is required */
|
|
545
545
|
required: boolean | undefined;
|
|
546
546
|
};
|
package/package.json
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.attribute = void 0;
|
|
18
18
|
const GeneratorKeys_js_1 = require("../dsl/GeneratorKeys.js");
|
|
19
19
|
const Definition_js_1 = require("../dsl/Definition.js");
|
|
20
|
+
const refFns_js_1 = require("../helpers/refFns.js");
|
|
20
21
|
/**
|
|
21
22
|
* Derive the attribution tuple for a producer.
|
|
22
23
|
*
|
|
@@ -57,7 +58,7 @@ exports.attribute = attribute;
|
|
|
57
58
|
*
|
|
58
59
|
* - OAS operation → `#/paths/<escaped-path>/<method>`
|
|
59
60
|
* - GQL operation → `<rootKind>.<fieldName>`
|
|
60
|
-
* - Model → `#/components/schemas/<refName>`
|
|
61
|
+
* - Model → its ref's pointer: `#/components/schemas/<refName>` for a component
|
|
61
62
|
* - Container / generator-only / no key → `''` (no schema location to point
|
|
62
63
|
* at — a container is a place many subjects insert into, so it has no
|
|
63
64
|
* position of its own; its MEMBERS carry their subjects' keys)
|
|
@@ -73,7 +74,7 @@ const schemaPointerFromKey = (parsed) => {
|
|
|
73
74
|
case 'gqlOperation':
|
|
74
75
|
return `${parsed.rootKind}.${parsed.fieldName}`;
|
|
75
76
|
case 'model':
|
|
76
|
-
return
|
|
77
|
+
return (0, refFns_js_1.toRefPointer)(parsed.ref);
|
|
77
78
|
case 'container':
|
|
78
79
|
case 'generator-only':
|
|
79
80
|
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',
|
|
@@ -299,7 +299,7 @@ class CoreContext {
|
|
|
299
299
|
* toGeneratorConfigMap: () => ({
|
|
300
300
|
* 'typescript-models': toModelEntry({
|
|
301
301
|
* id: 'typescript-models',
|
|
302
|
-
* transform: ({ context,
|
|
302
|
+
* transform: ({ context, ref }) => {}
|
|
303
303
|
* }),
|
|
304
304
|
* 'api-client': toOasOperationEntry({
|
|
305
305
|
* 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.
|
|
@@ -19,6 +19,7 @@ exports.toModelSource = exports.toGqlOperationSource = exports.toWebhookSource =
|
|
|
19
19
|
const normalizeWorkspacePath_js_1 = require("../helpers/normalizeWorkspacePath.js");
|
|
20
20
|
const applyGeneratedSuffix_js_1 = require("../helpers/applyGeneratedSuffix.js");
|
|
21
21
|
const DanglingRefError_js_1 = require("../oas/ref/DanglingRefError.js");
|
|
22
|
+
const refFns_js_1 = require("../helpers/refFns.js");
|
|
22
23
|
const Method_js_1 = require("../types/Method.js");
|
|
23
24
|
const OasOperationDriver_js_1 = require("../dsl/operation/oas/OasOperationDriver.js");
|
|
24
25
|
const WebhookDriver_js_1 = require("../dsl/webhook/WebhookDriver.js");
|
|
@@ -68,11 +69,11 @@ const EnrichmentWarning_js_1 = require("../enrichments/EnrichmentWarning.js");
|
|
|
68
69
|
*
|
|
69
70
|
* class TypeScriptInterface extends ModelProjectionBase {
|
|
70
71
|
* generate(): Definition {
|
|
71
|
-
* const schema = this.context.
|
|
72
|
+
* const schema = this.context.resolveSchemaRefOnce(this.ref);
|
|
72
73
|
*
|
|
73
74
|
* return new Definition({
|
|
74
75
|
* context: this.context,
|
|
75
|
-
* identifier: createType(this.refName),
|
|
76
|
+
* identifier: createType(this.ref.refName),
|
|
76
77
|
* description: schema.description,
|
|
77
78
|
* value: {
|
|
78
79
|
* generatorKey: this.generatorKey,
|
|
@@ -369,7 +370,7 @@ class GenerateContext {
|
|
|
369
370
|
break;
|
|
370
371
|
}
|
|
371
372
|
case 'model': {
|
|
372
|
-
const models = __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_schemaRefNames).call(this).filter(refName => generatorConfig.isSupported({ refName, context: this, variant: Variant_js_1.DEFAULT_VARIANT }));
|
|
373
|
+
const models = __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_schemaRefNames).call(this).filter(refName => generatorConfig.isSupported({ ref: (0, refFns_js_1.toSchemaComponentRef)(refName), context: this, variant: Variant_js_1.DEFAULT_VARIANT }));
|
|
373
374
|
out[generatorConfig.id] = { type: 'model', models };
|
|
374
375
|
break;
|
|
375
376
|
}
|
|
@@ -450,10 +451,10 @@ class GenerateContext {
|
|
|
450
451
|
// `undefined` for schemas it doesn't seed.
|
|
451
452
|
const models = {};
|
|
452
453
|
for (const refName of __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_schemaRefNames).call(this)) {
|
|
453
|
-
if (!generatorConfig.isSupported({ refName, context: this, variant: Variant_js_1.DEFAULT_VARIANT })) {
|
|
454
|
+
if (!generatorConfig.isSupported({ ref: (0, refFns_js_1.toSchemaComponentRef)(refName), context: this, variant: Variant_js_1.DEFAULT_VARIANT })) {
|
|
454
455
|
continue;
|
|
455
456
|
}
|
|
456
|
-
const leaf = __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_subjectDefaults).call(this, () => toDefaults({ refName, context: this, variant: Variant_js_1.DEFAULT_VARIANT }));
|
|
457
|
+
const leaf = __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_subjectDefaults).call(this, () => toDefaults({ ref: (0, refFns_js_1.toSchemaComponentRef)(refName), context: this, variant: Variant_js_1.DEFAULT_VARIANT }));
|
|
457
458
|
if (leaf === undefined)
|
|
458
459
|
continue;
|
|
459
460
|
models[refName] = { [Variant_js_1.DEFAULT_VARIANT]: leaf };
|
|
@@ -654,7 +655,7 @@ class GenerateContext {
|
|
|
654
655
|
insertNormalizedModel(projection, { schema, fallbackName, destinationPath }, ...rest) {
|
|
655
656
|
const insertOptions = (0, InsertOptions_js_1.toPeerInsertOptions)(rest);
|
|
656
657
|
if (schema.isRef()) {
|
|
657
|
-
const { definition } = this.insertModel(projection, schema
|
|
658
|
+
const { definition } = this.insertModel(projection, schema, {
|
|
658
659
|
...insertOptions,
|
|
659
660
|
destinationPath
|
|
660
661
|
});
|
|
@@ -701,14 +702,14 @@ class GenerateContext {
|
|
|
701
702
|
*
|
|
702
703
|
* @mutates this.files
|
|
703
704
|
*/
|
|
704
|
-
insertModel(projection,
|
|
705
|
+
insertModel(projection, ref, ...rest) {
|
|
705
706
|
// The Driver defaults `variant` and `noExport` and reads the caller's
|
|
706
707
|
// options off the call.
|
|
707
708
|
const { settings, definition } = new ModelDriver_js_1.ModelDriver({
|
|
708
709
|
context: this,
|
|
709
710
|
projection,
|
|
710
|
-
|
|
711
|
-
rootRef:
|
|
711
|
+
ref,
|
|
712
|
+
rootRef: ref,
|
|
712
713
|
...(0, InsertOptions_js_1.toInsertOptions)(rest)
|
|
713
714
|
});
|
|
714
715
|
return new Inserted_js_1.Inserted({ settings, definition });
|
|
@@ -815,36 +816,43 @@ class GenerateContext {
|
|
|
815
816
|
* Build content settings for a model projection by calling its statics
|
|
816
817
|
* `toIdentifierName` (pure, for the name) + `toIdentifierType`
|
|
817
818
|
* (context-aware, for type/typeName/exported), `toExportPath`, and
|
|
818
|
-
* `toEnrichments` against the given `
|
|
819
|
+
* `toEnrichments` against the given `ref` and `variant`. The full
|
|
819
820
|
* identifier is assembled through the projection's language
|
|
820
821
|
* (`lang.toIdentifier`).
|
|
821
822
|
*/
|
|
822
823
|
toModelContentSettings(args) {
|
|
823
|
-
const {
|
|
824
|
+
const { ref, projection, variant = Variant_js_1.DEFAULT_VARIANT } = args;
|
|
824
825
|
const options = (0, ProjectionOptions_js_1.readProjectionOptions)(args);
|
|
825
|
-
const enrichments = projection.toEnrichments({
|
|
826
|
+
const enrichments = projection.toEnrichments({ ref, context: this, variant });
|
|
826
827
|
return new ContentSettings_js_1.ContentSettings({
|
|
827
828
|
identifier: projection.lang.toIdentifier({
|
|
828
|
-
name: projection.toIdentifierName({
|
|
829
|
-
...projection.toIdentifierType(
|
|
829
|
+
name: projection.toIdentifierName({ ref, enrichments, variant, options }),
|
|
830
|
+
...projection.toIdentifierType(ref, this)
|
|
830
831
|
}),
|
|
831
|
-
exportPath: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, projection.toExportPath({
|
|
832
|
+
exportPath: __classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_toContentSettingsExportPath).call(this, projection.toExportPath({ ref, enrichments, variant, options }), projection.id),
|
|
832
833
|
enrichments,
|
|
833
834
|
variant
|
|
834
835
|
});
|
|
835
836
|
}
|
|
836
837
|
/**
|
|
837
|
-
* Perform one lookup of schema by `refName
|
|
838
|
-
*
|
|
838
|
+
* Perform one lookup of a model's schema: a component by `refName`, or,
|
|
839
|
+
* with a `refPath` other than `#/components/schemas`, the ref target the
|
|
840
|
+
* parser kept under its whole pointer.
|
|
841
|
+
* @param ref - The model's ref; an `OasRef<'schema'>` fits as it is
|
|
839
842
|
* @returns Matching schema or ref
|
|
840
|
-
* @throws {DanglingRefError} when no schema
|
|
843
|
+
* @throws {DanglingRefError} when no schema is found there
|
|
841
844
|
*/
|
|
842
|
-
resolveSchemaRefOnce(
|
|
845
|
+
resolveSchemaRefOnce(ref) {
|
|
846
|
+
const { refName, refPath } = ref;
|
|
843
847
|
switch (this.document.type) {
|
|
844
848
|
case 'oas': {
|
|
845
|
-
const
|
|
846
|
-
|
|
847
|
-
|
|
849
|
+
const document = this.document.value;
|
|
850
|
+
const component = (0, refFns_js_1.isDefaultRefPath)({ refPath, refType: 'schema' })
|
|
851
|
+
? document.components?.schemas?.[refName]
|
|
852
|
+
: document.toRefTarget((0, refFns_js_1.toRefPointer)({ refName, refPath }));
|
|
853
|
+
// The parser keeps ref targets of every kind; a model is built only from a schema.
|
|
854
|
+
if (component === undefined || !isSchemaEntry(component)) {
|
|
855
|
+
throw new DanglingRefError_js_1.DanglingRefError((0, refFns_js_1.toModelKey)(ref), { remote: (0, refFns_js_1.isRemoteRefPath)(refPath) });
|
|
848
856
|
}
|
|
849
857
|
const target = component.resolveOnce();
|
|
850
858
|
// One step, with what the component adds next to its reference
|
|
@@ -1148,6 +1156,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
|
|
|
1148
1156
|
? (document.value.components?.toSchemasRefNames() ?? [])
|
|
1149
1157
|
: document.value.registry.toSchemasRefNames();
|
|
1150
1158
|
refNames.forEach(refName => {
|
|
1159
|
+
const ref = (0, refFns_js_1.toSchemaComponentRef)(refName);
|
|
1151
1160
|
stackTrail.trace(refName, refTrail => {
|
|
1152
1161
|
// Resolve the variant list to fan out over. The consumer's
|
|
1153
1162
|
// enrichments are keyed `[generatorId][refName][variant]`; the
|
|
@@ -1170,7 +1179,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
|
|
|
1170
1179
|
refTrail.trace(['variant', variant], st => this.withSubjectTrail(st, () => {
|
|
1171
1180
|
try {
|
|
1172
1181
|
if (typeof generatorConfig.isSupported === 'function' &&
|
|
1173
|
-
!generatorConfig.isSupported({
|
|
1182
|
+
!generatorConfig.isSupported({ ref, context: this, variant })) {
|
|
1174
1183
|
this.captureCurrentResult('notSupported', st);
|
|
1175
1184
|
return;
|
|
1176
1185
|
}
|
|
@@ -1199,7 +1208,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
|
|
|
1199
1208
|
}
|
|
1200
1209
|
generatorConfig.transform({
|
|
1201
1210
|
context: this,
|
|
1202
|
-
|
|
1211
|
+
ref,
|
|
1203
1212
|
variant
|
|
1204
1213
|
});
|
|
1205
1214
|
const source = (0, exports.toModelSource)({
|
|
@@ -1207,7 +1216,7 @@ _GenerateContext_files = new WeakMap(), _GenerateContext_failedItems = new WeakM
|
|
|
1207
1216
|
generatorId: generatorConfig.id,
|
|
1208
1217
|
variant
|
|
1209
1218
|
});
|
|
1210
|
-
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_addPreview).call(this, source, generatorConfig.toPreviewModule?.({ context: this,
|
|
1219
|
+
__classPrivateFieldGet(this, _GenerateContext_instances, "m", _GenerateContext_addPreview).call(this, source, generatorConfig.toPreviewModule?.({ context: this, ref, variant }));
|
|
1211
1220
|
this.captureCurrentResult('success', st);
|
|
1212
1221
|
}
|
|
1213
1222
|
catch (error) {
|
|
@@ -1488,3 +1497,5 @@ const toIncludeModels = (include, generatorId) => {
|
|
|
1488
1497
|
}
|
|
1489
1498
|
return undefined;
|
|
1490
1499
|
};
|
|
1500
|
+
/** Whether a ref target is a schema, or a ref to one: what a model is built from. */
|
|
1501
|
+
const isSchemaEntry = (entry) => entry.isRef() ? entry.isSchemaRef() : entry.oasType === 'schema';
|