Skip to content

Conversation

@ShivaGupta-14
Copy link
Contributor

Description

When multiple const or enum constraints fail (e.g., via allOf), produce a single message with the most restrictive constraint instead of multiple redundant messages.

  • Compute the intersection of allowed values across all constraints
  • If intersection has 1 value: use const message
  • If intersection has multiple values: use enum message
  • If intersection is empty (contradictory): use boolean schema message
  • Fixes: Combine const and enum handlers #132

Checklist

  • npm test
  • npm run lint
  • npm run type-check

@ShivaGupta-14 ShivaGupta-14 force-pushed the 132-combine-const-enum-handlers branch from 7646a94 to ac73647 Compare January 30, 2026 18:24
Copy link
Collaborator

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach isn't going to work. Try,

{
  "allOf": [
    { "const": "a" },
    { "const": "b" }
  ]
}

@ShivaGupta-14 ShivaGupta-14 force-pushed the 132-combine-const-enum-handlers branch from ac73647 to 3b4eaf2 Compare January 31, 2026 15:51
@ShivaGupta-14
Copy link
Contributor Author

ShivaGupta-14 commented Jan 31, 2026

This approach isn't going to work. Try,

{
  "allOf": [
    { "const": "a" },
    { "const": "b" }
  ]
}

Hi @jdesrosiers,

thanks for pointing out the issue! I understood the problem:

Issue: with a schema like above one -> allOf: [{ const: "a" }, { const: "b" }], if the instance is "a"

  • const: "a" passes (not in errors)
  • Only const: "b" fails
  • My original code only saw failing constraints -> couldn't detect the contradiction
  • My Solution: I updated the handler to collect ALL constraints (both passing and failing), then compute the intersection:
const passed = normalizedErrors[...][schemaLocation] === true;
if (!passed) hasFailure = true;
// always collect
constraints.push({ allowedValues: [...], schemaLocation });

now:

  • Both ["a"] and ["b"] are collected
  • Intersection = [] (empty)
  • Returns getBooleanSchemaErrorMessage()

Tests Added:

  • contradictory const - empty intersection (instance matches one const)
  • contradictory enum - empty intersection (disjoint enum sets)

All tests pass. Is this approach good, or does it need further improvements?
Thanks!

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.

Combine const and enum handlers

2 participants