Skip to content

Rule schema: conditions array/null union shape returns 400 on visual-builder PUT #909

Description

@rubenvdlinde

Surfaced during the #877 browser smoke-test (PR #908).

The Rule schema declares conditions as a union type (array or null). When the visual condition builder serialises a non-empty condition tree as a JSON object (e.g. {"and": [{"var": ["user.email"]}]}) and PUTs it, OR's validation rejects it with HTTP 400 — the schema only accepts array or null at that path, not an object.

Repro

  1. Create a rule via the openconnector UI (/rules → Add)
  2. Open the rule detail page (feat(rules): bespoke Rule editor with visual condition + action builder (closes #833) #873)
  3. Use the visual condition builder to add a single var leaf
  4. Save → PUT returns 400 {"error":"Validation failed: conditions must be array or null"}

Root cause

JsonLogic's canonical shape is a top-level object ({op: [...args]}), not an array. The schema typing is wrong.

Fix options

  1. Change conditions type to object or object | null to match JsonLogic shape (preferred)
  2. Wrap the visual builder's output in an array at the frontend level ([{and: [...]}]) — but then backend evaluators need updating to unwrap

Option 1 is the right model. The backend already expects JsonLogic shape per jwadhams/json-logic-php's API.

Scope

Schema migration in OR's openconnector register (the rule schema definition lives in lib/Repair/InitializeRegister.php or similar). Test that existing rules with null conditions stay null; existing rules with already-wrapped-in-array conditions get unwrapped or stay wrapped (backend tolerates both).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions