Skip to content

Hold data to member and semantic-type ranges [patch] - #359

Merged
matt-edmondson merged 3 commits into
mainfrom
fix/349-enforce-member-range-on-data
Nov 4, 2026
Merged

matt-edmondson merged 3 commits into
mainfrom
fix/349-enforce-member-range-on-data

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #349

What changed

SchemaDataValidator now applies range to data values, which docs/schema-format.md already called for:

  • A number outside a non-wrapping range is an error at the value's path, for example 500 is outside the range [0, 100] of member 'Health'.
  • A wrapping range accepts any number.
  • Vectors and vector-form quantities are checked component by component (data.Value[1]), matching how range is validated on the schema side.
  • A semantic type's range is checked in ValidateSemanticValue, so it applies wherever a value of that type appears: a member, an array element, a map value or an optional. The ranges of the types it refines apply too.
  • Precedence: none. A member's own range and its semantic type's range both apply, and each miss is reported against its owner. A value has to sit inside all of them. This is now written down in docs/schema-format.md.
  • A value of the wrong type is reported once, as before, not also as out of range. A backwards range is left to schema validation.

The paths that go through the validator:

  • kschema validate and the generated data editors' Issues/IsValid pick the check up automatically, since the editors call SchemaDataValidator.
  • SchemaDataMigrator: ConformsTo now takes the member's range. A carried-over value the new range refuses follows the migrator's existing non-conforming rule (report it and use the default), with a message that says it is out of range rather than the wrong type. Without this, migrated data would no longer validate clean.

Tests

  • SchemaDataValidatorTypeTests: in range, on both bounds, out of range (the message names the range and the member), just past a float bound, a wrapping range, a vector checked per component, a wrong-type value reported once, a semantic-type range on a member and in an array, and a member range combined with a semantic range.
  • GeneratedDataEditorTests: Count now has a [0, 100] range. An out-of-range payload is added to the editor-vs-validator parity set, plus TestTheEditorRefusesAValueOutsideAMembersRange.
  • SchemaMigrationTests.AValueOutsideTheCurrentRangeIsReportedAndTakesTheDefault: the out-of-range value is replaced with the default and reported, the in-range one is kept, and the result validates clean.

With the fix reverted, the 9 new cases fail. With it, the full Schema.Test suite passes on net10.0 (733/733).

Main currently fails CA1506 on Schema/Models/Schema.cs (#353 fixes that). I ran the tests locally with that one rule suppressed, and the suppression isn't part of this PR. CI here will stay red on CA1506 until #353 lands.

Not covered: a vector whose ElementType is a ranged semantic type doesn't get that semantic type's range per component. The validator reduces component semantics in ExpectNumber without going through ValidateSemanticValue. Easy follow-up if wanted.


Generated by Claude Code

SchemaDataValidator checked a value against its type and never read a range,
so a non-wrapping [0, 100] Int member accepted 500 and -7. A number outside a
non-wrapping range is now an error at the value's path that names the range
and its owner. Vectors and vector quantities are checked per component, a
wrapping range accepts any number, and the range of a semantic type applies
wherever a value of it appears, alongside the member's own.

The migrator asks the validator through ConformsTo, which now takes the
member's range, so a value the new range refuses is reported and takes the
default instead of being carried into data that no longer validates.

Fixes #349

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW3VYgr52Mw1KS9otcE

Copy link
Copy Markdown
Contributor Author

CI is red on ci / .NET / Test, but the cause isn't this PR. The only error is CA1506: 'Schema' is coupled with '97' different types at Schema/Models/Schema.cs(18,22), which this diff doesn't touch. main fails the same way at 253db1a (run).

#353 has the fix and is mergeable. I haven't copied that refactor in here, since it would duplicate #353 across three open PRs and they would then conflict with it. Once #353 merges I'll bring main into this branch so CI re-runs. Locally, with only CA1506 suppressed, Schema.Test passes 733/733.


Generated by Claude Code

…r-range-on-data

# Conflicts:
#	Schema.Test/SchemaDataValidatorTypeTests.cs
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit fc71fd4 into main Nov 4, 2026
16 checks passed
@matt-edmondson
matt-edmondson deleted the fix/349-enforce-member-range-on-data branch November 4, 2026 03:26
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.

Data validation ignores member range: a non-wrapping [0, 100] Int member accepts 500 and -7 with no issues

2 participants