From 52082ec72056250f6894fefad09e98154479e24c Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 22 Sep 2026 20:13:53 +0200 Subject: [PATCH] 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 --- .../MiniJsonSchemaValidator.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/GameCult.Networking.Tests/MiniJsonSchemaValidator.cs b/tests/GameCult.Networking.Tests/MiniJsonSchemaValidator.cs index 904e4ecb..61a0a02c 100644 --- a/tests/GameCult.Networking.Tests/MiniJsonSchemaValidator.cs +++ b/tests/GameCult.Networking.Tests/MiniJsonSchemaValidator.cs @@ -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(); + 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))