private void ValidateProperties(JToken token, string propertyName, string propertyPath, List <ValidationError> errors)
        {
            var obj = token as JObject;

            foreach (var propertyInfo in _schema.Properties)
            {
                var newPropertyPath = propertyName != null ? propertyName + "." + propertyInfo.Key : propertyInfo.Key;

                var property = obj?.Property(propertyInfo.Key);
                if (property != null)
                {
                    var propertyValidator = new JsonSchemaValidator(propertyInfo.Value);
                    var propertyErrors    = propertyValidator.Validate(property.Value, propertyInfo.Key, newPropertyPath);
                    errors.AddRange(propertyErrors);
                }
                else if (propertyInfo.Value.IsRequired)
                {
                    errors.Add(new ValidationError(ValidationErrorKind.PropertyRequired, propertyInfo.Key, newPropertyPath));
                }
            }

            if (obj != null)
            {
                var properties = obj.Properties().ToList();

                ValidateMaxProperties(properties, propertyName, propertyPath, errors);
                ValidateMinProperties(properties, propertyName, propertyPath, errors);

                var additionalProperties = properties.Where(p => !_schema.Properties.ContainsKey(p.Name)).ToList();

                ValidatePatternProperties(additionalProperties, errors);
                ValidateAdditionalProperties(additionalProperties, propertyName, propertyPath, errors);
            }
        }
        private ChildSchemaValidationError TryCreateChildSchemaError(JsonSchemaValidator validator, JsonSchema4 schema, JToken token, ValidationErrorKind errorKind, string property, string path)
        {
            var errors = validator.Validate(token, null, null);

            if (errors.Count == 0)
            {
                return(null);
            }

            var errorDictionary = new Dictionary <JsonSchema4, ICollection <ValidationError> >();

            errorDictionary.Add(schema, errors);

            return(new ChildSchemaValidationError(errorKind, property, path, errorDictionary));
        }
        private ChildSchemaValidationError TryCreateChildSchemaError(JsonSchema4 schema, JToken token, ValidationErrorKind errorKind, string property, string path)
        {
            var validator = new JsonSchemaValidator(schema);

            return(TryCreateChildSchemaError(validator, schema, token, errorKind, property, path));
        }