Skip to content

fix(options): Allow only known options - #265

Merged
danielcardoso5 merged 5 commits into
mainfrom
fix-allow-only-known-options
Jul 15, 2026
Merged

fix(options): Allow only known options#265
danielcardoso5 merged 5 commits into
mainfrom
fix-allow-only-known-options

Conversation

@danielcardoso5

@danielcardoso5 danielcardoso5 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Follow up to #263

  • Breaking change – Ensures new options cannot be added when processing a conditional branch unless they are specified in the field's base options. If the field doesn't have the options property (e.g. anyOf), then any new options provided via conditionals are accepted
    • This is a breaking change since schemas that don't declare all the allowed options in the field by default, now won't show them when a conditional is adding new options
  • Refactors deepMergeSchemas into two separate functions: mergeSchemaBranch for the logic of merging conditional branches, mergeFieldProperties to merge field properties. deepMergeSchemas did both with mixed logic
  • Running tests in watch mode now properly watches the src folder
  • test/json-schema-test-suite/failed-json-schema-test-suite.json is not written every time we run the tests now, only via the test:write-failed-tests script. This fixes test:watch running an infinite loop, and ensures the file is only written to when intended

For the breaking change, if a field is declared the following way:

    "properties": {
        "permissions": {
            "type": "string",
            "enum": ["read", "write", "all"]
        }
    }

Then conditionals can only conditionally apply the options in the base enum, a subset or all of "enum": ["read", "write", "all"]. Any new value like update won't be accepted. The schema validates against both the base enum and the conditional enum. This applies even if the base enum is declared as an empty array.

However, if the key enum doesn't exist at all, then a conditional can add any enum option it wants. So if the schema is:

    "properties": {
        "permissions": {
            "type": "string"
        }
    }

then a conditional can set permissions.enum: ["update"] and it will accept that new option.


Note

Medium Risk
Breaking behavior for schemas that relied on conditionals to introduce new options; core mutation/validation path changed with broad test coverage.

Overview
Breaking change: When if/then/else (or allOf) branches merge into a field schema, enum, oneOf, anyOf, and options can only narrow or relabel values already declared on the base property—conditionals can no longer inject new option values. Field updates after validation use a separate merge path so option lists can still be fully replaced when reverting conditionals.

deepMergeSchemas is split into mergeSchemaBranch (conditional schema merge with option filtering) and mergeFieldProperties (in-place field updates); mutations.ts calls the new APIs.

Tooling: Jest roots includes src for watch mode; JSON Schema Test Suite failure tracking writes failed-json-schema-test-suite.json only when SHOULD_WRITE_FAILED_TESTS_TO_FILE=true via new test:write-failed-tests script (avoids watch loops and accidental overwrites).

Reviewed by Cursor Bugbot for commit fc71e4c. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 990903c. Configure here.

Comment thread test/json-schema-test-suite/json-schema-test-suite-tracker.js
Comment thread src/utils.ts
@remotecom
remotecom force-pushed the fix-allow-only-known-options branch from 990903c to 5ab33b4 Compare July 10, 2026 17:26
@danielcardoso5
danielcardoso5 force-pushed the fix-allow-only-known-options branch from fc71e4c to 80b6e8b Compare July 13, 2026 15:56
@danielcardoso5

Copy link
Copy Markdown
Collaborator Author

🟢 pipeline here

Comment thread test/json-schema-test-suite/json-schema-test-suite-tracker.js
Comment thread test/fields/options.test.ts
@danielcardoso5
danielcardoso5 merged commit 41845fa into main Jul 15, 2026
6 checks passed
@danielcardoso5
danielcardoso5 deleted the fix-allow-only-known-options branch July 15, 2026 14:54
@danielcardoso5 danielcardoso5 changed the title fix: Allow only known options fix(options): Allow only known options Jul 15, 2026
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.

3 participants