A switch compares its value; it does not evaluate it
Despite the parameter's name, a switch gateway runs no expression engine. The value is matched against each branch as it stands.
The rule
- A switch gateway MUST NOT evaluate its
expression. - The value MUST be compared unchanged against each branch's
value, in declaration order. - A branch MUST match if and only if the two values are equal as the conventions define equal values, which is JSON Schema's
constequality, with no conversion between types. - The first matching branch MUST be the sole active branch.
- The gateway MUST report that branch's name as active.
- Where no branch matches, the branch named by
default_branchMUST be active. - Where no branch matches and no usable default is named, the node MUST fail.
What it means
The parameter is named expression, but no expression engine ever sees it. A
value that happens to look like a query — a JSONPath-shaped string, say — is
still just a string, compared for equality against each branch's own
value in the order the branches are declared. There is no conversion either:
a value and a branch of different JSON types never match, even where a
conversion would make them equal.
Only the first branch to match becomes active, and its declared name is what the gateway reports. Nothing matching falls through to the configured default branch; nothing matching and no usable default fails the node outright.
Example
A value shaped exactly like a JSONPath query, matched against a branch whose own configured value is that same literal string:
{
"expression": "$.user.role",
"default_branch": "default",
"branches": [
{ "name": "Admin", "value": "admin" },
{ "name": "Literal", "value": "$.user.role" }
]
}["Literal"]The same strictness rules out a type match that a looser comparison would allow:
{ "expression": "1", "default_branch": "Fallback", "branches": [{ "name": "IntOne", "value": 1 }] }["Fallback"]"1" and 1 are equal after conversion but not of the same type, so the
comparison misses and the configured default branch, Fallback, is what
activates.
Equality is JSON Schema's, not the host language's. Two numbers with the same value are equal however they were written, and two objects are equal whatever order their members arrive in:
{
"expression": {"role": "admin", "level": 1.0},
"default_branch": "Fallback",
"branches": [{ "name": "Admin", "value": {"level": 1, "role": "admin"} }]
}["Admin"]