feat(gts): enforce x-gts-closed-derivations in OP#12 chain validation - #111
feat(gts): enforce x-gts-closed-derivations in OP#12 chain validation#111AndrejK666 wants to merge 1 commit into
Conversation
New schema modifier (spec 0.14 draft, S9.11.4): a base type may require every derived schema to resolve to a closed content model at its own top level (effective additionalProperties: false). Enforced in validate_schema_chain next to the x-gts-final guard, using the existing effective-schema extraction (allOf-closedness lattice). Modifier validation: boolean-only, top-level placement, rejected in combination with x-gts-final (a final type has no derivations). Tests: closed derived passes; open and default-open rejected; closedness via allOf conjunct passes; final+closed-derivations rejected. Signed-off-by: Andrej Kuchma <Andrej.Kuchma@constructor.tech>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe PR adds ChangesClosed derivation validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant BaseSchema
participant validate_schema_chain
participant DerivedSchema
BaseSchema->>validate_schema_chain: declare x-gts-closed-derivations
validate_schema_chain->>DerivedSchema: resolve top-level content model
DerivedSchema-->>validate_schema_chain: return additionalProperties setting
validate_schema_chain-->>BaseSchema: accept or return ValidationError
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@AndrejK666, please check GlobalTypeSystem/gts-spec#91 (comment) |
Summary
Implements the x-gts-closed-derivations schema modifier proposed in GlobalTypeSystem/gts-spec# (0.14 draft, §9.11.4): a base type may require every derived schema to resolve to a closed content model at its own top level. Enforced in validate_schema_chain (OP#12) next to the existing x-gts-final guard.
Changes
gts/src/schema_modifiers.rs
new constant X_GTS_CLOSED_DERIVATIONS with doc comment;
validate_schema_modifiers: boolean-only value, top-level placement (same fail-fast rule as the other modifiers), and rejection of the meaningless x-gts-final + x-gts-closed-derivations combination.
gts/src/store.rs — in validate_schema_chain, for each (base, derived) pair: if the base declares the modifier, the derived schema's effective top-level additionalProperties (via the existing extract_effective_schema, which already folds allOf through the closedness-preserving lattice) must be false; otherwise StoreError::ValidationError naming the modifier, the base and the derived id.
gts/src/store_test.rs — five tests:
closed derived schema under a closed-derivations base → passes;
derived with additionalProperties: true → rejected (message names the modifier);
derived with additionalProperties omitted (default-open) → rejected;
closedness contributed by an allOf conjunct → passes;
final + closed-derivations on one schema → modifier validation error.
Why only direct derivations are checked
A closed derived level already prevents grandchildren from adding properties (§3.1), and a grandchild re-opening the level would accept instances its closed parent rejects — failing derivation compatibility (§4.1) through the existing checks. See spec §9.11.4 item 3.
Testing
bash
cargo test -p gts
All existing tests pass unchanged (the modifier is opt-in; schemas without it are unaffected).
Related
Spec: GlobalTypeSystem/gts-spec#
Motivating discussion: gears-rust tenant-metadata envelope (open abstract base + mandatory-closed derived metadata schemas); pairs with the planned open-content-model support in struct_to_gts_schema.
Summary by CodeRabbit
New Features
Bug Fixes
Tests