gregsdennis / Manatee.Json

A fully object-oriented approach to JSON manipulation, validation, and serialization that focuses on modeling the JSON structure rather than mere string parsing and conversion.
MIT License
198 stars 32 forks source link

additionalProperties of additionalProperties #287

Open amosonn opened 4 years ago

amosonn commented 4 years ago

Describe the bug additionalProperties inside an additionalProperties subschema is not properly validated.

To Reproduce

using System;
using Manatee.Json;
using Manatee.Json.Schema;
using Manatee.Json.Serialization;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var schemaStr = @"
{
  ""$schema"": ""http://json-schema.org/draft-07/schema#"",
  ""additionalProperties"": {
      ""additionalProperties"": false
  }
}";
            var jsonStr = @"
{
  ""abc"": {
    ""abc"": ""abc""
  }
}";
            var serializer = new JsonSerializer();
            var schema = serializer.Deserialize<JsonSchema>(JsonValue.Parse(schemaStr));
            var json = JsonValue.Parse(jsonStr);
            var validation = schema.Validate(json);
            Console.WriteLine("{0}", serializer.Serialize(validation));
        }
    }
}

Should give false, gives true.

Version

Additional context This problem doesn't exist in JsonSchema.NET.

gregsdennis commented 4 years ago

What does that schema do? Instances can have properties so long as they're not an object or have no properties?

Also, I'm winding down support for this library in favor of the new one. Happy to pull in a PR if you want to try and fix it, though.

amosonn commented 4 years ago

Yes, that what it means. It's of course contrived, but it is just a minimal reproduction from a larger schema I had. I think that also other subschemas inside additionalProperties aren't properly checked.

As mentioned above, this bug doesn't exist in the newer one, and I guess we'll switch soon. But I thought if I found it, I might as well document it.