Skip to Content
@jetio/schema-builder docs are live 🎉
API ReferenceConditionBuilder

ConditionBuilder

.if() returns a ConditionBuilder. While you’re inside it, .then() and .elseIf() keep returning the ConditionBuilder so you can keep chaining conditions. .else() and .end() close the conditional and hand control back to the parent builder — the SchemaBuilder (or sub-builder) you called .if() on — so you can continue with .properties(), .required(), .build(), and so on.

In other words, “parent builder” is whatever builder the conditional was attached to. .else() / .end() are how you step back out to it.

const schema = new SchemaBuilder() .object() .properties({ role: (s) => s.string(), adminKey: (s) => s.string(), }) .if((s) => s.object().properties({ role: (s) => s.const("admin") })) .then((s) => s.object().required(["adminKey"])) .end() // closes the conditional, returns the ObjectSchemaBuilder .required(["role"]) // back on the parent builder .build();

Without a trailing .else(), you must call .end() to return to the parent — otherwise the chain is still inside the ConditionBuilder and .build() isn’t available.

MethodParametersReturnsDescription
.then(schema)BuilderSchema or (b: SchemaBuilder) => SchemaBuilderConditionBuilderSchema applied if the condition passes
.elseIf(condition)BuilderSchema or (b: SchemaBuilder) => SchemaBuilderConditionBuilderAdd another condition to the chain
.else(schema)BuilderSchema or (b: SchemaBuilder) => SchemaBuilderParent builderSchema if all conditions fail; closes the conditional
.end()—Parent builderClose the conditional without an else
Last updated on