Add "not" support to MiniJsonSchemaValidator
fieldPredicate's oneOf branches use `not: {required: [...]}` to make
values/number exclusive; the validator had no "not" handling at all, so it
silently ignored the keyword and FieldPredicate_ValuesAndNumberTogether_FailsItsSchema
found nothing wrong. A schema matches "not" when validating against the
subschema produces zero errors, in which case the instance must not match it.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
f47060d5c2
commit
52082ec720
1 changed files with 9 additions and 1 deletions
|
|
@ -12,7 +12,7 @@ namespace GameCult.Networking.Tests
|
|||
/// A deliberately small JSON Schema (draft 2020-12) validator covering only the constructs
|
||||
/// contracts/cultnet/*.schema.json actually use: object/array/string/integer/boolean/null types
|
||||
/// (plain or as a ["type","null"] union), required, additionalProperties: false, properties,
|
||||
/// items, const, enum, pattern, minLength, minItems, oneOf, and $ref - same-document
|
||||
/// items, const, enum, pattern, minLength, minItems, oneOf, not, and $ref - same-document
|
||||
/// ("#/$defs/name"), cross-document ("other.schema.json"), and both ("other.schema.json#/$defs/name").
|
||||
/// Not a general validator: it exists for R-S (docs/cultnet-selection-cut.md, fix batch 3) to
|
||||
/// decode real C# wire bytes and check them against the committed schema files, which no
|
||||
|
|
@ -114,6 +114,14 @@ namespace GameCult.Networking.Tests
|
|||
}
|
||||
}
|
||||
|
||||
if (schema.TryGetProperty("not", out var not))
|
||||
{
|
||||
var local = new List<string>();
|
||||
ValidateAgainst(instance, not, file, path, local);
|
||||
if (local.Count == 0)
|
||||
errors.Add($"{path}: matched the \"not\" subschema, which it must not");
|
||||
}
|
||||
|
||||
if (schema.TryGetProperty("const", out var constEl))
|
||||
{
|
||||
if (!JsonElementDeepEquals(instance, constEl))
|
||||
|
|
|
|||
Loading…
Reference in a new issue