Ejemplo n.º 1
0
        /// <summary>
        /// Validates a <see cref="JsonValue"/> against the schema.
        /// </summary>
        /// <param name="json">A <see cref="JsonValue"/></param>
        /// <param name="root">The root schema serialized to a <see cref="JsonValue"/>.  Used internally for resolving references.</param>
        /// <returns>True if the <see cref="JsonValue"/> passes validation; otherwise false.</returns>
        public virtual SchemaValidationResults Validate(JsonValue json, JsonValue root = null)
        {
            var jValue     = root ?? ToJson(null);
            var validators = JsonSchemaPropertyValidatorFactory.Get(this, json);
            var results    = validators.Select(v => v.Validate(this, json, jValue)).ToList();

            return(new SchemaValidationResults(results));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validates a <see cref="JsonValue"/> against the schema.
        /// </summary>
        /// <param name="json">A <see cref="JsonValue"/></param>
        /// <param name="root">The root schema serialized to a <see cref="JsonValue"/>.  Used internally for resolving references.</param>
        /// <returns>True if the <see cref="JsonValue"/> passes validation; otherwise false.</returns>
        public virtual SchemaValidationResults Validate(JsonValue json, JsonValue root = null)
        {
            if (BooleanSchemaDefinition == true)
            {
                return(new SchemaValidationResults());
            }
            if (BooleanSchemaDefinition == false)
            {
                return(new SchemaValidationResults(new[] { new SchemaValidationError(string.Empty, "All schemata are invalid") }));
            }

            var jValue     = root ?? ToJson(null);
            var validators = JsonSchemaPropertyValidatorFactory.Get(this, json);
            var results    = validators.Select(v => v.Validate(this, json, jValue)).ToList();

            return(new SchemaValidationResults(results));
        }