@twin.org/tools-core 0.0.3-next.2 → 0.0.3-next.21
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/README.md +2 -2
- package/dist/es/index.js +20 -11
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/ITypeScriptToSchemaContext.js +2 -0
- package/dist/es/models/ITypeScriptToSchemaContext.js.map +1 -0
- package/dist/es/models/ITypeScriptToSchemaDiagnostics.js +4 -0
- package/dist/es/models/ITypeScriptToSchemaDiagnostics.js.map +1 -0
- package/dist/es/models/ITypeScriptToSchemaOptions.js +4 -0
- package/dist/es/models/ITypeScriptToSchemaOptions.js.map +1 -0
- package/dist/es/utils/constants.js +43 -0
- package/dist/es/utils/constants.js.map +1 -0
- package/dist/es/utils/diagnosticReporter.js +32 -0
- package/dist/es/utils/diagnosticReporter.js.map +1 -0
- package/dist/es/utils/disallowedTypeGuard.js +151 -0
- package/dist/es/utils/disallowedTypeGuard.js.map +1 -0
- package/dist/es/utils/enum.js +152 -0
- package/dist/es/utils/enum.js.map +1 -0
- package/dist/es/utils/fileUtils.js +130 -0
- package/dist/es/utils/fileUtils.js.map +1 -0
- package/dist/es/utils/importTypeQuerySchemaResolver.js +328 -0
- package/dist/es/utils/importTypeQuerySchemaResolver.js.map +1 -0
- package/dist/es/utils/indexSignaturePatternResolver.js +94 -0
- package/dist/es/utils/indexSignaturePatternResolver.js.map +1 -0
- package/dist/es/utils/intersectionSchemaMerger.js +85 -0
- package/dist/es/utils/intersectionSchemaMerger.js.map +1 -0
- package/dist/es/utils/jsDoc.js +120 -0
- package/dist/es/utils/jsDoc.js.map +1 -0
- package/dist/es/utils/jsonSchemaBuilder.js +3373 -0
- package/dist/es/utils/jsonSchemaBuilder.js.map +1 -0
- package/dist/es/utils/mappedTypeSchemaResolver.js +231 -0
- package/dist/es/utils/mappedTypeSchemaResolver.js.map +1 -0
- package/dist/es/utils/objectTransformer.js +162 -0
- package/dist/es/utils/objectTransformer.js.map +1 -0
- package/dist/es/utils/regEx.js +128 -0
- package/dist/es/utils/regEx.js.map +1 -0
- package/dist/es/utils/resolver.js +164 -0
- package/dist/es/utils/resolver.js.map +1 -0
- package/dist/es/utils/templateLiteralPatternBuilder.js +94 -0
- package/dist/es/utils/templateLiteralPatternBuilder.js.map +1 -0
- package/dist/es/utils/typeScriptToSchema.js +112 -0
- package/dist/es/utils/typeScriptToSchema.js.map +1 -0
- package/dist/es/utils/utilityTypeSchemaMapper.js +412 -0
- package/dist/es/utils/utilityTypeSchemaMapper.js.map +1 -0
- package/dist/types/index.d.ts +20 -11
- package/dist/types/models/ITypeScriptToSchemaContext.d.ts +64 -0
- package/dist/types/models/ITypeScriptToSchemaDiagnostics.d.ts +31 -0
- package/dist/types/models/ITypeScriptToSchemaOptions.d.ts +22 -0
- package/dist/types/utils/constants.d.ts +13 -0
- package/dist/types/utils/diagnosticReporter.d.ts +17 -0
- package/dist/types/utils/disallowedTypeGuard.d.ts +16 -0
- package/dist/types/utils/enum.d.ts +42 -0
- package/dist/types/utils/fileUtils.d.ts +66 -0
- package/dist/types/utils/importTypeQuerySchemaResolver.d.ts +52 -0
- package/dist/types/utils/indexSignaturePatternResolver.d.ts +21 -0
- package/dist/types/utils/intersectionSchemaMerger.d.ts +16 -0
- package/dist/types/utils/jsDoc.d.ts +46 -0
- package/dist/types/utils/jsonSchemaBuilder.d.ts +747 -0
- package/dist/types/utils/mappedTypeSchemaResolver.d.ts +46 -0
- package/dist/types/utils/objectTransformer.d.ts +33 -0
- package/dist/types/utils/regEx.d.ts +24 -0
- package/dist/types/utils/resolver.d.ts +16 -0
- package/dist/types/utils/templateLiteralPatternBuilder.d.ts +12 -0
- package/dist/types/utils/typeScriptToSchema.d.ts +31 -0
- package/dist/types/utils/utilityTypeSchemaMapper.d.ts +92 -0
- package/docs/changelog.md +176 -1
- package/docs/examples.md +87 -1
- package/docs/reference/classes/Constants.md +29 -0
- package/docs/reference/classes/DiagnosticReporter.md +49 -0
- package/docs/reference/classes/DisallowedTypeGuard.md +35 -0
- package/docs/reference/classes/Enum.md +93 -0
- package/docs/reference/classes/FileUtils.md +237 -0
- package/docs/reference/classes/ImportTypeQuerySchemaResolver.md +87 -0
- package/docs/reference/classes/IndexSignaturePatternResolver.md +69 -0
- package/docs/reference/classes/IntersectionSchemaMerger.md +48 -0
- package/docs/reference/classes/JsDoc.md +141 -0
- package/docs/reference/classes/JsonSchemaBuilder.md +2870 -0
- package/docs/reference/classes/MappedTypeSchemaResolver.md +211 -0
- package/docs/reference/classes/ObjectTransformer.md +119 -0
- package/docs/reference/classes/RegEx.md +99 -0
- package/docs/reference/classes/Resolver.md +41 -0
- package/docs/reference/classes/TemplateLiteralPatternBuilder.md +35 -0
- package/docs/reference/classes/TypeScriptToSchema.md +91 -0
- package/docs/reference/classes/UtilityTypeSchemaMapper.md +341 -0
- package/docs/reference/index.md +20 -14
- package/docs/reference/interfaces/ITypeScriptToSchemaContext.md +113 -0
- package/docs/reference/interfaces/ITypeScriptToSchemaDiagnostics.md +55 -0
- package/docs/reference/interfaces/ITypeScriptToSchemaOptions.md +44 -0
- package/locales/en.json +32 -1
- package/package.json +4 -3
- package/dist/es/models/IJsonSchema.js +0 -2
- package/dist/es/models/IJsonSchema.js.map +0 -1
- package/dist/es/models/IOpenApi.js +0 -2
- package/dist/es/models/IOpenApi.js.map +0 -1
- package/dist/es/models/IOpenApiExample.js +0 -4
- package/dist/es/models/IOpenApiExample.js.map +0 -1
- package/dist/es/models/IOpenApiHeader.js +0 -4
- package/dist/es/models/IOpenApiHeader.js.map +0 -1
- package/dist/es/models/IOpenApiPathMethod.js +0 -2
- package/dist/es/models/IOpenApiPathMethod.js.map +0 -1
- package/dist/es/models/IOpenApiResponse.js +0 -2
- package/dist/es/models/IOpenApiResponse.js.map +0 -1
- package/dist/es/models/IOpenApiSecurityScheme.js +0 -4
- package/dist/es/models/IOpenApiSecurityScheme.js.map +0 -1
- package/dist/es/models/IPackageJson.js +0 -4
- package/dist/es/models/IPackageJson.js.map +0 -1
- package/dist/es/models/jsonTypeName.js +0 -2
- package/dist/es/models/jsonTypeName.js.map +0 -1
- package/dist/es/utils/jsonSchemaHelper.js +0 -258
- package/dist/es/utils/jsonSchemaHelper.js.map +0 -1
- package/dist/es/utils/openApiHelper.js +0 -12
- package/dist/es/utils/openApiHelper.js.map +0 -1
- package/dist/types/models/IJsonSchema.d.ts +0 -5
- package/dist/types/models/IOpenApi.d.ts +0 -54
- package/dist/types/models/IOpenApiExample.d.ts +0 -13
- package/dist/types/models/IOpenApiHeader.d.ts +0 -19
- package/dist/types/models/IOpenApiPathMethod.d.ts +0 -65
- package/dist/types/models/IOpenApiResponse.d.ts +0 -32
- package/dist/types/models/IOpenApiSecurityScheme.d.ts +0 -25
- package/dist/types/models/IPackageJson.d.ts +0 -15
- package/dist/types/models/jsonTypeName.d.ts +0 -5
- package/dist/types/utils/jsonSchemaHelper.d.ts +0 -78
- package/dist/types/utils/openApiHelper.d.ts +0 -9
- package/docs/reference/classes/JsonSchemaHelper.md +0 -233
- package/docs/reference/classes/OpenApiHelper.md +0 -21
- package/docs/reference/interfaces/IOpenApi.md +0 -103
- package/docs/reference/interfaces/IOpenApiExample.md +0 -19
- package/docs/reference/interfaces/IOpenApiHeader.md +0 -31
- package/docs/reference/interfaces/IOpenApiPathMethod.md +0 -119
- package/docs/reference/interfaces/IOpenApiResponse.md +0 -35
- package/docs/reference/interfaces/IOpenApiSecurityScheme.md +0 -43
- package/docs/reference/interfaces/IPackageJson.md +0 -23
- package/docs/reference/type-aliases/IJsonSchema.md +0 -5
- package/docs/reference/type-aliases/JsonTypeName.md +0 -5
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
import { type IJsonSchema } from "@twin.org/tools-models";
|
|
2
|
+
import * as ts from "typescript";
|
|
3
|
+
import type { ITypeScriptToSchemaContext } from "../models/ITypeScriptToSchemaContext.js";
|
|
4
|
+
/**
|
|
5
|
+
* Builder for composing JSON schema fragments from TypeScript AST nodes.
|
|
6
|
+
*/
|
|
7
|
+
export declare class JsonSchemaBuilder {
|
|
8
|
+
/**
|
|
9
|
+
* The JSON Schema version used.
|
|
10
|
+
*/
|
|
11
|
+
static readonly SCHEMA_VERSION = "https://json-schema.org/draft/2020-12/schema";
|
|
12
|
+
/**
|
|
13
|
+
* Runtime name for the class.
|
|
14
|
+
*/
|
|
15
|
+
static readonly CLASS_NAME: string;
|
|
16
|
+
/**
|
|
17
|
+
* Dictionary of TypeScript utility type names to their schema mapping handlers.
|
|
18
|
+
*/
|
|
19
|
+
private static readonly _utilityTypeHandlers;
|
|
20
|
+
/**
|
|
21
|
+
* Parse all object declarations from a source file.
|
|
22
|
+
* @param context The generation context.
|
|
23
|
+
* @param sourceFilePath The source file path.
|
|
24
|
+
* @param source The TypeScript source.
|
|
25
|
+
* @param visitedFiles The list of visited source files.
|
|
26
|
+
* @returns The generated schema titles.
|
|
27
|
+
*/
|
|
28
|
+
static parseAllObjectSchemas(context: ITypeScriptToSchemaContext, sourceFilePath: string, source: string, visitedFiles: string[]): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Apply @json-schema tags from JSDoc to a schema object.
|
|
31
|
+
* @param schema The schema to expand.
|
|
32
|
+
* @param node The node to inspect for tags.
|
|
33
|
+
* @throws GeneralError Thrown when a tag key is not supported by IJsonSchema.
|
|
34
|
+
*/
|
|
35
|
+
static applyJsonSchemaTags(schema: Partial<IJsonSchema>, node: ts.Node): void;
|
|
36
|
+
/**
|
|
37
|
+
* Validate that a @json-schema constraint key is compatible with the given schema type,
|
|
38
|
+
* and that the raw value is valid for the constraint.
|
|
39
|
+
* @param schemaKey The mapped schema key being applied.
|
|
40
|
+
* @param schemaType The type already set on the schema, if any.
|
|
41
|
+
* @param rawValue The raw string value from the JSDoc tag.
|
|
42
|
+
* @throws GeneralError Thrown when the constraint is not valid for the schema type.
|
|
43
|
+
* @throws GeneralError Thrown when the format value is not a recognised JSON Schema format.
|
|
44
|
+
*/
|
|
45
|
+
static validateJsonSchemaTagConstraint(schemaKey: string, schemaType: string | string[] | undefined, rawValue: string): void;
|
|
46
|
+
/**
|
|
47
|
+
* Determine whether a mapped @json-schema tag key is supported.
|
|
48
|
+
* @param key The mapped schema key.
|
|
49
|
+
* @returns True if the key is supported.
|
|
50
|
+
*/
|
|
51
|
+
static isAllowedJsonSchemaTagKey(key: string): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Build the base schema with common properties.
|
|
54
|
+
* @param namespace The namespace for generated schema id.
|
|
55
|
+
* @param title The schema title.
|
|
56
|
+
* @param statement The type statement node.
|
|
57
|
+
* @returns The base schema to be expanded.
|
|
58
|
+
*/
|
|
59
|
+
static buildBaseSchema(namespace: string, title: string, statement: ts.Node): Partial<IJsonSchema>;
|
|
60
|
+
/**
|
|
61
|
+
* Add enum information to a schema.
|
|
62
|
+
* @param schema The schema to expand.
|
|
63
|
+
* @param entries The enum entries.
|
|
64
|
+
*/
|
|
65
|
+
static buildEnumSchema(schema: Partial<IJsonSchema>, entries: {
|
|
66
|
+
value: string | number;
|
|
67
|
+
description?: string;
|
|
68
|
+
}[]): void;
|
|
69
|
+
/**
|
|
70
|
+
* Build an object schema from interface or type literal members.
|
|
71
|
+
* @param context The generation context.
|
|
72
|
+
* @param schema The schema to expand.
|
|
73
|
+
* @param members The members to process.
|
|
74
|
+
*/
|
|
75
|
+
static buildObjectSchema(context: ITypeScriptToSchemaContext, schema: Partial<IJsonSchema>, members: ts.NodeArray<ts.TypeElement>): void;
|
|
76
|
+
/**
|
|
77
|
+
* Build property schemas and required list from type members.
|
|
78
|
+
* @param context The generation context.
|
|
79
|
+
* @param members The members to process.
|
|
80
|
+
* @returns The object property schema map and required list.
|
|
81
|
+
*/
|
|
82
|
+
static buildObjectMembersSchema(context: ITypeScriptToSchemaContext, members: ts.NodeArray<ts.TypeElement>): {
|
|
83
|
+
properties: {
|
|
84
|
+
[key: string]: IJsonSchema;
|
|
85
|
+
};
|
|
86
|
+
required: string[];
|
|
87
|
+
patternProperties?: {
|
|
88
|
+
[pattern: string]: IJsonSchema;
|
|
89
|
+
};
|
|
90
|
+
additionalProperties?: IJsonSchema;
|
|
91
|
+
propertyNames?: IJsonSchema;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* Build an object schema from a type literal node.
|
|
95
|
+
* @param context The generation context.
|
|
96
|
+
* @param typeNode The type literal node.
|
|
97
|
+
* @returns The object schema.
|
|
98
|
+
*/
|
|
99
|
+
static buildTypeLiteralSchema(context: ITypeScriptToSchemaContext, typeNode: ts.TypeLiteralNode): IJsonSchema;
|
|
100
|
+
/**
|
|
101
|
+
* Merge pattern property schemas by pattern, deduplicating equivalent branches.
|
|
102
|
+
* @param patternPropertySchemas Pattern and schema entries to merge.
|
|
103
|
+
* @returns Merged patternProperties map.
|
|
104
|
+
*/
|
|
105
|
+
static mergePatternPropertySchemas(patternPropertySchemas: {
|
|
106
|
+
pattern: string;
|
|
107
|
+
schema: IJsonSchema;
|
|
108
|
+
}[]): {
|
|
109
|
+
[pattern: string]: IJsonSchema;
|
|
110
|
+
} | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Map a property type node to schema.
|
|
113
|
+
* @param context The generation context.
|
|
114
|
+
* @param typeNode The member type node.
|
|
115
|
+
* @returns The mapped member schema.
|
|
116
|
+
*/
|
|
117
|
+
static mapMemberTypeToSchema(context: ITypeScriptToSchemaContext, typeNode: ts.TypeNode): IJsonSchema | undefined;
|
|
118
|
+
/**
|
|
119
|
+
* Map TypeScript type nodes to JSON schema.
|
|
120
|
+
* @param context The generation context.
|
|
121
|
+
* @param typeNode The node to process.
|
|
122
|
+
* @returns The mapped schema.
|
|
123
|
+
*/
|
|
124
|
+
static mapTypeNodeToSchema(context: ITypeScriptToSchemaContext, typeNode: ts.TypeNode): IJsonSchema | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Determine whether a union of primitive keyword branches is pairwise disjoint.
|
|
127
|
+
* @param unionTypeNode The union node being mapped.
|
|
128
|
+
* @param unionTypeNodes The original union branch type nodes.
|
|
129
|
+
* @param unionSchemas The mapped union branch schemas.
|
|
130
|
+
* @returns True if every branch is a primitive keyword schema and no branches overlap.
|
|
131
|
+
*/
|
|
132
|
+
static isDisjointPrimitiveKeywordUnion(unionTypeNode: ts.UnionTypeNode, unionTypeNodes: ts.NodeArray<ts.TypeNode>, unionSchemas: IJsonSchema[]): boolean;
|
|
133
|
+
/**
|
|
134
|
+
* Determine whether a union of schemas represents mutually exclusive object branches.
|
|
135
|
+
* @param context The generation context.
|
|
136
|
+
* @param unionTypeNodes The union branch type nodes for cross-checking with the mapped schemas.
|
|
137
|
+
* @param unionSchemas The mapped union branch schemas.
|
|
138
|
+
* @returns True if each branch is an object schema with a unique required key set.
|
|
139
|
+
*/
|
|
140
|
+
static isNeverDiscriminatedObjectUnion(context: ITypeScriptToSchemaContext, unionTypeNodes: ts.NodeArray<ts.TypeNode>, unionSchemas: IJsonSchema[]): boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Determine whether object union branches are discriminated by a shared required literal tag.
|
|
143
|
+
* @param context The generation context.
|
|
144
|
+
* @param unionSchemas The mapped union branch schemas.
|
|
145
|
+
* @returns True if the union can be safely represented as oneOf.
|
|
146
|
+
*/
|
|
147
|
+
static isLiteralTagDiscriminatedObjectUnion(context: ITypeScriptToSchemaContext, unionSchemas: IJsonSchema[]): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Resolve branch members that can encode never-based discriminators.
|
|
150
|
+
* @param context The generation context.
|
|
151
|
+
* @param unionTypeNode The union branch type node.
|
|
152
|
+
* @returns Type members for the branch when resolvable.
|
|
153
|
+
*/
|
|
154
|
+
static resolveNeverDiscriminatorMembers(context: ITypeScriptToSchemaContext, unionTypeNode: ts.TypeNode): ts.NodeArray<ts.TypeElement> | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Resolve a local $ref schema to its stored schema definition.
|
|
157
|
+
* @param context The generation context.
|
|
158
|
+
* @param schema The schema that may contain a local reference.
|
|
159
|
+
* @returns The resolved schema when available.
|
|
160
|
+
*/
|
|
161
|
+
static resolveLocalSchemaReference(context: ITypeScriptToSchemaContext, schema: IJsonSchema): IJsonSchema | undefined;
|
|
162
|
+
/**
|
|
163
|
+
* Resolve a property value from a const object declaration in an imported source file.
|
|
164
|
+
* @param context The generation context.
|
|
165
|
+
* @param objectName The name of the const object.
|
|
166
|
+
* @param propertyName The name of the property to resolve.
|
|
167
|
+
* @returns The resolved string or number value, or undefined if unresolvable.
|
|
168
|
+
*/
|
|
169
|
+
static resolveConstObjectProperty(context: ITypeScriptToSchemaContext, objectName: string, propertyName: string): string | number | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* Find a variable declaration by traversing import and export chains.
|
|
172
|
+
* @param sourceFilePath The source file path to start from.
|
|
173
|
+
* @param variableName The variable declaration name to find.
|
|
174
|
+
* @param visitedFiles The file set already visited.
|
|
175
|
+
* @returns The variable declaration when found.
|
|
176
|
+
*/
|
|
177
|
+
static findVariableDeclarationInModuleGraph(sourceFilePath: string, variableName: string, visitedFiles: Set<string>): ts.VariableDeclaration | undefined;
|
|
178
|
+
/**
|
|
179
|
+
* Find an imported symbol reference by local identifier name.
|
|
180
|
+
* @param sourceFile The source file to inspect.
|
|
181
|
+
* @param localName The local identifier name.
|
|
182
|
+
* @returns The module specifier and imported symbol name.
|
|
183
|
+
*/
|
|
184
|
+
static findImportedValueReference(sourceFile: ts.SourceFile, localName: string): {
|
|
185
|
+
moduleSpecifier: string;
|
|
186
|
+
importedName: string;
|
|
187
|
+
} | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* Resolve an import declaration module specifier to a source file.
|
|
190
|
+
* @param containingSourceFilePath The containing source file path.
|
|
191
|
+
* @param moduleSpecifier The module specifier text.
|
|
192
|
+
* @returns The resolved source file path.
|
|
193
|
+
*/
|
|
194
|
+
static resolveImportDeclarationSourceFile(containingSourceFilePath: string, moduleSpecifier: string): string | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Extract a const-object property value from a declaration initializer.
|
|
197
|
+
* @param objectDeclaration The variable declaration.
|
|
198
|
+
* @param propertyName The property to resolve.
|
|
199
|
+
* @returns The resolved value.
|
|
200
|
+
*/
|
|
201
|
+
static extractConstObjectPropertyFromDeclarationInitializer(objectDeclaration: ts.VariableDeclaration, propertyName: string): string | number | undefined;
|
|
202
|
+
/**
|
|
203
|
+
* Extract a const-object property value from a declaration type annotation.
|
|
204
|
+
* @param declarationTypeNode The declaration type annotation.
|
|
205
|
+
* @param propertyName The property to resolve.
|
|
206
|
+
* @returns The resolved value.
|
|
207
|
+
*/
|
|
208
|
+
static extractConstObjectPropertyFromDeclarationType(declarationTypeNode: ts.TypeNode, propertyName: string): string | number | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* Extract a literal value from a type node when possible.
|
|
211
|
+
* @param typeNode The type node.
|
|
212
|
+
* @returns The literal value.
|
|
213
|
+
*/
|
|
214
|
+
static extractLiteralValueFromTypeNode(typeNode: ts.TypeNode): string | number | undefined;
|
|
215
|
+
/**
|
|
216
|
+
* Extract a referenced type name from an import type qualifier.
|
|
217
|
+
* @param qualifier The import type qualifier.
|
|
218
|
+
* @returns The resolved type name.
|
|
219
|
+
*/
|
|
220
|
+
static extractImportTypeName(qualifier: ts.EntityName | undefined): string | undefined;
|
|
221
|
+
/**
|
|
222
|
+
* Resolve import-type references to local or external schema ids.
|
|
223
|
+
* @param context The generation context.
|
|
224
|
+
* @param moduleSpecifier The import module specifier.
|
|
225
|
+
* @param typeName The imported type name.
|
|
226
|
+
* @param title The derived schema title.
|
|
227
|
+
* @returns The resolved schema id.
|
|
228
|
+
*/
|
|
229
|
+
static resolveImportTypeReferenceSchemaId(context: ITypeScriptToSchemaContext, moduleSpecifier: string, typeName: string, title: string): string | undefined;
|
|
230
|
+
/**
|
|
231
|
+
* Infer a primitive JSON schema from a literal expression.
|
|
232
|
+
* @param context The generation context.
|
|
233
|
+
* @param expr The expression to inspect.
|
|
234
|
+
* @param asConst Whether to produce exact const schemas matching an as-const assertion.
|
|
235
|
+
* @returns The inferred schema.
|
|
236
|
+
*/
|
|
237
|
+
static inferSchemaFromExpression(context: ITypeScriptToSchemaContext, expr: ts.Expression, asConst?: boolean): IJsonSchema;
|
|
238
|
+
/**
|
|
239
|
+
* Infer an object schema from an object literal expression, using const or widened types.
|
|
240
|
+
* @param context The generation context.
|
|
241
|
+
* @param expr The object literal expression.
|
|
242
|
+
* @param asConst Whether property value schemas should be exact const types.
|
|
243
|
+
* @returns The inferred object schema.
|
|
244
|
+
*/
|
|
245
|
+
static inferObjectLiteralSchema(context: ITypeScriptToSchemaContext, expr: ts.ObjectLiteralExpression, asConst: boolean): IJsonSchema;
|
|
246
|
+
/**
|
|
247
|
+
* Infer an array schema from an array literal expression.
|
|
248
|
+
* For as-const arrays a fixed-length tuple schema is produced; otherwise a plain array schema.
|
|
249
|
+
* @param context The generation context.
|
|
250
|
+
* @param expr The array literal expression.
|
|
251
|
+
* @param asConst Whether to produce a const-exact tuple schema.
|
|
252
|
+
* @returns The inferred array schema.
|
|
253
|
+
*/
|
|
254
|
+
static inferArrayLiteralSchema(context: ITypeScriptToSchemaContext, expr: ts.ArrayLiteralExpression, asConst: boolean): IJsonSchema;
|
|
255
|
+
/**
|
|
256
|
+
* Map conditional type nodes (e.g. T extends U ? X : Y) to schema.
|
|
257
|
+
* @param context The generation context.
|
|
258
|
+
* @param typeNode The conditional type node.
|
|
259
|
+
* @returns The mapped schema.
|
|
260
|
+
*/
|
|
261
|
+
static mapConditionalTypeToSchema(context: ITypeScriptToSchemaContext, typeNode: ts.ConditionalTypeNode): IJsonSchema | undefined;
|
|
262
|
+
/**
|
|
263
|
+
* Map indexed access type nodes (e.g. T["id"]) to schema.
|
|
264
|
+
* @param context The generation context.
|
|
265
|
+
* @param typeNode The indexed access type node.
|
|
266
|
+
* @returns The mapped schema.
|
|
267
|
+
*/
|
|
268
|
+
static mapIndexedAccessTypeToSchema(context: ITypeScriptToSchemaContext, typeNode: ts.IndexedAccessTypeNode): IJsonSchema | undefined;
|
|
269
|
+
/**
|
|
270
|
+
* Map template literal type nodes to string schemas.
|
|
271
|
+
* @param context The generation context.
|
|
272
|
+
* @param typeNode The template literal type node.
|
|
273
|
+
* @returns The mapped schema.
|
|
274
|
+
*/
|
|
275
|
+
static mapTemplateLiteralTypeToSchema(context: ITypeScriptToSchemaContext, typeNode: ts.TemplateLiteralTypeNode): IJsonSchema;
|
|
276
|
+
/**
|
|
277
|
+
* Map mapped type nodes to object schemas.
|
|
278
|
+
* @param context The generation context.
|
|
279
|
+
* @param typeNode The mapped type node.
|
|
280
|
+
* @returns The mapped schema.
|
|
281
|
+
*/
|
|
282
|
+
static mapMappedTypeToSchema(context: ITypeScriptToSchemaContext, typeNode: ts.MappedTypeNode): IJsonSchema | undefined;
|
|
283
|
+
/**
|
|
284
|
+
* Determine whether a mapped type value uses indexed access with the mapped key parameter.
|
|
285
|
+
* @param typeNode The mapped type node.
|
|
286
|
+
* @param mappedTypeParameterName The mapped type parameter name.
|
|
287
|
+
* @returns True if the value shape is based on source indexed access.
|
|
288
|
+
*/
|
|
289
|
+
static isMappedTypeIndexedValueByTypeParameter(typeNode: ts.MappedTypeNode, mappedTypeParameterName: string): boolean;
|
|
290
|
+
/**
|
|
291
|
+
* Check whether a type node is allowed for schema generation.
|
|
292
|
+
* @param context The generation context.
|
|
293
|
+
* @param typeNode The type node to inspect.
|
|
294
|
+
* @param propertyName The optional property name when the type is a property type.
|
|
295
|
+
* @param enclosingObjectName The optional enclosing object name when the type is a property type.
|
|
296
|
+
* @returns True when the type is allowed.
|
|
297
|
+
*/
|
|
298
|
+
static checkTypeNodeAllowed(context: ITypeScriptToSchemaContext, typeNode: ts.TypeNode, propertyName?: string, enclosingObjectName?: string): boolean;
|
|
299
|
+
/**
|
|
300
|
+
* Determine whether a property type should be treated as a function and skipped.
|
|
301
|
+
* @param typeNode The property type node.
|
|
302
|
+
* @returns True if the property type is function-like.
|
|
303
|
+
*/
|
|
304
|
+
static isFunctionPropertyType(typeNode: ts.TypeNode): boolean;
|
|
305
|
+
/**
|
|
306
|
+
* Determine whether a type node represents symbol or unique symbol.
|
|
307
|
+
* @param typeNode The type node to inspect.
|
|
308
|
+
* @returns True when the type is symbol or unique symbol.
|
|
309
|
+
*/
|
|
310
|
+
static isSymbolTypeNode(typeNode: ts.TypeNode): boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Determine whether a computed property expression references a symbol.
|
|
313
|
+
* Covers well-known symbols (Symbol.iterator, etc.) and const variables
|
|
314
|
+
* declared with a unique symbol type annotation.
|
|
315
|
+
* @param context The generation context.
|
|
316
|
+
* @param expression The computed property expression.
|
|
317
|
+
* @returns True when the key is symbol-based.
|
|
318
|
+
*/
|
|
319
|
+
static isSymbolKeyedComputedExpression(context: ITypeScriptToSchemaContext, expression: ts.Expression): boolean;
|
|
320
|
+
/**
|
|
321
|
+
* Extract a property name from TypeScript property syntax.
|
|
322
|
+
* Computed names are resolved when they evaluate to concrete literals.
|
|
323
|
+
* @param context The generation context.
|
|
324
|
+
* @param propertyName The property name node.
|
|
325
|
+
* @returns The normalized property name.
|
|
326
|
+
*/
|
|
327
|
+
static extractPropertyName(context: ITypeScriptToSchemaContext, propertyName: ts.PropertyName): string | undefined;
|
|
328
|
+
/**
|
|
329
|
+
* Find a variable declaration by name in a source file.
|
|
330
|
+
* @param sourceFile The source file to search.
|
|
331
|
+
* @param variableName The variable name.
|
|
332
|
+
* @returns The declaration if found.
|
|
333
|
+
*/
|
|
334
|
+
static findVariableDeclaration(sourceFile: ts.SourceFile | undefined, variableName: string): ts.VariableDeclaration | undefined;
|
|
335
|
+
/**
|
|
336
|
+
* Resolve a schema for an imported identifier used in a type query.
|
|
337
|
+
* @param context The generation context.
|
|
338
|
+
* @param localName The local imported symbol name.
|
|
339
|
+
* @returns The mapped schema if resolvable.
|
|
340
|
+
*/
|
|
341
|
+
static resolveImportedTypeQuerySchema(context: ITypeScriptToSchemaContext, localName: string): IJsonSchema | undefined;
|
|
342
|
+
/**
|
|
343
|
+
* Resolve computed property name expressions when they can be evaluated to concrete keys.
|
|
344
|
+
* @param context The generation context.
|
|
345
|
+
* @param expression The computed property expression.
|
|
346
|
+
* @param resolvingIdentifiers Identifier names currently being resolved.
|
|
347
|
+
* @returns The resolved property key.
|
|
348
|
+
*/
|
|
349
|
+
static resolveComputedPropertyNameExpression(context: ITypeScriptToSchemaContext, expression: ts.Expression, resolvingIdentifiers: Set<string>): string | undefined;
|
|
350
|
+
/**
|
|
351
|
+
* Find a local const variable declaration in the active source file.
|
|
352
|
+
* @param context The generation context.
|
|
353
|
+
* @param variableName The variable name.
|
|
354
|
+
* @returns The declaration when found.
|
|
355
|
+
*/
|
|
356
|
+
static findConstVariableDeclaration(context: ITypeScriptToSchemaContext, variableName: string): ts.VariableDeclaration | undefined;
|
|
357
|
+
/**
|
|
358
|
+
* Resolve a property value from a local const object declaration.
|
|
359
|
+
* @param context The generation context.
|
|
360
|
+
* @param objectName The const object name.
|
|
361
|
+
* @param propertyName The property to resolve.
|
|
362
|
+
* @returns The resolved value when available.
|
|
363
|
+
*/
|
|
364
|
+
static resolveLocalConstObjectProperty(context: ITypeScriptToSchemaContext, objectName: string, propertyName: string): string | number | undefined;
|
|
365
|
+
/**
|
|
366
|
+
* Map a tuple type node to schema.
|
|
367
|
+
* @param context The generation context.
|
|
368
|
+
* @param tupleTypeNode The tuple type node.
|
|
369
|
+
* @returns The mapped tuple schema.
|
|
370
|
+
*/
|
|
371
|
+
static mapTupleTypeToSchema(context: ITypeScriptToSchemaContext, tupleTypeNode: ts.TupleTypeNode): IJsonSchema | undefined;
|
|
372
|
+
/**
|
|
373
|
+
* Extract schema for a tuple rest element.
|
|
374
|
+
* @param context The generation context.
|
|
375
|
+
* @param restElementType The rest element type.
|
|
376
|
+
* @returns The mapped rest element schema.
|
|
377
|
+
*/
|
|
378
|
+
static extractRestElementSchema(context: ITypeScriptToSchemaContext, restElementType: ts.TypeNode): IJsonSchema | undefined;
|
|
379
|
+
/**
|
|
380
|
+
* Find an existing schema id by title in known package schemas.
|
|
381
|
+
* @param context The generation context.
|
|
382
|
+
* @param schemaTitle The schema title to find.
|
|
383
|
+
* @returns The existing schema id if found.
|
|
384
|
+
*/
|
|
385
|
+
static findExistingSchemaIdByTitle(context: ITypeScriptToSchemaContext, schemaTitle: string): string | undefined;
|
|
386
|
+
/**
|
|
387
|
+
* Apply interface inheritance (`extends`) as `allOf` references.
|
|
388
|
+
* @param context The generation context.
|
|
389
|
+
* @param schema The schema to expand.
|
|
390
|
+
* @param declaration The interface declaration.
|
|
391
|
+
*/
|
|
392
|
+
static applyInterfaceExtendsSchema(context: ITypeScriptToSchemaContext, schema: Partial<IJsonSchema>, declaration: ts.InterfaceDeclaration): void;
|
|
393
|
+
/**
|
|
394
|
+
* Map Partial<T> to an object schema with no required properties.
|
|
395
|
+
* @param context The generation context.
|
|
396
|
+
* @param typeNode The Partial type reference.
|
|
397
|
+
* @returns The mapped schema.
|
|
398
|
+
*/
|
|
399
|
+
static mapPartialUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): IJsonSchema | undefined;
|
|
400
|
+
/**
|
|
401
|
+
* Map Required<T> to an object schema with all properties required.
|
|
402
|
+
* @param context The generation context.
|
|
403
|
+
* @param typeNode The Required type reference.
|
|
404
|
+
* @returns The mapped schema.
|
|
405
|
+
*/
|
|
406
|
+
static mapRequiredUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): IJsonSchema | undefined;
|
|
407
|
+
/**
|
|
408
|
+
* Map Pick<T, K> to an object schema with selected keys preserved.
|
|
409
|
+
* @param context The generation context.
|
|
410
|
+
* @param typeNode The Pick type reference.
|
|
411
|
+
* @returns The mapped schema.
|
|
412
|
+
*/
|
|
413
|
+
static mapPickUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): IJsonSchema | undefined;
|
|
414
|
+
/**
|
|
415
|
+
* Map Omit<T, K> to an object schema with selected keys removed.
|
|
416
|
+
* @param context The generation context.
|
|
417
|
+
* @param typeNode The Omit type reference.
|
|
418
|
+
* @returns The mapped schema.
|
|
419
|
+
*/
|
|
420
|
+
static mapOmitUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): IJsonSchema | undefined;
|
|
421
|
+
/**
|
|
422
|
+
* Map Exclude<T, U> to a schema that removes U members from T.
|
|
423
|
+
* @param context The generation context.
|
|
424
|
+
* @param typeNode The Exclude type reference.
|
|
425
|
+
* @returns The mapped schema.
|
|
426
|
+
*/
|
|
427
|
+
static mapExcludeUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): IJsonSchema | undefined;
|
|
428
|
+
/**
|
|
429
|
+
* Map Extract<T, U> to a schema that keeps U members from T.
|
|
430
|
+
* @param context The generation context.
|
|
431
|
+
* @param typeNode The Extract type reference.
|
|
432
|
+
* @returns The mapped schema.
|
|
433
|
+
*/
|
|
434
|
+
static mapExtractUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): IJsonSchema | undefined;
|
|
435
|
+
/**
|
|
436
|
+
* Map NonNullable<T> by removing null and undefined branches from T.
|
|
437
|
+
* @param context The generation context.
|
|
438
|
+
* @param typeNode The NonNullable type reference.
|
|
439
|
+
* @returns The mapped schema.
|
|
440
|
+
*/
|
|
441
|
+
static mapNonNullableUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): IJsonSchema | undefined;
|
|
442
|
+
/**
|
|
443
|
+
* Map Record<K, V> to an object schema with key constraints where possible.
|
|
444
|
+
* @param context The generation context.
|
|
445
|
+
* @param typeNode The Record type reference.
|
|
446
|
+
* @returns The mapped schema.
|
|
447
|
+
*/
|
|
448
|
+
static mapRecordUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): IJsonSchema | undefined;
|
|
449
|
+
/**
|
|
450
|
+
* Determine whether a type node represents null or undefined.
|
|
451
|
+
* @param typeNode The type node.
|
|
452
|
+
* @returns True if the node is null or undefined.
|
|
453
|
+
*/
|
|
454
|
+
static isNullOrUndefinedTypeNode(typeNode: ts.TypeNode): boolean;
|
|
455
|
+
/**
|
|
456
|
+
* Extract literal keys from a Record key type argument.
|
|
457
|
+
* @param keyTypeNode The key type argument node.
|
|
458
|
+
* @returns The extracted literal keys.
|
|
459
|
+
*/
|
|
460
|
+
static extractRecordLiteralKeys(keyTypeNode: ts.TypeNode): string[];
|
|
461
|
+
/**
|
|
462
|
+
* Map JsonLdObject utility types using key-removal and optional key-addition rules.
|
|
463
|
+
* @param context The generation context.
|
|
464
|
+
* @param typeNode The JsonLdObject utility type reference.
|
|
465
|
+
* @param options Mapping options.
|
|
466
|
+
* @param options.keysToRemove Keys to remove from the base schema.
|
|
467
|
+
* @param options.keyToAdd Optional key to add to the base schema.
|
|
468
|
+
* @param options.isAddedKeyRequired Whether the added key should be required.
|
|
469
|
+
* @returns The mapped schema.
|
|
470
|
+
*/
|
|
471
|
+
static mapJsonLdObjectUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode, options: {
|
|
472
|
+
keysToRemove: string[];
|
|
473
|
+
keyToAdd?: "id" | "@id" | "type" | "@type" | "@context";
|
|
474
|
+
isAddedKeyRequired?: boolean;
|
|
475
|
+
}): IJsonSchema | undefined;
|
|
476
|
+
/**
|
|
477
|
+
* Resolve a default schema for JsonLdObject utility key additions when the type argument is omitted.
|
|
478
|
+
* @param baseSchema The base object schema.
|
|
479
|
+
* @param keyToAdd The key being added by the utility.
|
|
480
|
+
* @returns The resolved schema.
|
|
481
|
+
*/
|
|
482
|
+
static mapJsonLdObjectDefaultSchemaByKey(baseSchema: IJsonSchema, keyToAdd: "id" | "@id" | "type" | "@type" | "@context"): IJsonSchema;
|
|
483
|
+
/**
|
|
484
|
+
* Resolve default id schema for JsonLdObjectWithId when Id type argument is omitted.
|
|
485
|
+
* @param baseSchema The base object schema.
|
|
486
|
+
* @returns The resolved id schema.
|
|
487
|
+
*/
|
|
488
|
+
static mapJsonLdObjectWithIdDefaultIdSchema(baseSchema: IJsonSchema): IJsonSchema;
|
|
489
|
+
/**
|
|
490
|
+
* Resolve default type schema for JsonLdObjectWithType when Type argument is omitted.
|
|
491
|
+
* @param baseSchema The base object schema.
|
|
492
|
+
* @returns The resolved type schema.
|
|
493
|
+
*/
|
|
494
|
+
static mapJsonLdObjectWithTypeDefaultTypeSchema(baseSchema: IJsonSchema): IJsonSchema;
|
|
495
|
+
/**
|
|
496
|
+
* Resolve default context schema for JsonLdObjectWithContext when Context argument is omitted.
|
|
497
|
+
* @param baseSchema The base object schema.
|
|
498
|
+
* @returns The resolved context schema.
|
|
499
|
+
*/
|
|
500
|
+
static mapJsonLdObjectWithContextDefaultContextSchema(baseSchema: IJsonSchema): IJsonSchema;
|
|
501
|
+
/**
|
|
502
|
+
* Resolve default schema from either of two source keys, with fallback when both are absent.
|
|
503
|
+
* @param baseSchema The base object schema.
|
|
504
|
+
* @param firstKey The primary key to resolve.
|
|
505
|
+
* @param secondKey The secondary key to resolve.
|
|
506
|
+
* @param fallbackSchema The fallback schema.
|
|
507
|
+
* @returns The resolved schema.
|
|
508
|
+
*/
|
|
509
|
+
static mapJsonLdObjectDefaultEitherSchema(baseSchema: IJsonSchema, firstKey: string, secondKey: string, fallbackSchema: IJsonSchema): IJsonSchema;
|
|
510
|
+
/**
|
|
511
|
+
* Map ObjectOrArray<T> to a schema accepting T or T[].
|
|
512
|
+
* @param context The generation context.
|
|
513
|
+
* @param typeNode The ObjectOrArray type reference.
|
|
514
|
+
* @returns The mapped schema.
|
|
515
|
+
*/
|
|
516
|
+
static mapObjectOrArrayUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): IJsonSchema | undefined;
|
|
517
|
+
/**
|
|
518
|
+
* Map SingleOccurrenceArray<T, U> to a non-empty array containing exactly one U.
|
|
519
|
+
* @param context The generation context.
|
|
520
|
+
* @param typeNode The SingleOccurrenceArray type reference.
|
|
521
|
+
* @returns The mapped schema.
|
|
522
|
+
*/
|
|
523
|
+
static mapSingleOccurrenceArrayUtilityType(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): IJsonSchema | undefined;
|
|
524
|
+
/**
|
|
525
|
+
* Add a comment to schemas inlined for utility type transformations.
|
|
526
|
+
* @param schema The schema to annotate.
|
|
527
|
+
* @param baseTypeDescription The utility base type description.
|
|
528
|
+
* @returns The annotated schema.
|
|
529
|
+
*/
|
|
530
|
+
static annotateUtilityInlineSchema(schema: IJsonSchema, baseTypeDescription: string): IJsonSchema;
|
|
531
|
+
/**
|
|
532
|
+
* Resolve a utility base type node to an object schema.
|
|
533
|
+
* @param context The generation context.
|
|
534
|
+
* @param baseTypeNode The utility base type node.
|
|
535
|
+
* @returns The resolved object schema.
|
|
536
|
+
* @throws GeneralError when a named type reference cannot be resolved to a schema.
|
|
537
|
+
*/
|
|
538
|
+
static resolveUtilityBaseObjectSchema(context: ITypeScriptToSchemaContext, baseTypeNode: ts.TypeNode): IJsonSchema | undefined;
|
|
539
|
+
/**
|
|
540
|
+
* Resolve a mapped utility schema to an object schema when possible.
|
|
541
|
+
* @param context The generation context.
|
|
542
|
+
* @param mappedSchema The mapped schema.
|
|
543
|
+
* @returns The resolved object schema.
|
|
544
|
+
*/
|
|
545
|
+
static resolveMappedUtilityBaseObjectSchema(context: ITypeScriptToSchemaContext, mappedSchema: IJsonSchema): IJsonSchema | undefined;
|
|
546
|
+
/**
|
|
547
|
+
* Expand allOf references in a schema by inlining referenced schemas.
|
|
548
|
+
* This handles inheritance cases where a type extends another type.
|
|
549
|
+
* When applying utility operations (Omit, Pick) to types with allOf inheritance,
|
|
550
|
+
* the referenced schemas must be expanded so properties are available for omit/pick.
|
|
551
|
+
* @param context The generation context.
|
|
552
|
+
* @param schema The schema potentially containing allOf with references.
|
|
553
|
+
* @param currentSchemaTitle The title of the current schema being processed, used for $comment annotations.
|
|
554
|
+
* @returns The schema with expanded references merged into properties.
|
|
555
|
+
*/
|
|
556
|
+
static expandAllOfReferences(context: ITypeScriptToSchemaContext, schema: IJsonSchema, currentSchemaTitle?: string): IJsonSchema;
|
|
557
|
+
/**
|
|
558
|
+
* Attempt to load an external schema by title from imported module declarations.
|
|
559
|
+
* @param context The generation context.
|
|
560
|
+
* @param schemaTitle The schema title.
|
|
561
|
+
* @returns The loaded schema.
|
|
562
|
+
*/
|
|
563
|
+
static tryLoadExternalSchemaByTitle(context: ITypeScriptToSchemaContext, schemaTitle: string): IJsonSchema | undefined;
|
|
564
|
+
/**
|
|
565
|
+
* Resolve an object schema for utility type application.
|
|
566
|
+
* @param context The generation context.
|
|
567
|
+
* @param typeName The referenced type name.
|
|
568
|
+
* @returns The resolved object schema.
|
|
569
|
+
*/
|
|
570
|
+
static resolveObjectTypeSchemaForUtility(context: ITypeScriptToSchemaContext, typeName: string): IJsonSchema | undefined;
|
|
571
|
+
/**
|
|
572
|
+
* Find an imported type reference from the active source file by local or exported symbol name.
|
|
573
|
+
* @param context The generation context.
|
|
574
|
+
* @param typeName The local or exported type name to find.
|
|
575
|
+
* @returns The module specifier and exported candidate type name when found.
|
|
576
|
+
*/
|
|
577
|
+
static findImportedTypeReference(context: ITypeScriptToSchemaContext, typeName: string): {
|
|
578
|
+
moduleSpecifier: string;
|
|
579
|
+
candidateTypeName: string;
|
|
580
|
+
} | undefined;
|
|
581
|
+
/**
|
|
582
|
+
* Resolve an imported object schema for utility type application.
|
|
583
|
+
* @param context The generation context.
|
|
584
|
+
* @param moduleSpecifier The module where the type is imported from.
|
|
585
|
+
* @param candidateTypeName The exported candidate type name.
|
|
586
|
+
* @param title The stripped title of the requested type.
|
|
587
|
+
* @returns The resolved object schema.
|
|
588
|
+
*/
|
|
589
|
+
static resolveImportedObjectTypeSchemaForUtility(context: ITypeScriptToSchemaContext, moduleSpecifier: string, candidateTypeName: string, title: string): IJsonSchema | undefined;
|
|
590
|
+
/**
|
|
591
|
+
* Map a local interface or type alias declaration to an object schema.
|
|
592
|
+
* @param context The generation context.
|
|
593
|
+
* @param typeName The referenced type name.
|
|
594
|
+
* @returns The mapped schema.
|
|
595
|
+
*/
|
|
596
|
+
static mapObjectTypeFromLocalDeclaration(context: ITypeScriptToSchemaContext, typeName: string): IJsonSchema | undefined;
|
|
597
|
+
/**
|
|
598
|
+
* Extract string literal keys from a utility type key argument (e.g. Pick or Omit).
|
|
599
|
+
* @param context The generation context.
|
|
600
|
+
* @param keysTypeNode The keys type node.
|
|
601
|
+
* @returns The extracted keys.
|
|
602
|
+
*/
|
|
603
|
+
static extractUtilityTypeKeys(context: ITypeScriptToSchemaContext, keysTypeNode: ts.TypeNode | undefined): string[];
|
|
604
|
+
/**
|
|
605
|
+
* Extract property keys from an indexed access index type.
|
|
606
|
+
* @param context The generation context.
|
|
607
|
+
* @param indexTypeNode The index type node.
|
|
608
|
+
* @returns The extracted keys.
|
|
609
|
+
*/
|
|
610
|
+
static extractIndexedAccessKeys(context: ITypeScriptToSchemaContext, indexTypeNode: ts.TypeNode): string[];
|
|
611
|
+
/**
|
|
612
|
+
* Extract keys for a mapped type constraint.
|
|
613
|
+
* @param context The generation context.
|
|
614
|
+
* @param constraintTypeNode The mapped type constraint.
|
|
615
|
+
* @returns The extracted keys.
|
|
616
|
+
*/
|
|
617
|
+
static extractMappedTypeKeys(context: ITypeScriptToSchemaContext, constraintTypeNode: ts.TypeNode | undefined): string[];
|
|
618
|
+
/**
|
|
619
|
+
* Resolve a referenced type node from a local type alias declaration.
|
|
620
|
+
* @param context The generation context.
|
|
621
|
+
* @param typeNode The type reference node.
|
|
622
|
+
* @returns The referenced type node, if found locally.
|
|
623
|
+
*/
|
|
624
|
+
static resolveReferencedTypeNodeFromLocalDeclaration(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode): ts.TypeNode | undefined;
|
|
625
|
+
/**
|
|
626
|
+
* Create a nested mapping context with generic parameters bound.
|
|
627
|
+
* @param context The current generation context.
|
|
628
|
+
* @param typeParameters The generic type parameters for the declaration.
|
|
629
|
+
* @param typeArguments Explicit type arguments, when provided.
|
|
630
|
+
* @returns The scoped mapping context.
|
|
631
|
+
*/
|
|
632
|
+
static withTypeParameterBindings(context: ITypeScriptToSchemaContext, typeParameters: ts.NodeArray<ts.TypeParameterDeclaration> | undefined, typeArguments?: ts.NodeArray<ts.TypeNode>): ITypeScriptToSchemaContext;
|
|
633
|
+
/**
|
|
634
|
+
* Get a bound generic type parameter for the current mapping scope.
|
|
635
|
+
* @param context The current generation context.
|
|
636
|
+
* @param typeName The type name to resolve.
|
|
637
|
+
* @returns The bound type node, null for unresolved generic parameters, or undefined when not generic.
|
|
638
|
+
*/
|
|
639
|
+
static getTypeParameterBinding(context: ITypeScriptToSchemaContext, typeName: string): ts.TypeNode | null | undefined;
|
|
640
|
+
/**
|
|
641
|
+
* Determine whether a mapped type is a homomorphic source-preserving form.
|
|
642
|
+
* @param typeNode The mapped type node.
|
|
643
|
+
* @returns True if the mapped type mirrors an existing object shape.
|
|
644
|
+
*/
|
|
645
|
+
static isHomomorphicMappedType(typeNode: ts.MappedTypeNode): boolean;
|
|
646
|
+
/**
|
|
647
|
+
* Resolve a source object schema for a mapped type when one exists.
|
|
648
|
+
* @param context The generation context.
|
|
649
|
+
* @param typeNode The mapped type node.
|
|
650
|
+
* @returns The resolved source object schema.
|
|
651
|
+
*/
|
|
652
|
+
static resolveMappedTypeSourceObjectSchema(context: ITypeScriptToSchemaContext, typeNode: ts.MappedTypeNode): IJsonSchema | undefined;
|
|
653
|
+
/**
|
|
654
|
+
* Map a single mapped-type property schema.
|
|
655
|
+
* @param context The generation context.
|
|
656
|
+
* @param typeNode The mapped type node.
|
|
657
|
+
* @param sourcePropertyKey The original property key from the source object, used for lookup when the mapped type is homomorphic.
|
|
658
|
+
* @param mappedTypeParameterName The mapped type parameter name.
|
|
659
|
+
* @param sourceObjectSchema The optional source object schema.
|
|
660
|
+
* @returns The mapped property schema.
|
|
661
|
+
*/
|
|
662
|
+
static mapMappedTypePropertySchema(context: ITypeScriptToSchemaContext, typeNode: ts.MappedTypeNode, sourcePropertyKey: string, mappedTypeParameterName: string, sourceObjectSchema?: IJsonSchema): IJsonSchema | undefined;
|
|
663
|
+
/**
|
|
664
|
+
* Resolve a concrete property schema for an indexed access object type and key.
|
|
665
|
+
* @param context The generation context.
|
|
666
|
+
* @param objectTypeNode The source object type node.
|
|
667
|
+
* @param propertyKey The property key to resolve.
|
|
668
|
+
* @param sourceObjectSchema The optional pre-resolved source object schema.
|
|
669
|
+
* @returns The resolved property schema.
|
|
670
|
+
*/
|
|
671
|
+
static resolveIndexedPropertySchema(context: ITypeScriptToSchemaContext, objectTypeNode: ts.TypeNode, propertyKey: string, sourceObjectSchema?: IJsonSchema): IJsonSchema | undefined;
|
|
672
|
+
/**
|
|
673
|
+
* Determine whether a type node is a reference to the mapped type parameter.
|
|
674
|
+
* @param typeNode The type node.
|
|
675
|
+
* @param mappedTypeParameterName The mapped type parameter name.
|
|
676
|
+
* @returns True if the node references the mapped parameter.
|
|
677
|
+
*/
|
|
678
|
+
static isMappedTypeParameterReference(typeNode: ts.TypeNode, mappedTypeParameterName: string): boolean;
|
|
679
|
+
/**
|
|
680
|
+
* Apply mapped-type optionality to a schema cloned from a source object.
|
|
681
|
+
* @param schema The mapped schema.
|
|
682
|
+
* @param optionalToken The mapped type optional token.
|
|
683
|
+
*/
|
|
684
|
+
static applyMappedTypeOptionality(schema: IJsonSchema, optionalToken: ts.QuestionToken | ts.PlusToken | ts.MinusToken | undefined): void;
|
|
685
|
+
/**
|
|
686
|
+
* Apply mapped-type required keys for generated property sets.
|
|
687
|
+
* @param schema The mapped schema.
|
|
688
|
+
* @param propertyKeys The generated property keys.
|
|
689
|
+
* @param optionalToken The mapped type optional token.
|
|
690
|
+
*/
|
|
691
|
+
static applyMappedTypeRequiredKeys(schema: IJsonSchema, propertyKeys: string[], optionalToken: ts.QuestionToken | ts.PlusToken | ts.MinusToken | undefined): void;
|
|
692
|
+
/**
|
|
693
|
+
* Extract key names from a keyof operand where possible.
|
|
694
|
+
* @param context The generation context.
|
|
695
|
+
* @param keysOperandNode The operand used with keyof.
|
|
696
|
+
* @returns The extracted keys.
|
|
697
|
+
*/
|
|
698
|
+
static extractKeyofTypeKeys(context: ITypeScriptToSchemaContext, keysOperandNode: ts.TypeNode): string[];
|
|
699
|
+
/**
|
|
700
|
+
* Determine whether a keyof operand is a generic type parameter reference.
|
|
701
|
+
* @param context The generation context.
|
|
702
|
+
* @param keysOperandNode The operand used with keyof.
|
|
703
|
+
* @returns True if the operand is a generic parameter.
|
|
704
|
+
*/
|
|
705
|
+
static isGenericKeyofOperand(context: ITypeScriptToSchemaContext, keysOperandNode: ts.TypeNode): boolean;
|
|
706
|
+
/**
|
|
707
|
+
* Resolve a schema id for an external imported type reference.
|
|
708
|
+
* @param context The generation context.
|
|
709
|
+
* @param typeNode The type reference node.
|
|
710
|
+
* @param typeName The referenced type name.
|
|
711
|
+
* @returns The resolved schema id.
|
|
712
|
+
*/
|
|
713
|
+
static resolveExternalTypeReferenceSchemaId(context: ITypeScriptToSchemaContext, typeNode: ts.TypeReferenceNode, typeName: string): string | undefined;
|
|
714
|
+
/**
|
|
715
|
+
* Resolve a mapped schema target for an imported reference.
|
|
716
|
+
* @param context The generation context.
|
|
717
|
+
* @param packageName The referenced package or module specifier.
|
|
718
|
+
* @param typeName The imported type name.
|
|
719
|
+
* @returns The mapped schema id and optional namespace if one matches.
|
|
720
|
+
*/
|
|
721
|
+
static resolveReferenceMappingTarget(context: ITypeScriptToSchemaContext, packageName: string, typeName: string): {
|
|
722
|
+
schemaId: string;
|
|
723
|
+
namespace?: string;
|
|
724
|
+
} | undefined;
|
|
725
|
+
/**
|
|
726
|
+
* Find a module specifier for a referenced type in the active source file imports.
|
|
727
|
+
* @param sourceFile The active source file.
|
|
728
|
+
* @param typeNode The referenced type node.
|
|
729
|
+
* @param typeName The referenced type name.
|
|
730
|
+
* @returns The module specifier.
|
|
731
|
+
*/
|
|
732
|
+
static findImportedModuleSpecifier(sourceFile: ts.SourceFile, typeNode: ts.TypeReferenceNode, typeName: string): string | undefined;
|
|
733
|
+
/**
|
|
734
|
+
* Map custom tag key names to JSON schema property names.
|
|
735
|
+
* @param key The raw tag key.
|
|
736
|
+
* @returns The schema key.
|
|
737
|
+
*/
|
|
738
|
+
static mapJsonSchemaTagKey(key: string): string;
|
|
739
|
+
/**
|
|
740
|
+
* Extract the inner type node from a named or rest tuple element.
|
|
741
|
+
* Named tuple members and rest elements both wrap an inner type node; this unwraps them.
|
|
742
|
+
* Plain type nodes are returned as-is.
|
|
743
|
+
* @param element The tuple element.
|
|
744
|
+
* @returns The inner type node.
|
|
745
|
+
*/
|
|
746
|
+
static extractTupleElementType(element: ts.TypeNode): ts.TypeNode | undefined;
|
|
747
|
+
}
|