Allow a compound to declare an ordered validation - #7580
Open
laritakr wants to merge 2 commits into
Open
Conversation
A compound can now declare a rule relating two of its sub-properties, so
an entry whose end date falls before its start date is refused:
dates:
validations:
- { type: ordered, before: start_date, after: end_date }
`required:` constrains one sub-property at a time, leaving no way to
express a relationship between two. An unrecognized rule type is carried
through rather than rejected, so a profile written against a newer Hyrax
still loads; profile validation warns about it, which keeps a misspelled
rule from silently doing nothing.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for compound-level validation rules so a compound property can enforce ordering constraints across two sub-properties (e.g., end date must not precede start date), with profile-time warnings for rules that would otherwise be silently ignored.
Changes:
- Introduces normalized
validations:on compound definitions and implements anorderedrule inHyrax::CompoundEntryValidation. - Adds a flexible-schema validator that warns on unknown/incomplete compound validation rules (non-blocking).
- Adds specs, documentation, and I18n strings for the new ordering rule and warnings.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| spec/services/hyrax/flexible_schema_validators/compound_validations_validator_spec.rb | Tests warning behavior for unknown/incomplete compound validation rules. |
| spec/services/hyrax/compound_schema_spec.rb | Verifies compound validations: are carried through schema definitions and default to empty. |
| spec/services/hyrax/compound_entry_validation_spec.rb | Tests ordered-rule behavior (in-order, equal, blank end date, deduped violations). |
| documentation/compound_fields.md | Documents validations: and the ordered rule semantics and messaging. |
| config/locales/hyrax.en.yml | Adds end-user error message for out-of-order entries and validator warning messages. |
| app/services/hyrax/flexible_schema_validators/compound_validations_validator.rb | Implements warning-only profile validation for compound validations: rules. |
| app/services/hyrax/flexible_schema_validator_service.rb | Wires the new compound validations validator into overall schema validation. |
| app/services/hyrax/compound_schema.rb | Normalizes compound validations: rules into the compound definition. |
| app/services/hyrax/compound_entry_validation.rb | Implements ordered validation and emits :out_of_order violations. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+111
to
+118
| def comparable(row, key) | ||
| value = row[key] || row[key.to_sym] | ||
| return if value.blank? | ||
|
|
||
| Date.parse(value.to_s) | ||
| rescue ArgumentError, TypeError | ||
| nil | ||
| end |
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.
Summary
A compound metadata property can declare a rule relating two of its sub-properties, so an entry whose end date falls before its start date is refused.
Details
Nothing previously stopped a reversed range from saving: validation was per-sub-property, with no way to express a rule across two. This validation is declared on the compound rather than a sub-property:
orderedcompares dates. A blankafter(the usual case for an optional end date) is allowed, as are equal values; a value that does not parse as a date is skipped rather than flagged.missing_required_subpropertiesdedupes. A row still missing arequired:sub-property reports only that, so a half-filled entry doesn't raise two complaints.type:is carried through rather than rejected, so a profile written against a newer Hyrax still loads. A new profile-validation warning surfaces it, which stops a misspelling (ordred) from silently disabling the rule.validations:behave exactly as before.