public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { bool succeeded = true; JsonObject target = value as JsonObject; if (target == null) return true; foreach (Regex pattern in items.Keys) { foreach (string property in target.GetKeys().Where(x => pattern.IsMatch(x))) { JsonSchemaRule rule = items[pattern]; JsonPathSegment segment = new JsonPropertySegment(property); JsonSchemaCallback scope = callback.Scope(segment); if (rule.IsValid(definitions, target.Get(property), callback) == false) { callback.Add(scope); succeeded = false; } } } return succeeded; }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { if (rule.IsValid(definitions, value, JsonSchemaCallback.Ignore()) == false) return true; return callback.Fail(value, "The NOT condition should not be valid."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { bool succeeded = true; JsonObject target = value as JsonObject; if (target == null) return true; foreach (string property in target.GetKeys()) { if (items.ContainsKey(property)) { JsonPathSegment segment = new JsonPropertySegment(property); JsonSchemaCallback scope = callback.Scope(segment); JsonSchemaRule rule = items[property]; if (rule.IsValid(definitions, target.Get(property), scope) == false) { callback.Add(scope); succeeded = false; } } } return succeeded; }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { int count = 0; List<JsonSchemaCallback> scopes = new List<JsonSchemaCallback>(); foreach (JsonSchemaRule rule in rules) { JsonSchemaCallback scope = callback.Scope(); if (rule.IsValid(definitions, value, scope)) count++; if (scope.Count > 0) scopes.Add(scope); if (count > 1) break; } if (count == 1) return true; if (count > 1) return callback.Fail(value, $"Exactly one schema should be valid, but {count} schemas were valid."); foreach (JsonSchemaCallback scope in scopes) callback.Add(scope); return callback.Fail(value, "Exactly one schema should be valid, but nothing was valid."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { bool succeeded = true; foreach (JsonSchemaRule rule in rules) if (rule.IsValid(definitions, value, callback) == false) succeeded = false; return succeeded; }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { // TODO: How to right pass meaningful messages? foreach (JsonSchemaRule rule in rules) if (rule.IsValid(definitions, value, JsonSchemaCallback.Ignore())) return true; return callback.Fail(value, "At least one schema should be valid."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { if (values.Contains(value)) return true; string list = String.Join(",", values); string message = $"The value should be from the given list: [{list}]"; return callback.Fail(value, message); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { foreach (string type in types) if (HasType(value, type)) return true; string allowed = String.Join(",", types); string message = $"The type is not valid. Allowed types: [{allowed}]"; return callback.Fail(value, message); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { JsonArray target = value as JsonArray; if (target == null) return true; if (maxItems >= target.Count) return true; return callback.Fail(value, $"The array cannot have more than {maxItems} items."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { JsonArray target = value as JsonArray; if (target == null) return true; if (target.Count <= items) return true; return callback.Fail(value, $"The array is in tuple mode and cannot contain additional items. Tuple size: {items}. Array size: {target.Count}."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { JsonText target = value as JsonText; if (target == null) return true; if (pattern.IsMatch(target.Value)) return true; return callback.Fail(value, "The value does not match the pattern."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { JsonObject target = value as JsonObject; if (target == null) return true; if (maxProperties >= target.Count) return true; return callback.Fail(value, $"The object cannot have more than {maxProperties} properties."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { JsonArray target = value as JsonArray; if (target == null) return true; if (minItems <= target.Count) return true; return callback.Fail(value, $"The array should have more than or equal to {minItems} items"); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { List<JsonSchemaMessage> messages = new List<JsonSchemaMessage>(); if (definitions.Resolve(reference).IsValid(value, messages)) return true; foreach (JsonSchemaMessage message in messages) callback.Add(message); return callback.Fail(value, $"Referenced schema '{reference}' is invalid."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { JsonText text = value as JsonText; if (text == null) return true; if (text.Value.Length <= maxLength) return true; return callback.Fail(value, $"The text cannot be longer than {maxLength} characters."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { JsonNumber target = value as JsonNumber; if (target == null) return true; if (exclusiveMaximum == false && target.ToDecimal() <= maximum) return true; if (exclusiveMaximum == true && target.ToDecimal() < maximum) return true; return callback.Fail(value, $"The number should be greater than {maximum}."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { JsonNumber target = value as JsonNumber; if (target == null) return true; decimal division = target.ToDecimal() / multipleOf; long integer = Convert.ToInt64(division); if (integer == division) return true; return callback.Fail(value, $"The number should be multiplication of {multipleOf}."); }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { JsonObject target = value as JsonObject; if (target == null) return true; bool succeeded = true; List<string> left = new List<string>(target.GetKeys()); foreach (string property in properties) left.Remove(property); foreach (Regex pattern in patterns) left.RemoveAll(pattern.IsMatch); if (left.Count == 0) return true; if (rule == null && left.Count > 0) { foreach (string property in left) callback.Fail(new JsonPropertySegment(property), value, "The presence of any additional property is not allowed."); return false; } if (rule != null) { foreach (string property in left) { JsonPathSegment segment = new JsonPropertySegment(property); JsonSchemaCallback scope = callback.Scope(segment); if (rule.IsValid(definitions, target.Get(property), scope) == false) { callback.Add(scope); succeeded = false; } } } return succeeded; }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { bool succeeded = true; JsonArray target = value as JsonArray; if (target == null) return true; if (schema != null) { foreach (JsonValue item in target.Items()) { int index = target.IndexOf(item); JsonPathSegment segment = new JsonIndexSegment(index); JsonSchemaCallback scope = callback.Scope(segment); if (schema.IsValid(definitions, item, scope) == false) { callback.Add(scope); succeeded = false; } } } if (tuples != null) { for (int i = 0; i < tuples.Count && i < target.Count; i++) { JsonPathSegment segment = new JsonIndexSegment(i); JsonSchemaCallback scope = callback.Scope(segment); JsonValue item = target.Get(i); JsonSchemaRule rule = tuples[i]; if (rule.IsValid(definitions, item, scope) == false) { callback.Add(scope); succeeded = false; } } } return succeeded; }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { bool succeeded = true; JsonObject target = value as JsonObject; if (target == null) return true; foreach (string property in properties) { if (target.Contains(property) == false) { callback.Fail(new JsonPropertySegment(property), value, "The property is required."); succeeded = false; } } return succeeded; }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { switch (format) { case "uri": return IsValidUri(value, callback); case "ipv4": return IsIpAddressV4(value, callback); case "ipv6": return IsIpAddressV6(value, callback); case "date-time": return IsDateTime(value, callback); case "email": default: return true; } }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { bool succeeded = true; JsonObject target = value.As<JsonObject>(); if (target == null) return true; foreach (string property in byName.Keys) if (target.Contains(property)) foreach (string dependency in byName[property]) if (target.Contains(dependency) == false) { JsonPathSegment segment = new JsonPropertySegment(property); callback.Fail(segment, value, $"The dependency is not valid. Missing property: {dependency}."); succeeded = false; } foreach (string property in byRule.Keys) { if (target.Contains(property)) { JsonSchemaRule rule = byRule[property]; JsonPathSegment segment = new JsonPropertySegment(property); JsonSchemaCallback scope = callback.Scope(segment); if (rule.IsValid(definitions, value, scope) == false) { callback.Add(scope); succeeded = false; } } } return succeeded; }
public override bool IsValid(JsonSchemaDefinitions definitions, JsonValue value, JsonSchemaCallback callback) { JsonArray target = value as JsonArray; if (target == null) return true; HashSet<JsonValue> found = new HashSet<JsonValue>(); List<JsonValue> repeated = new List<JsonValue>(); foreach (JsonValue item in target.Items()) if (found.Add(item) == false) repeated.Add(item); if (repeated.Count > 0) { string items = String.Join(",", repeated); string message = $"The array elements should be unique. Repeated elements: [{items}]"; return callback.Fail(value, message); } return true; }