Ejemplo n.º 1
0
        public override IEnumerable <SchemaIssue> FindIssues(IContentNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            var issues = base.FindIssues(node);

            if (issues.Any())
            {
                foreach (var i in issues)
                {
                    yield return(i);
                }
            }
            else
            {
                if (Properties != null)
                {
                    foreach (var prop in Properties)
                    {
                        var path = ContentPath.Root.Append(prop.Key);

                        var exists = node.TryEvaluate(path, out IContentNode result);

                        if (exists)
                        {
                            var fieldIssues = prop.Value.FindIssues(result);
                            foreach (var issue in fieldIssues)
                            {
                                yield return(new SchemaIssue(
                                                 path.Append(issue.SubjectPath),
                                                 issue.Error));
                            }
                        }
                        else if (prop.IsRequired)
                        {
                            yield return(new SchemaIssue(path, $"required but missing"));
                        }
                    }
                }
                else
                {
                    if (node is ContentObject objectNode)
                    {
                        foreach (var key in objectNode.Keys)
                        {
                            var path = ContentPath.Root.Append(key);
                            node.TryEvaluate(path, out IContentNode result);

                            var fieldIssues = ItemType.FindIssues(result);
                            foreach (var issue in fieldIssues)
                            {
                                yield return(new SchemaIssue(
                                                 path.Append(issue.SubjectPath),
                                                 issue.Error));
                            }
                        }
                    }
                }
            }

            yield break;
        }