コード例 #1
0
        public void RefResolvesToInternallyStoredSchema()
        {
            var source = new JsonSchema()
                         .Id("http://schema.org/source")
                         .AllOf(new JsonSchema().Ref("http://schema.org/target"));

            var target = new JsonSchema()
                         .Id("http://schema.org/target")
                         .Property("test", true)
                         .Required("test");

            JsonSchemaRegistry.Register(source);
            JsonSchemaRegistry.Register(target);

            try
            {
                var instance = new JsonObject {
                    ["test"] = "literally anything"
                };

                var results = source.Validate(instance);

                results.AssertValid();
            }
            finally
            {
                JsonSchemaRegistry.Unregister(source);
                JsonSchemaRegistry.Unregister(target);
            }
        }
コード例 #2
0
        public void RecursiveRefResolvesOuterAnchor_BrokenChain()
        {
            var source = new JsonSchema()
                         .Id("http://schema.org/source")
                         .RecursiveAnchor(true)
                         .OneOf(new JsonSchema()
                                .Property("nested", new JsonSchema()
                                          .Ref("http://schema.org/middle"))
                                .Required("nested"),
                                new JsonSchema()
                                .Property("test", true)
                                .Required("test"));

            var middle = new JsonSchema()
                         .Id("http://schema.org/middle")
                         .OneOf(new JsonSchema()
                                .Ref("http://schema.org/target"),
                                new JsonSchema()
                                .Property("middle", false)
                                .Required("middle"));

            var target = new JsonSchema()
                         .Id("http://schema.org/target")
                         .RecursiveAnchor(true)
                         .AllOf(new JsonSchema().RecursiveRefRoot());

            JsonSchemaRegistry.Register(source);
            JsonSchemaRegistry.Register(middle);
            JsonSchemaRegistry.Register(target);

            try
            {
                var instance = new JsonObject
                {
                    ["nested"] = new JsonObject
                    {
                        ["test"] = "literally anything"
                    }
                };

                var results = source.Validate(instance);

                results.AssertValid();
            }
            finally
            {
                JsonSchemaRegistry.Unregister(source);
                JsonSchemaRegistry.Unregister(middle);
                JsonSchemaRegistry.Unregister(target);
            }
        }