Skip to content

Conversation

@domdomegg
Copy link

Summary

Implements detection of JSON Schema enum changes with context-aware breaking change detection.

Resolves the issue where enum arrays being extended or reduced were not detected by the tool.

Changes

  • Added EnumAdd and EnumRemove change types with context flags (lhs_has_no_enum and rhs_has_no_enum)
  • Smart breaking change logic:
    • Adding values to existing enum: non-breaking (accepts more data)
    • Removing values from existing enum: breaking (rejects previously valid data)
    • Adding enum constraint entirely: breaking (restricts previously valid data)
    • Removing enum constraint entirely: non-breaking (accepts more data)
  • Comprehensive test coverage: 9 test cases covering all scenarios including the real-world case from the issue

Examples

# Adding a value to existing enum (non-breaking)
$ json-schema-diff old.json new.json
{"path":"","change":{"EnumAdd":{"added":"debug","lhs_has_no_enum":false}},"is_breaking":false}

# Removing a value from existing enum (breaking)
$ json-schema-diff old.json new.json  
{"path":"","change":{"EnumRemove":{"removed":"debug","rhs_has_no_enum":false}},"is_breaking":true}

# Adding enum constraint (breaking)
$ json-schema-diff old.json new.json
{"path":"","change":{"EnumAdd":{"added":"error","lhs_has_no_enum":true}},"is_breaking":true}

# Removing enum constraint (non-breaking)
$ json-schema-diff old.json new.json
{"path":"","change":{"EnumRemove":{"removed":"error","rhs_has_no_enum":true}},"is_breaking":false}

Fixes #38

Implements detection of JSON Schema enum changes, resolving issue getsentry#38.

Changes:
- Add EnumAdd and EnumRemove change types with context flags
- Track whether enum constraint is being added/removed entirely
- Smart breaking change logic:
  - Adding values to existing enum: non-breaking (accepts more)
  - Removing values from existing enum: breaking (rejects data)
  - Adding enum constraint: breaking (restricts values)
  - Removing enum constraint: non-breaking (relaxes values)
- Comprehensive test coverage with 9 test cases including the real-world
  scenario from the original issue

Fixes getsentry#38

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@domdomegg domdomegg requested a review from a team as a code owner October 7, 2025 13:43
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.

Enum support

1 participant