--- id: LANG-27 family: GR-LANG level: core profiles: [runtime] posture: normative-target added: "1.0" changed: "1.0" source: https://flowdrop.io/spec/rules/gr-lang/lang-27 specification: FlowDrop Workflow Specification 1.0 licence: CC BY 4.0 --- # LANG-27 — A switch compares its value; it does not evaluate it *GR-LANG (Part I) · level: core · profiles: runtime · added in 1.0* Despite the parameter's name, a switch gateway runs no expression engine. The value is matched against each branch as it stands. ## The rule > **Normative.** This is the rule. > > 1. A switch gateway MUST NOT evaluate its `expression`. > > 2. The value MUST be compared unchanged against each branch's `value`, in declaration order. > > 3. A branch MUST match if and only if the two values are equal as the conventions define equal values, which is JSON Schema's `const` equality, with no conversion between types. > > 4. The first matching branch MUST be the sole active branch. > > 5. The gateway MUST report that branch's name as active. > > 6. Where no branch matches, the branch named by `default_branch` MUST be active. > > 7. 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: ```json title="The expression and the branches it is compared against" { "expression": "$.user.role", "default_branch": "default", "branches": [ { "name": "Admin", "value": "admin" }, { "name": "Literal", "value": "$.user.role" } ] } ``` ```json title="The active branch" verdict="active" ["Literal"] ``` The same strictness rules out a type match that a looser comparison would allow: ```json title="A string expression against a branch whose value is the integer 1" { "expression": "1", "default_branch": "Fallback", "branches": [{ "name": "IntOne", "value": 1 }] } ``` ```json title="The active branch" verdict="active" ["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: ```json title="A number and an object, against branches written differently" { "expression": {"role": "admin", "level": 1.0}, "default_branch": "Fallback", "branches": [{ "name": "Admin", "value": {"level": 1, "role": "admin"} }] } ``` ```json title="The active branch" verdict="active" ["Admin"] ``` ## Why Recorded under [OPEN-25](https://flowdrop.io/spec/rulings/open-25), [OPEN-29](https://flowdrop.io/spec/rulings/open-29). --- Rule identifiers are permanent and are never renumbered. This specification carries no implementation status: each implementation publishes its own standing against these rules. Licensed CC BY 4.0.