Added XSD value restrictions to model attributes - #719
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements Issue #191 by adding support for XSD restriction facets on value types and attribute-level restrictions, ensuring facets are enforced during model validation and correctly round-trip through XSD compilation/generation.
Changes:
- Adds a facet DSL to
Lutaml::Model::Type::Value(inclusive/exclusive bounds, length, enumeration, pattern, whiteSpace, totalDigits/fractionDigits) with inheritance/merge rules. - Introduces lazy restriction enforcement on attributes via
RestrictionValidation, integrated intoAttribute#validate_value!, and surfaces facet errors through model-level error types. - Extends the XML compiler and XSD schema generator to parse/emit restriction facets (including canonical ordering and lexical preservation), plus adds extensive regression/round-trip test coverage.
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| spec/lutaml/xml/schema/facet_round_trip_spec.rb | New end-to-end round-trip coverage for facet regeneration (model⇄XSD). |
| spec/lutaml/xml/schema/compiler/restriction_spec.rb | Adds unit coverage for new restriction facet accessors and emitted macros. |
| spec/lutaml/xml/schema/compiler_spec.rb | Adds integration coverage for compiled models enforcing facets and edge regressions. |
| spec/lutaml/model/type_white_space_facet_spec.rb | New specs for cast-time whiteSpace normalization and inheritance behavior. |
| spec/lutaml/model/type_facet_restriction_spec.rb | New specs for facet tightening/merging, guards, and lazy validation semantics. |
| spec/lutaml/model/type_digit_facet_spec.rb | New specs for totalDigits/fractionDigits semantics, guards, and enforcement. |
| spec/lutaml/model/schema/xsd_schema_spec.rb | Ensures XSD generation inlines restrictions for constrained types and fails on conjunctive patterns. |
| spec/lutaml/model/attribute_restriction_spec.rb | New specs for attribute-level restrictions (min/max, signed, min/max length, collections, etc.). |
| spec/fixtures/xml/restriction_facets.xsd | New fixture XSD containing representative restriction facets for compiler tests. |
| lib/lutaml/xml/schema/xsd/min_exclusive.rb | Changes minExclusive value attribute type to string for lexical preservation. |
| lib/lutaml/xml/schema/xsd/max_exclusive.rb | Changes maxExclusive value attribute type to string for lexical preservation. |
| lib/lutaml/xml/schema/xsd_schema.rb | Inlines <xs:restriction> for constrained value types and emits facets in canonical order. |
| lib/lutaml/model/validation.rb | Collects restriction errors during validate (non-bang) runs. |
| lib/lutaml/model/type/value.rb | Implements facet declaration/merge/tightening logic, plus additional facet macros. |
| lib/lutaml/model/type/string.rb | Adds cast-time whitespace normalization and memoized effective whiteSpace mode. |
| lib/lutaml/model/type.rb | Autoloads new type-level exclusive-bound errors. |
| lib/lutaml/model/services/type/validator.rb | Adds exclusive bound validator helpers and type-level exclusive errors. |
| lib/lutaml/model/schema/xml_compiler/simple_type.rb | Emits facet declarations into generated simple-type classes. |
| lib/lutaml/model/schema/xml_compiler/restriction.rb | Adds facet macro emission (incl/excl/length/pattern/enums/whiteSpace/digits) with correct literal rendering. |
| lib/lutaml/model/schema/xml_compiler.rb | Parses additional facet elements; preserves tightest bounds with numeric ordering and lexical preservation. |
| lib/lutaml/model/restriction_validation.rb | New module enforcing merged Layer-1/Layer-2 restriction facets at validation time. |
| lib/lutaml/model/error/type/min_exclusive_error.rb | New type-level minExclusive error. |
| lib/lutaml/model/error/type/max_exclusive_error.rb | New type-level maxExclusive error. |
| lib/lutaml/model/error/type.rb | Autoloads new type-level exclusive-bound errors. |
| lib/lutaml/model/error/total_digits_error.rb | New model-level totalDigits restriction error. |
| lib/lutaml/model/error/restriction_error.rb | New model-level base restriction error type. |
| lib/lutaml/model/error/min_length_error.rb | New model-level minLength restriction error. |
| lib/lutaml/model/error/min_inclusive_error.rb | New model-level minInclusive restriction error. |
| lib/lutaml/model/error/min_exclusive_error.rb | New model-level minExclusive restriction error. |
| lib/lutaml/model/error/max_length_error.rb | New model-level maxLength restriction error. |
| lib/lutaml/model/error/max_inclusive_error.rb | New model-level maxInclusive restriction error. |
| lib/lutaml/model/error/max_exclusive_error.rb | New model-level maxExclusive restriction error. |
| lib/lutaml/model/error/length_error.rb | New model-level exact-length restriction error. |
| lib/lutaml/model/error/fraction_digits_error.rb | New model-level fractionDigits restriction error. |
| lib/lutaml/model/attribute.rb | Hooks restriction validation into attribute validation; expands allowed restriction options. |
| lib/lutaml/model.rb | Autoloads restriction validation module and new model-level restriction errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
72296e4 to
54cda07
Compare
JS build checkTriggered [ The result will appear as a |
JS build checkTriggered [ The result will appear as a |
JS build checkTriggered [ The result will appear as a |
JS build checkTriggered [ The result will appear as a |
…_xsd/to_xsd round-trip
… bounds, and export valid XSD patterns
…mial regex (CodeQL)
203ddac to
4bcd68f
Compare
JS build checkTriggered [ The result will appear as a |
fixes #191