示例#1
0
        public void Issue141_ExamplesInSchema()
        {
            var schema = new JsonSchema06
            {
                Schema     = JsonSchema06.MetaSchema.Id,
                Type       = JsonSchemaType.Object,
                Properties = new Dictionary <string, IJsonSchema>
                {
                    ["test"] = new JsonSchema06
                    {
                        Id          = "/properties/test",
                        Type        = JsonSchemaType.String,
                        Title       = "Test property",
                        Description = "Test property",
                        Default     = "",
                        Examples    = new JsonArray {
                            "any string"
                        }
                    }
                }
            };
            var json = new JsonObject {
                ["test"] = "a valid string"
            };

            var results = schema.Validate(json);

            Console.WriteLine(string.Join("\n", results.Errors));

            Assert.IsTrue(results.Valid);
        }
示例#2
0
        public void Draft06_ValidateReturnsValidOnLessThanExclusiveMaximum()
        {
            var schema = new JsonSchema06 {
                Type = JsonSchemaType.Integer, ExclusiveMaximum = 5
            };
            var json = (JsonValue)3;

            var results = schema.Validate(json);

            results.AssertValid();
        }
示例#3
0
        public void Draft06_ValidateReturnsErrorOnEqualsExclusiveMaximum()
        {
            var schema = new JsonSchema06 {
                Type = JsonSchemaType.Integer, ExclusiveMaximum = 5
            };
            var json = (JsonValue)5;

            var results = schema.Validate(json);

            results.AssertInvalid();
        }
示例#4
0
        public void Draft06_ValidateReturnsValidOnMoreThanExclusiveMinimum()
        {
            var schema = new JsonSchema06 {
                Type = JsonSchemaType.Number, ExclusiveMinimum = 5
            };
            var json = (JsonValue)10;

            var results = schema.Validate(json);

            results.AssertValid();
        }
 public static IEnumerable <IJsonSchemaPropertyValidator <JsonSchema06> > Get(JsonSchema06 schema, JsonValue json)
 {
     return(_schema06Validators.Where(v => v.Applies(schema, json)));
 }
示例#6
0
        public void Issue167_PropertyNamesWithPropertylessRequired(JsonObject json, bool isValid)
        {
            var schema = new JsonSchema06
            {
                Schema      = JsonSchema06.MetaSchema.Id,
                Definitions = new Dictionary <string, IJsonSchema>
                {
                    ["fields"] = new JsonSchema06
                    {
                        Type       = JsonSchemaType.Object,
                        Properties = new Dictionary <string, IJsonSchema>
                        {
                            ["field1"] = new JsonSchema06 {
                                Type = JsonSchemaType.String
                            },
                            ["field2"] = new JsonSchema06 {
                                Type = JsonSchemaType.Integer
                            }
                        }
                    },
                    ["xyzBaseFieldNames"] = new JsonSchema06
                    {
                        Enum = new EnumSchemaValue[] { "field1", "field2" }
                    },
                    ["worldwide"] = new JsonSchema06
                    {
                        AllOf = new IJsonSchema[]
                        {
                            new JsonSchemaReference("#/definitions/fields", typeof(JsonSchema06)),
                            new JsonSchema06 {
                                Required = new[] { "field1" }
                            },
                            new JsonSchema06
                            {
                                Properties = new Dictionary <string, IJsonSchema>
                                {
                                    ["A"] = new JsonSchema06 {
                                        Type = JsonSchemaType.String
                                    },
                                    ["B"] = new JsonSchema06 {
                                        Type = JsonSchemaType.Integer
                                    }
                                },
                                OneOf = new IJsonSchema[]
                                {
                                    new JsonSchema06 {
                                        Required = new[] { "A" }
                                    },
                                    new JsonSchema06 {
                                        Required = new[] { "B" }
                                    },
                                }
                            },
                            new JsonSchema06
                            {
                                PropertyNames = new JsonSchema06
                                {
                                    AnyOf = new IJsonSchema[]
                                    {
                                        new JsonSchemaReference("#/definitions/xyzBaseFieldNames", typeof(JsonSchema06)),
                                        new JsonSchema06
                                        {
                                            Enum = new EnumSchemaValue[] { "A", "B" }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                Type       = JsonSchemaType.Object,
                Properties = new Dictionary <string, IJsonSchema>
                {
                    ["xyz"] = new JsonSchemaReference("#/definitions/worldwide", typeof(JsonSchema06))
                },
                AdditionalProperties = JsonSchema06.False,
                Required             = new[] { "xyz" }
            };

            var results = schema.Validate(json);

            Assert.AreEqual(isValid, results.Valid);
        }