Repository navigation
feat(core): evaluate value constraints in validator-free rule conditions - #2647
Open
gigibiffi84 wants to merge 14 commits into
Open
gigibiffi84 wants to merge 14 commits into
gigibiffi84 wants to merge 14 commits into
Conversation
Update to latest
The SET_AJV reducer compiled the schema with the new Ajv instance but never wrote it to state, so every later setSchema or re-enabled validation silently went back to the previous instance. Part of eclipsesource#1498 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…ing them with Ajv Combinator tab selection compiled every oneOf/anyOf/allOf branch with Ajv and then ignored all errors except the structural keywords required, additionalProperties, type, enum and const. The new isStructuralMatch evaluates exactly those keywords itself, recursively through properties, patternProperties, items, $ref, nested combinators and if/then/else. Tab selection therefore no longer depends on an Ajv instance or on code generation, so it also works under a Content Security Policy without unsafe-eval. Equivalence with the previous filtered-Ajv behaviour is covered by tests comparing both approaches keyword by keyword. Part of eclipsesource#1498 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Adds the validation seam from issue eclipsesource#1498 as a non-breaking addition: the `validator` init/updateCore option takes a FormValidatorFactory `(schema) => FormValidator` or a FormValidator already bound to the schema. The types mirror the FormValidator / ValidationIssue of the 4.x presentation-model branch, restricted to synchronous results. - The core reducer creates the Form Validator through the factory whenever the schema changes and caches it in `state.formValidator`; `state.validator` keeps holding the compiled Ajv function when Ajv validates, so existing consumers are unaffected. - Issues from custom validators are converted to the Ajv error shape the rest of core and the renderers read (`issuesToErrors`): missing `key` becomes `custom`, `required` issues addressed to the missing property are split into parent path plus `params.missingProperty`, non-error severities are dropped and a missing `parentSchema` is resolved from the form schema. - `createAjvValidator(ajv?)` is the built-in adapter; `compiledAjvValidator(validateFn)` wraps Ajv standalone code for CSP setups without unsafe-eval. - `getValidator(state)` exposes the bound Form Validator. - Switching to NoValidation via setValidationMode now also drops the cached validator, as init and updateCore already did. Precedence: `validator` wins, otherwise `ajv`, otherwise the default Ajv instance. Existing users notice nothing. Part of eclipsesource#1498 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Resolved with the bridge's reducer (which already stores the Ajv instance on setAjv), both util exports, and both groups of reducer tests.
Schema based rule conditions were always evaluated with ajv.validate(condition.schema, value), the last place where a custom Form Validator did not apply. - Widen the `ajv` parameter of isVisible, isEnabled, isReadonly, the eval* functions and Runtime.isVisible/isEnabled to RuleValidator: an Ajv instance (unchanged behaviour), a FormValidator (its `matches`, or the Structural Matcher when it has none), a FormValidatorFactory (one Form Validator per condition schema, cached) or undefined (the Structural Matcher alone). - Add matchesConditionSchema and the getRuleValidator selector; core's own mappers pass getRuleValidator(state) instead of getAjv(state). Part of eclipsesource#1498 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- React, Vue and Angular JsonForms gain a `validator` prop/input next to `ajv`, forwarded to init/updateCore; Vue adds useValidator(); JsonFormsAngularService.updateCoreState takes an optional validator. - Material and vanilla withAjvProps additionally inject `ruleValidator` (getRuleValidator), used by the categorization layouts; Angular Material evaluates category visibility with getRuleValidator too. - ExampleDescription gains an optional `validator`, passed through by all five example apps; new "Custom validator" example with a dependency-free handwritten Form Validator and a schema-based rule. Part of eclipsesource#1498 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Rule conditions evaluated without a validator (none configured, or a custom Form Validator without `matches`) only knew the structural keywords. The new isSchemaMatch extends the Structural Matcher with minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, minLength, maxLength, pattern, minItems, maxItems, uniqueItems, minProperties, maxProperties and not, mirroring Ajv's semantics, and matchesConditionSchema uses it for both validator-free paths. isStructuralMatch is unchanged, so combinator tab selection keeps ignoring value keywords as before. Part of eclipsesource#1498 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
✅ Deploy Preview for jsonforms-examples ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1498. Stacked on #2643 (Structural Matcher) and #2645 (rules through the Form Validator); the diff shrinks to the last commit once those are merged.
What changed
Rule conditions evaluated without a validator (no
validatorconfigured and no Ajv instance, or a custom Form Validator withoutmatches) used the Structural Matcher, which knowstype,enum,const,requiredandadditionalPropertiesonly. Real rule conditions also use value constraints.isSchemaMatch(schema, data, rootSchema?): the Structural Matcher extended withminimum,maximum,exclusiveMinimum,exclusiveMaximum(draft-07 numbers and draft-04 booleans),multipleOf,minLength,maxLength(code points, like Ajv),pattern(unanchored,uflag, invalid patterns ignored),minItems,maxItems,uniqueItems,minProperties,maxPropertiesandnot.formatand$dataare not evaluated. No validator instance, no code generation.matchesConditionSchemausesisSchemaMatchfor both validator-free paths.isStructuralMatchis unchanged, so combinator tab selection keeps ignoring value keywords as it always did.For adopters
Nothing changes for Ajv users or for Form Validators with
matches. Adopters with a custom Form Validator and nomatchesnow get rule conditions with numeric, string and array constraints evaluated correctly instead of being treated as always satisfied.Tests
test/util/structural.test.ts: 32 cases comparingisSchemaMatchwith full Ajv validity keyword by keyword, plus draft-04 booleans, invalid pattern,formatignored, and a guard thatisStructuralMatchstill ignores value constraints.test/util/runtime.test.ts: rules withminimum,patternandnotunder no validator and under a validator withoutmatches. 570 core tests green; build, package lint and typedoc succeed.🤖 Generated with Claude Code