Class: JsonSchemaBuilder
Builder for composing JSON schema fragments from TypeScript AST nodes.
Constructors
Constructor
new JsonSchemaBuilder():
JsonSchemaBuilder
Returns
JsonSchemaBuilder
Properties
SCHEMA_VERSION
readonlystaticSCHEMA_VERSION:"https://json-schema.org/draft/2020-12/schema"="https://json-schema.org/draft/2020-12/schema"
The JSON Schema version used.
CLASS_NAME
readonlystaticCLASS_NAME:string
Runtime name for the class.
Methods
parseAllObjectSchemas()
staticparseAllObjectSchemas(context,sourceFilePath,source,visitedFiles):string[]
Parse all object declarations from a source file.
Parameters
context
The generation context.
sourceFilePath
string
The source file path.
source
string
The TypeScript source.
visitedFiles
string[]
The list of visited source files.
Returns
string[]
The generated schema titles.
applyJsonSchemaTags()
staticapplyJsonSchemaTags(schema,node):void
Apply
Parameters
schema
Partial<IJsonSchema>
The schema to expand.
node
Node
The node to inspect for tags.
Returns
void
Throws
GeneralError Thrown when a tag key is not supported by IJsonSchema.
validateJsonSchemaTagConstraint()
staticvalidateJsonSchemaTagConstraint(schemaKey,schemaType,rawValue):void
Validate that a
Parameters
schemaKey
string
The mapped schema key being applied.
schemaType
string | string[] | undefined
The type already set on the schema, if any.
rawValue
string
The raw string value from the JSDoc tag.
Returns
void
Throws
GeneralError Thrown when the constraint is not valid for the schema type.
Throws
GeneralError Thrown when the format value is not a recognised JSON Schema format.
isAllowedJsonSchemaTagKey()
staticisAllowedJsonSchemaTagKey(key):boolean
Determine whether a mapped
Parameters
key
string
The mapped schema key.
Returns
boolean
True if the key is supported.
buildBaseSchema()
staticbuildBaseSchema(namespace,title,statement):Partial<IJsonSchema>
Build the base schema with common properties.
Parameters
namespace
string
The namespace for generated schema id.
title
string
The schema title.
statement
Node
The type statement node.
Returns
Partial<IJsonSchema>
The base schema to be expanded.
buildEnumSchema()
staticbuildEnumSchema(schema,entries):void
Add enum information to a schema.
Parameters
schema
Partial<IJsonSchema>
The schema to expand.
entries
object[]
The enum entries.
Returns
void
buildObjectSchema()
staticbuildObjectSchema(context,schema,members):void
Build an object schema from interface or type literal members.
Parameters
context
The generation context.
schema
Partial<IJsonSchema>
The schema to expand.
members
NodeArray<TypeElement>
The members to process.
Returns
void
buildObjectMembersSchema()
staticbuildObjectMembersSchema(context,members):object
Build property schemas and required list from type members.
Parameters
context
The generation context.
members
NodeArray<TypeElement>
The members to process.
Returns
object
The object property schema map and required list.
properties
properties:
object
Index Signature
[key: string]: IJsonSchema
required
required:
string[]
patternProperties?
optionalpatternProperties?:object
Index Signature
[pattern: string]: IJsonSchema
additionalProperties?
optionaladditionalProperties?:IJsonSchema
propertyNames?
optionalpropertyNames?:IJsonSchema
buildTypeLiteralSchema()
staticbuildTypeLiteralSchema(context,typeNode):IJsonSchema
Build an object schema from a type literal node.
Parameters
context
The generation context.
typeNode
TypeLiteralNode
The type literal node.
Returns
IJsonSchema
The object schema.
mergePatternPropertySchemas()
staticmergePatternPropertySchemas(patternPropertySchemas): {[pattern:string]:IJsonSchema; } |undefined
Merge pattern property schemas by pattern, deduplicating equivalent branches.
Parameters
patternPropertySchemas
object[]
Pattern and schema entries to merge.
Returns
{[pattern: string]: IJsonSchema; } | undefined
Merged patternProperties map.
mapMemberTypeToSchema()
staticmapMemberTypeToSchema(context,typeNode):IJsonSchema|undefined
Map a property type node to schema.
Parameters
context
The generation context.
typeNode
TypeNode
The member type node.
Returns
IJsonSchema | undefined
The mapped member schema.
mapTypeNodeToSchema()
staticmapTypeNodeToSchema(context,typeNode):IJsonSchema|undefined
Map TypeScript type nodes to JSON schema.
Parameters
context
The generation context.
typeNode
TypeNode
The node to process.
Returns
IJsonSchema | undefined
The mapped schema.
isDisjointPrimitiveKeywordUnion()
staticisDisjointPrimitiveKeywordUnion(unionTypeNode,unionTypeNodes,unionSchemas):boolean
Determine whether a union of primitive keyword branches is pairwise disjoint.
Parameters
unionTypeNode
UnionTypeNode
The union node being mapped.
unionTypeNodes
NodeArray<TypeNode>
The original union branch type nodes.
unionSchemas
IJsonSchema[]
The mapped union branch schemas.
Returns
boolean
True if every branch is a primitive keyword schema and no branches overlap.
isNeverDiscriminatedObjectUnion()
staticisNeverDiscriminatedObjectUnion(context,unionTypeNodes,unionSchemas):boolean
Determine whether a union of schemas represents mutually exclusive object branches.
Parameters
context
The generation context.
unionTypeNodes
NodeArray<TypeNode>
The union branch type nodes for cross-checking with the mapped schemas.
unionSchemas
IJsonSchema[]
The mapped union branch schemas.
Returns
boolean
True if each branch is an object schema with a unique required key set.
isLiteralTagDiscriminatedObjectUnion()
staticisLiteralTagDiscriminatedObjectUnion(context,unionSchemas):boolean
Determine whether object union branches are discriminated by a shared required literal tag.
Parameters
context
The generation context.
unionSchemas
IJsonSchema[]
The mapped union branch schemas.
Returns
boolean
True if the union can be safely represented as oneOf.
resolveNeverDiscriminatorMembers()
staticresolveNeverDiscriminatorMembers(context,unionTypeNode):NodeArray<TypeElement> |undefined
Resolve branch members that can encode never-based discriminators.
Parameters
context
The generation context.
unionTypeNode
TypeNode
The union branch type node.
Returns
NodeArray<TypeElement> | undefined
Type members for the branch when resolvable.
resolveLocalSchemaReference()
staticresolveLocalSchemaReference(context,schema):IJsonSchema|undefined
Resolve a local $ref schema to its stored schema definition.
Parameters
context
The generation context.
schema
IJsonSchema
The schema that may contain a local reference.
Returns
IJsonSchema | undefined
The resolved schema when available.
resolveConstObjectProperty()
staticresolveConstObjectProperty(context,objectName,propertyName):string|number|undefined
Resolve a property value from a const object declaration in an imported source file.
Parameters
context
The generation context.
objectName
string
The name of the const object.
propertyName
string
The name of the property to resolve.
Returns
string | number | undefined
The resolved string or number value, or undefined if unresolvable.
findVariableDeclarationInModuleGraph()
staticfindVariableDeclarationInModuleGraph(sourceFilePath,variableName,visitedFiles):VariableDeclaration|undefined
Find a variable declaration by traversing import and export chains.
Parameters
sourceFilePath
string
The source file path to start from.
variableName
string
The variable declaration name to find.
visitedFiles
Set<string>
The file set already visited.
Returns
VariableDeclaration | undefined
The variable declaration when found.
findImportedValueReference()
staticfindImportedValueReference(sourceFile,localName): {moduleSpecifier:string;importedName:string; } |undefined
Find an imported symbol reference by local identifier name.
Parameters
sourceFile
SourceFile
The source file to inspect.
localName
string
The local identifier name.
Returns
{ moduleSpecifier: string; importedName: string; } | undefined
The module specifier and imported symbol name.
resolveImportDeclarationSourceFile()
staticresolveImportDeclarationSourceFile(containingSourceFilePath,moduleSpecifier):string|undefined
Resolve an import declaration module specifier to a source file.
Parameters
containingSourceFilePath
string
The containing source file path.
moduleSpecifier
string
The module specifier text.
Returns
string | undefined
The resolved source file path.
extractConstObjectPropertyFromDeclarationInitializer()
staticextractConstObjectPropertyFromDeclarationInitializer(objectDeclaration,propertyName):string|number|undefined
Extract a const-object property value from a declaration initializer.
Parameters
objectDeclaration
VariableDeclaration
The variable declaration.
propertyName
string
The property to resolve.
Returns
string | number | undefined
The resolved value.
extractConstObjectPropertyFromDeclarationType()
staticextractConstObjectPropertyFromDeclarationType(declarationTypeNode,propertyName):string|number|undefined
Extract a const-object property value from a declaration type annotation.
Parameters
declarationTypeNode
TypeNode
The declaration type annotation.
propertyName
string
The property to resolve.
Returns
string | number | undefined
The resolved value.
extractLiteralValueFromTypeNode()
staticextractLiteralValueFromTypeNode(typeNode):string|number|undefined
Extract a literal value from a type node when possible.
Parameters
typeNode
TypeNode
The type node.
Returns
string | number | undefined
The literal value.
extractImportTypeName()
staticextractImportTypeName(qualifier):string|undefined
Extract a referenced type name from an import type qualifier.
Parameters
qualifier
EntityName | undefined
The import type qualifier.
Returns
string | undefined
The resolved type name.
resolveImportTypeReferenceSchemaId()
staticresolveImportTypeReferenceSchemaId(context,moduleSpecifier,typeName,title):string|undefined
Resolve import-type references to local or external schema ids.
Parameters
context
The generation context.
moduleSpecifier
string
The import module specifier.
typeName
string
The imported type name.
title
string
The derived schema title.
Returns
string | undefined
The resolved schema id.
inferSchemaFromExpression()
staticinferSchemaFromExpression(context,expr,asConst?):IJsonSchema
Infer a primitive JSON schema from a literal expression.
Parameters
context
The generation context.
expr
Expression
The expression to inspect.
asConst?
boolean = false
Whether to produce exact const schemas matching an as-const assertion.
Returns
IJsonSchema
The inferred schema.
inferObjectLiteralSchema()
staticinferObjectLiteralSchema(context,expr,asConst):IJsonSchema
Infer an object schema from an object literal expression, using const or widened types.
Parameters
context
The generation context.
expr
ObjectLiteralExpression
The object literal expression.
asConst
boolean
Whether property value schemas should be exact const types.
Returns
IJsonSchema
The inferred object schema.
inferArrayLiteralSchema()
staticinferArrayLiteralSchema(context,expr,asConst):IJsonSchema
Infer an array schema from an array literal expression. For as-const arrays a fixed-length tuple schema is produced; otherwise a plain array schema.
Parameters
context
The generation context.
expr
ArrayLiteralExpression
The array literal expression.
asConst
boolean
Whether to produce a const-exact tuple schema.
Returns
IJsonSchema
The inferred array schema.
mapConditionalTypeToSchema()
staticmapConditionalTypeToSchema(context,typeNode):IJsonSchema|undefined
Map conditional type nodes (e.g. T extends U ? X : Y) to schema.
Parameters
context
The generation context.
typeNode
ConditionalTypeNode
The conditional type node.
Returns
IJsonSchema | undefined
The mapped schema.
mapIndexedAccessTypeToSchema()
staticmapIndexedAccessTypeToSchema(context,typeNode):IJsonSchema|undefined
Map indexed access type nodes (e.g. T["id"]) to schema.
Parameters
context
The generation context.
typeNode
IndexedAccessTypeNode
The indexed access type node.
Returns
IJsonSchema | undefined
The mapped schema.
mapTemplateLiteralTypeToSchema()
staticmapTemplateLiteralTypeToSchema(context,typeNode):IJsonSchema
Map template literal type nodes to string schemas.
Parameters
context
The generation context.
typeNode
TemplateLiteralTypeNode
The template literal type node.
Returns
IJsonSchema
The mapped schema.
mapMappedTypeToSchema()
staticmapMappedTypeToSchema(context,typeNode):IJsonSchema|undefined
Map mapped type nodes to object schemas.
Parameters
context
The generation context.
typeNode
MappedTypeNode
The mapped type node.
Returns
IJsonSchema | undefined
The mapped schema.
isMappedTypeIndexedValueByTypeParameter()
staticisMappedTypeIndexedValueByTypeParameter(typeNode,mappedTypeParameterName):boolean
Determine whether a mapped type value uses indexed access with the mapped key parameter.
Parameters
typeNode
MappedTypeNode
The mapped type node.
mappedTypeParameterName
string
The mapped type parameter name.
Returns
boolean
True if the value shape is based on source indexed access.
checkTypeNodeAllowed()
staticcheckTypeNodeAllowed(context,typeNode,propertyName?,enclosingObjectName?):boolean
Check whether a type node is allowed for schema generation.
Parameters
context
The generation context.
typeNode
TypeNode
The type node to inspect.
propertyName?
string
The optional property name when the type is a property type.
enclosingObjectName?
string
The optional enclosing object name when the type is a property type.
Returns
boolean
True when the type is allowed.
isFunctionPropertyType()
staticisFunctionPropertyType(typeNode):boolean
Determine whether a property type should be treated as a function and skipped.
Parameters
typeNode
TypeNode
The property type node.
Returns
boolean
True if the property type is function-like.
isSymbolTypeNode()
staticisSymbolTypeNode(typeNode):boolean
Determine whether a type node represents symbol or unique symbol.
Parameters
typeNode
TypeNode
The type node to inspect.
Returns
boolean
True when the type is symbol or unique symbol.
isSymbolKeyedComputedExpression()
staticisSymbolKeyedComputedExpression(context,expression):boolean
Determine whether a computed property expression references a symbol. Covers well-known symbols (Symbol.iterator, etc.) and const variables declared with a unique symbol type annotation.
Parameters
context
The generation context.
expression
Expression
The computed property expression.
Returns
boolean
True when the key is symbol-based.
extractPropertyName()
staticextractPropertyName(context,propertyName):string|undefined
Extract a property name from TypeScript property syntax. Computed names are resolved when they evaluate to concrete literals.
Parameters
context
The generation context.
propertyName
PropertyName
The property name node.
Returns
string | undefined
The normalized property name.
findVariableDeclaration()
staticfindVariableDeclaration(sourceFile,variableName):VariableDeclaration|undefined
Find a variable declaration by name in a source file.
Parameters
sourceFile
SourceFile | undefined
The source file to search.
variableName
string
The variable name.
Returns
VariableDeclaration | undefined
The declaration if found.
resolveImportedTypeQuerySchema()
staticresolveImportedTypeQuerySchema(context,localName):IJsonSchema|undefined
Resolve a schema for an imported identifier used in a type query.
Parameters
context
The generation context.
localName
string
The local imported symbol name.
Returns
IJsonSchema | undefined
The mapped schema if resolvable.
resolveComputedPropertyNameExpression()
staticresolveComputedPropertyNameExpression(context,expression,resolvingIdentifiers):string|undefined
Resolve computed property name expressions when they can be evaluated to concrete keys.
Parameters
context
The generation context.
expression
Expression
The computed property expression.
resolvingIdentifiers
Set<string>
Identifier names currently being resolved.
Returns
string | undefined
The resolved property key.
findConstVariableDeclaration()
staticfindConstVariableDeclaration(context,variableName):VariableDeclaration|undefined
Find a local const variable declaration in the active source file.
Parameters
context
The generation context.
variableName
string
The variable name.
Returns
VariableDeclaration | undefined
The declaration when found.
resolveLocalConstObjectProperty()
staticresolveLocalConstObjectProperty(context,objectName,propertyName):string|number|undefined
Resolve a property value from a local const object declaration.
Parameters
context
The generation context.
objectName
string
The const object name.
propertyName
string
The property to resolve.
Returns
string | number | undefined
The resolved value when available.
mapTupleTypeToSchema()
staticmapTupleTypeToSchema(context,tupleTypeNode):IJsonSchema|undefined
Map a tuple type node to schema.
Parameters
context
The generation context.
tupleTypeNode
TupleTypeNode
The tuple type node.
Returns
IJsonSchema | undefined
The mapped tuple schema.
extractRestElementSchema()
staticextractRestElementSchema(context,restElementType):IJsonSchema|undefined
Extract schema for a tuple rest element.
Parameters
context
The generation context.
restElementType
TypeNode
The rest element type.
Returns
IJsonSchema | undefined
The mapped rest element schema.
findExistingSchemaIdByTitle()
staticfindExistingSchemaIdByTitle(context,schemaTitle):string|undefined
Find an existing schema id by title in known package schemas.
Parameters
context
The generation context.
schemaTitle
string
The schema title to find.
Returns
string | undefined
The existing schema id if found.
applyInterfaceExtendsSchema()
staticapplyInterfaceExtendsSchema(context,schema,declaration):void
Apply interface inheritance (extends) as allOf references.
Parameters
context
The generation context.
schema
Partial<IJsonSchema>
The schema to expand.
declaration
InterfaceDeclaration
The interface declaration.
Returns
void
Throws
GeneralError when an extended type cannot be resolved to a schema.
resolveRefinementUtilityBaseRef()
staticresolveRefinementUtilityBaseRef(context,declaration,extendedType):IJsonSchema|undefined
Resolve a direct base reference for refinement Omit patterns in interface extends clauses.
Parameters
context
The generation context.
declaration
InterfaceDeclaration
The interface declaration being mapped.
extendedType
ExpressionWithTypeArguments
The heritage type being processed.
Returns
IJsonSchema | undefined
A direct base reference when a refinement pattern is detected.
isNullOrUndefinedTypeNode()
staticisNullOrUndefinedTypeNode(typeNode):boolean
Determine whether a type node represents null or undefined.
Parameters
typeNode
TypeNode
The type node.
Returns
boolean
True if the node is null or undefined.
extractRecordLiteralKeys()
staticextractRecordLiteralKeys(keyTypeNode):string[]
Extract literal keys from a Record key type argument.
Parameters
keyTypeNode
TypeNode
The key type argument node.
Returns
string[]
The extracted literal keys.
mapJsonLdObjectDefaultSchemaByKey()
staticmapJsonLdObjectDefaultSchemaByKey(baseSchema,keyToAdd):IJsonSchema
Resolve a default schema for JsonLdObject utility key additions when the type argument is omitted.
Parameters
baseSchema
IJsonSchema
The base object schema.
keyToAdd
"type" | "id" | "@id" | "@type" | "@context"
The key being added by the utility.
Returns
IJsonSchema
The resolved schema.
mapJsonLdObjectWithIdDefaultIdSchema()
staticmapJsonLdObjectWithIdDefaultIdSchema(baseSchema):IJsonSchema
Resolve default id schema for JsonLdObjectWithId when Id type argument is omitted.
Parameters
baseSchema
IJsonSchema
The base object schema.
Returns
IJsonSchema
The resolved id schema.
mapJsonLdObjectWithTypeDefaultTypeSchema()
staticmapJsonLdObjectWithTypeDefaultTypeSchema(baseSchema):IJsonSchema
Resolve default type schema for JsonLdObjectWithType when Type argument is omitted.
Parameters
baseSchema
IJsonSchema
The base object schema.
Returns
IJsonSchema
The resolved type schema.
mapJsonLdObjectWithContextDefaultContextSchema()
staticmapJsonLdObjectWithContextDefaultContextSchema(baseSchema):IJsonSchema
Resolve default context schema for JsonLdObjectWithContext when Context argument is omitted.
Parameters
baseSchema
IJsonSchema
The base object schema.
Returns
IJsonSchema
The resolved context schema.
mapJsonLdObjectDefaultEitherSchema()
staticmapJsonLdObjectDefaultEitherSchema(baseSchema,firstKey,secondKey,fallbackSchema):IJsonSchema
Resolve default schema from either of two source keys, with fallback when both are absent.
Parameters
baseSchema
IJsonSchema
The base object schema.
firstKey
string
The primary key to resolve.
secondKey
string
The secondary key to resolve.
fallbackSchema
IJsonSchema
The fallback schema.
Returns
IJsonSchema
The resolved schema.
annotateUtilityInlineSchema()
staticannotateUtilityInlineSchema(schema,baseTypeDescription):IJsonSchema
Add a comment to schemas inlined for utility type transformations.
Parameters
schema
IJsonSchema
The schema to annotate.
baseTypeDescription
string
The utility base type description.
Returns
IJsonSchema
The annotated schema.
resolveUtilityBaseObjectSchema()
staticresolveUtilityBaseObjectSchema(context,baseTypeNode):IJsonSchema|undefined
Resolve a utility base type node to an object schema.
Parameters
context
The generation context.
baseTypeNode
TypeNode
The utility base type node.
Returns
IJsonSchema | undefined
The resolved object schema.
Throws
GeneralError when a named type reference cannot be resolved to a schema.
resolveMappedUtilityBaseObjectSchema()
staticresolveMappedUtilityBaseObjectSchema(context,mappedSchema):IJsonSchema|undefined
Resolve a mapped utility schema to an object schema when possible.
Parameters
context
The generation context.
mappedSchema
IJsonSchema
The mapped schema.
Returns
IJsonSchema | undefined
The resolved object schema.
expandAllOfReferences()
staticexpandAllOfReferences(context,schema,currentSchemaTitle?):IJsonSchema
Expand allOf references in a schema by inlining referenced schemas. This handles inheritance cases where a type extends another type. When applying utility operations (Omit, Pick) to types with allOf inheritance, the referenced schemas must be expanded so properties are available for omit/pick.
Parameters
context
The generation context.
schema
IJsonSchema
The schema potentially containing allOf with references.
currentSchemaTitle?
string
The title of the current schema being processed, used for $comment annotations.
Returns
IJsonSchema
The schema with expanded references merged into properties.
tryLoadExternalSchemaByTitle()
statictryLoadExternalSchemaByTitle(context,schemaTitle):IJsonSchema|undefined
Attempt to load an external schema by title from imported module declarations.
Parameters
context
The generation context.
schemaTitle
string
The schema title.
Returns
IJsonSchema | undefined
The loaded schema.
resolveObjectTypeSchemaForUtility()
staticresolveObjectTypeSchemaForUtility(context,typeName):IJsonSchema|undefined
Resolve an object schema for utility type application.
Parameters
context
The generation context.
typeName
string
The referenced type name.
Returns
IJsonSchema | undefined
The resolved object schema.
findImportedTypeReference()
staticfindImportedTypeReference(context,typeName): {moduleSpecifier:string;candidateTypeName:string; } |undefined
Find an imported type reference from the active source file by local or exported symbol name.
Parameters
context
The generation context.
typeName
string
The local or exported type name to find.
Returns
{ moduleSpecifier: string; candidateTypeName: string; } | undefined
The module specifier and exported candidate type name when found.
resolveImportedObjectTypeSchemaForUtility()
staticresolveImportedObjectTypeSchemaForUtility(context,moduleSpecifier,candidateTypeName,title):IJsonSchema|undefined
Resolve an imported object schema for utility type application.
Parameters
context
The generation context.
moduleSpecifier
string
The module where the type is imported from.
candidateTypeName
string
The exported candidate type name.
title
string
The stripped title of the requested type.
Returns
IJsonSchema | undefined
The resolved object schema.
mapObjectTypeFromLocalDeclaration()
staticmapObjectTypeFromLocalDeclaration(context,typeName):IJsonSchema|undefined
Map a local interface or type alias declaration to an object schema.
Parameters
context
The generation context.
typeName
string
The referenced type name.
Returns
IJsonSchema | undefined
The mapped schema.
extractUtilityTypeKeys()
staticextractUtilityTypeKeys(context,keysTypeNode):string[]
Extract string literal keys from a utility type key argument (e.g. Pick or Omit).
Parameters
context
The generation context.
keysTypeNode
TypeNode | undefined
The keys type node.
Returns
string[]
The extracted keys.
extractIndexedAccessKeys()
staticextractIndexedAccessKeys(context,indexTypeNode):string[]
Extract property keys from an indexed access index type.
Parameters
context
The generation context.
indexTypeNode
TypeNode
The index type node.
Returns
string[]
The extracted keys.
extractMappedTypeKeys()
staticextractMappedTypeKeys(context,constraintTypeNode):string[]
Extract keys for a mapped type constraint.
Parameters
context
The generation context.
constraintTypeNode
TypeNode | undefined
The mapped type constraint.
Returns
string[]
The extracted keys.
resolveReferencedTypeNodeFromLocalDeclaration()
staticresolveReferencedTypeNodeFromLocalDeclaration(context,typeNode):TypeNode|undefined
Resolve a referenced type node from a local type alias declaration.
Parameters
context
The generation context.
typeNode
TypeReferenceNode
The type reference node.
Returns
TypeNode | undefined
The referenced type node, if found locally.
withTypeParameterBindings()
staticwithTypeParameterBindings(context,typeParameters,typeArguments?):ITypeScriptToSchemaContext
Create a nested mapping context with generic parameters bound.
Parameters
context
The current generation context.
typeParameters
NodeArray<TypeParameterDeclaration> | undefined
The generic type parameters for the declaration.
typeArguments?
NodeArray<TypeNode>
Explicit type arguments, when provided.
Returns
The scoped mapping context.
getTypeParameterBinding()
staticgetTypeParameterBinding(context,typeName):TypeNode|null|undefined
Get a bound generic type parameter for the current mapping scope.
Parameters
context
The current generation context.
typeName
string
The type name to resolve.
Returns
TypeNode | null | undefined
The bound type node, null for unresolved generic parameters, or undefined when not generic.
isHomomorphicMappedType()
staticisHomomorphicMappedType(typeNode):boolean
Determine whether a mapped type is a homomorphic source-preserving form.
Parameters
typeNode
MappedTypeNode
The mapped type node.
Returns
boolean
True if the mapped type mirrors an existing object shape.
resolveMappedTypeSourceObjectSchema()
staticresolveMappedTypeSourceObjectSchema(context,typeNode):IJsonSchema|undefined
Resolve a source object schema for a mapped type when one exists.
Parameters
context
The generation context.
typeNode
MappedTypeNode
The mapped type node.
Returns
IJsonSchema | undefined
The resolved source object schema.
mapMappedTypePropertySchema()
staticmapMappedTypePropertySchema(context,typeNode,sourcePropertyKey,mappedTypeParameterName,sourceObjectSchema?):IJsonSchema|undefined
Map a single mapped-type property schema.
Parameters
context
The generation context.
typeNode
MappedTypeNode
The mapped type node.
sourcePropertyKey
string
The original property key from the source object, used for lookup when the mapped type is homomorphic.
mappedTypeParameterName
string
The mapped type parameter name.
sourceObjectSchema?
IJsonSchema
The optional source object schema.
Returns
IJsonSchema | undefined
The mapped property schema.
resolveIndexedPropertySchema()
staticresolveIndexedPropertySchema(context,objectTypeNode,propertyKey,sourceObjectSchema?):IJsonSchema|undefined
Resolve a concrete property schema for an indexed access object type and key.
Parameters
context
The generation context.
objectTypeNode
TypeNode
The source object type node.
propertyKey
string
The property key to resolve.
sourceObjectSchema?
IJsonSchema
The optional pre-resolved source object schema.
Returns
IJsonSchema | undefined
The resolved property schema.
isMappedTypeParameterReference()
staticisMappedTypeParameterReference(typeNode,mappedTypeParameterName):boolean
Determine whether a type node is a reference to the mapped type parameter.
Parameters
typeNode
TypeNode
The type node.
mappedTypeParameterName
string
The mapped type parameter name.
Returns
boolean
True if the node references the mapped parameter.
applyMappedTypeOptionality()
staticapplyMappedTypeOptionality(schema,optionalToken):void
Apply mapped-type optionality to a schema cloned from a source object.
Parameters
schema
IJsonSchema
The mapped schema.
optionalToken
QuestionToken | PlusToken | MinusToken | undefined
The mapped type optional token.
Returns
void
applyMappedTypeRequiredKeys()
staticapplyMappedTypeRequiredKeys(schema,propertyKeys,optionalToken):void
Apply mapped-type required keys for generated property sets.
Parameters
schema
IJsonSchema
The mapped schema.
propertyKeys
string[]
The generated property keys.
optionalToken
QuestionToken | PlusToken | MinusToken | undefined
The mapped type optional token.
Returns
void
extractKeyofTypeKeys()
staticextractKeyofTypeKeys(context,keysOperandNode):string[]
Extract key names from a keyof operand where possible.
Parameters
context
The generation context.
keysOperandNode
TypeNode
The operand used with keyof.
Returns
string[]
The extracted keys.
isGenericKeyofOperand()
staticisGenericKeyofOperand(context,keysOperandNode):boolean
Determine whether a keyof operand is a generic type parameter reference.
Parameters
context
The generation context.
keysOperandNode
TypeNode
The operand used with keyof.
Returns
boolean
True if the operand is a generic parameter.
resolveExternalTypeReferenceSchemaId()
staticresolveExternalTypeReferenceSchemaId(context,typeNode,typeName):string|undefined
Resolve a schema id for an external imported type reference.
Parameters
context
The generation context.
typeNode
TypeReferenceNode
The type reference node.
typeName
string
The referenced type name.
Returns
string | undefined
The resolved schema id.
resolveReferenceMappingTarget()
staticresolveReferenceMappingTarget(context,packageName,typeName): {schemaId:string;namespace?:string; } |undefined
Resolve a mapped schema target for an imported reference.
Parameters
context
The generation context.
packageName
string
The referenced package or module specifier.
typeName
string
The imported type name.
Returns
{ schemaId: string; namespace?: string; } | undefined
The mapped schema id and optional namespace if one matches.
findImportedModuleSpecifier()
staticfindImportedModuleSpecifier(sourceFile,typeNode,typeName):string|undefined
Find a module specifier for a referenced type in the active source file imports.
Parameters
sourceFile
SourceFile
The active source file.
typeNode
TypeReferenceNode
The referenced type node.
typeName
string
The referenced type name.
Returns
string | undefined
The module specifier.
mapJsonSchemaTagKey()
staticmapJsonSchemaTagKey(key):string
Map custom tag key names to JSON schema property names.
Parameters
key
string
The raw tag key.
Returns
string
The schema key.
extractTupleElementType()
staticextractTupleElementType(element):TypeNode|undefined
Extract the inner type node from a named or rest tuple element. Named tuple members and rest elements both wrap an inner type node; this unwraps them. Plain type nodes are returned as-is.
Parameters
element
TypeNode
The tuple element.
Returns
TypeNode | undefined
The inner type node.