Aller au contenu principal

generateUnionValidation()

generateUnionValidation(varName, ctx, constraints): object

Experimental

Generates complete validation code for a union schema. Automatically chooses the best strategy based on branch types.


Parameters

varName: string

The variable name to validate

ctx: GeneratorContext

The generator context

constraints: UnionConstraintMeta

Union constraint metadata


Returns: object

Generated code lines and updated context

code: string[]

ctx: GeneratorContext


Since

2.0.0


Example

const result = generateUnionValidation("value", ctx, {
branches: [
{ typeName: "string", typeofCheck: "string", generateCode: stringGenerator },
{ typeName: "number", typeofCheck: "number", generateCode: numberGenerator }
]
});