Skip to content

Added XSD value restrictions to model attributes - #719

Open
HassanAkbar wants to merge 5 commits into
mainfrom
feat/restrictions-for-attributes
Open

Added XSD value restrictions to model attributes#719
HassanAkbar wants to merge 5 commits into
mainfrom
feat/restrictions-for-attributes

Conversation

@HassanAkbar

Copy link
Copy Markdown
Member

fixes #191

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 into Attribute#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.

Comment thread lib/lutaml/model/restriction_validation.rb
Comment thread lib/lutaml/model/restriction_validation.rb Outdated
@HassanAkbar
HassanAkbar force-pushed the feat/restrictions-for-attributes branch from 72296e4 to 54cda07 Compare July 14, 2026 11:37
@github-actions

Copy link
Copy Markdown

JS build check

Triggered [js-pr-check]
(https://github.com/lutaml/lutaml-model-js/actions/workflows/pr-check.yml)
against this PR's head (54cda07).

The result will appear as a lutaml-model-js / pr-check status check
on this PR once the workflow run completes.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 42 out of 42 changed files in this pull request and generated 2 comments.

Comment thread lib/lutaml/model/attribute.rb
Comment thread lib/lutaml/model/restriction_validation.rb
@github-actions

Copy link
Copy Markdown

JS build check

Triggered [js-pr-check]
(https://github.com/lutaml/lutaml-model-js/actions/workflows/pr-check.yml)
against this PR's head (68cb36d).

The result will appear as a lutaml-model-js / pr-check status check
on this PR once the workflow run completes.

@github-actions

Copy link
Copy Markdown

JS build check

Triggered [js-pr-check]
(https://github.com/lutaml/lutaml-model-js/actions/workflows/pr-check.yml)
against this PR's head (b663005).

The result will appear as a lutaml-model-js / pr-check status check
on this PR once the workflow run completes.

Comment thread lib/lutaml/xml/schema/xsd_schema.rb Fixed
Comment thread lib/lutaml/xml/schema/xsd_schema.rb Fixed
@github-actions

Copy link
Copy Markdown

JS build check

Triggered [js-pr-check]
(https://github.com/lutaml/lutaml-model-js/actions/workflows/pr-check.yml)
against this PR's head (203ddac).

The result will appear as a lutaml-model-js / pr-check status check
on this PR once the workflow run completes.

@HassanAkbar
HassanAkbar marked this pull request as ready for review July 16, 2026 07:59
@HassanAkbar
HassanAkbar force-pushed the feat/restrictions-for-attributes branch from 203ddac to 4bcd68f Compare July 23, 2026 08:47
@github-actions

Copy link
Copy Markdown

JS build check

Triggered [js-pr-check]
(https://github.com/lutaml/lutaml-model-js/actions/workflows/pr-check.yml)
against this PR's head (4bcd68f).

The result will appear as a lutaml-model-js / pr-check status check
on this PR once the workflow run completes.

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.

Required restrictions for attributes

3 participants