feat(gts): enforce x-gts-closed-derivations in OP#12 chain validation - #111
Open
AndrejK666 wants to merge 1 commit into
Open
feat(gts): enforce x-gts-closed-derivations in OP#12 chain validation#111AndrejK666 wants to merge 1 commit into
AndrejK666 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 |
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
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