Skip to content

Conversation

@antoniocapelo
Copy link
Collaborator

Overview

This PR addresses a bug where the allowForbiddenValues option was interfering with boolean conditional evaluation in JSON Schema if statements. When boolean literals (true or false) are used as conditions, they should always evaluate consistently regardless of validation options.

🐛 Problem Solved

When using boolean literals as conditions in JSON Schema conditionals:

{
  "if": true,
  "then": { "required": ["field1"] },
  "else": { "required": ["field2"] }
}

The allowForbiddenValues option was incorrectly affecting the evaluation of these boolean conditions, leading to unpredictable behavior where:

  • if: true might not always trigger the then branch
  • if: false might not always trigger the else branch

Solution

Enhanced the evaluateIfCondition function to properly handle boolean conditionals:

const isTheConditionalABoolean = typeof ifNode === 'boolean'
const conditionIsTrue = validateSchema(value, ifNode, { 
  ...options, 
  ...(isTheConditionalABoolean ? { allowForbiddenValues: false } : {}) 
}, path, jsonLogicContext).length === 0

Key Changes:

  • Boolean conditionals now ignore the allowForbiddenValues option during evaluation
  • if: true always evaluates to true (triggers then branch)
  • if: false always evaluates to false (triggers else branch)
  • Non-boolean conditions continue to respect the allowForbiddenValues option normally

@antoniocapelo antoniocapelo changed the title fix: consider boolean if conditions fix(conditionals): respect "if" blocks that are booleans Jul 22, 2025
@antoniocapelo antoniocapelo merged commit 2422832 into main Jul 22, 2025
5 checks passed
@antoniocapelo antoniocapelo deleted the devxp-3286-consider-boolean-conditionals branch July 22, 2025 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants