コード例 #1
0
        /// <summary>
        /// Provides the validation logic for this keyword.
        /// </summary>
        /// <param name="context">The context object.</param>
        /// <returns>Results object containing a final result and any errors that may have been found.</returns>
        public SchemaValidationResults Validate(SchemaValidationContext context)
        {
            if (Resolved == null)
            {
                _ResolveReference(context);
                if (Resolved == null)
                {
                    throw new SchemaReferenceNotFoundException(context.RelativeLocation);
                }
            }

            var results = new SchemaValidationResults(Name, context);

            var newContext = new SchemaValidationContext
            {
                BaseUri              = _resolvedRoot.DocumentPath,
                Instance             = context.Instance,
                Root                 = _resolvedRoot ?? context.Root,
                BaseRelativeLocation = _resolvedFragment.WithHash(),
                RelativeLocation     = context.RelativeLocation.CloneAndAppend(Name),
                InstanceLocation     = context.InstanceLocation
            };
            var nestedResults = Resolved.Validate(newContext);

            if (!nestedResults.IsValid)
            {
                results.IsValid = false;
                results.Keyword = Name;
            }

            results.NestedResults.Add(nestedResults);

            return(results);
        }
コード例 #2
0
        /// <summary>
        /// Provides the validation logic for this keyword.
        /// </summary>
        /// <param name="context">The context object.</param>
        /// <returns>Results object containing a final result and any errors that may have been found.</returns>
        public SchemaValidationResults Validate(SchemaValidationContext context)
        {
            if (Resolved == null)
            {
                _ResolveReference(context);
                if (Resolved == null)
                {
                    throw new SchemaReferenceNotFoundException(context.RelativeLocation);
                }

                Log.Schema(() => "Reference found");
            }

            var results = new SchemaValidationResults(Name, context);

            var newContext = new SchemaValidationContext(context)
            {
                BaseUri              = _resolvedRoot?.DocumentPath,
                Instance             = context.Instance,
                Root                 = _resolvedRoot ?? context.Root,
                BaseRelativeLocation = _resolvedFragment?.WithHash(),
                RelativeLocation     = context.RelativeLocation.CloneAndAppend(Name),
            };
            var nestedResults = Resolved.Validate(newContext);

            results.IsValid = nestedResults.IsValid;
            results.NestedResults.Add(nestedResults);
            context.UpdateEvaluatedPropertiesAndItemsFromSubschemaValidation(newContext);

            return(results);
        }
コード例 #3
0
        /// <summary>
        /// Provides the validation logic for this keyword.
        /// </summary>
        /// <param name="context">The context object.</param>
        /// <returns>Results object containing a final result and any errors that may have been found.</returns>
        public SchemaValidationResults Validate(SchemaValidationContext context)
        {
            if (_validatingLocations.Any(l => Equals(l, context.InstanceLocation)))
            {
                return new SchemaValidationResults(Name, context)
                       {
                           RecursionDetected = true,
                           AnnotationValue   = "Detected recursive loop. Processing halted on this branch."
                       }
            }
            ;

            if (Resolved == null)
            {
                _ResolveReference(context);

                if (Resolved == null)
                {
                    throw new SchemaReferenceNotFoundException(context.RelativeLocation);
                }
            }

            var results = new SchemaValidationResults(Name, context);

            var newContext = new SchemaValidationContext(context)
            {
                BaseUri = _resolvedRoot.DocumentPath,
                Root    = _resolvedRoot ?? context.Root,
                BaseRelativeLocation = _resolvedFragment.WithHash(),
                RelativeLocation     = context.RelativeLocation.CloneAndAppend(Name),
            };

            _validatingLocations.Add(context.InstanceLocation);
            var nestedResults = Resolved.Validate(newContext);

            _validatingLocations.Remove(context.InstanceLocation);

            results.IsValid = nestedResults.IsValid;
            results.NestedResults.Add(nestedResults);

            return(results);
        }