예제 #1
0
        private Uri RegisterSubschemasAndGetBaseUri(SchemaRegistry registry, Uri currentUri)
        {
            if (Keywords == null)
            {
                return(null);                              // boolean cases
            }
            var idKeyword = Keywords.OfType <IdKeyword>().SingleOrDefault();

            if (idKeyword != null)
            {
                currentUri = idKeyword.UpdateUri(currentUri);
                var parts    = idKeyword.Id.OriginalString.Split(new[] { '#' }, StringSplitOptions.None);
                var fragment = parts.Length > 1 ? parts[1] : null;
                if (string.IsNullOrEmpty(fragment) || fragment[0] == '/')
                {
                    registry.Register(currentUri, this);
                }
                else
                {
                    registry.RegisterAnchor(currentUri, fragment, this);
                }
            }

            var anchorKeyword = Keywords.OfType <AnchorKeyword>().SingleOrDefault();

            if (anchorKeyword != null)
            {
                registry.RegisterAnchor(currentUri, anchorKeyword.Anchor, this);
            }

            var keywords = Keywords.OfType <IRefResolvable>().OrderBy(k => ((IJsonSchemaKeyword)k).Priority());

            foreach (var keyword in keywords)
            {
                keyword.RegisterSubschemas(registry, currentUri);
            }

            return(currentUri);
        }
        private Uri?RegisterSubschemasAndGetBaseUri(SchemaRegistry registry, Uri currentUri)
        {
            if (Keywords == null)
            {
                return(null);                              // boolean cases
            }
            var idKeyword  = Keywords.OfType <IdKeyword>().SingleOrDefault();
            var refKeyword = Keywords.OfType <RefKeyword>().SingleOrDefault();
            var refMatters = refKeyword != null &&
                             (registry.ValidatingAs == Draft.Draft6 || registry.ValidatingAs == Draft.Draft7);

            if (idKeyword != null && !refMatters)
            {
                currentUri = idKeyword.UpdateUri(currentUri);
                var parts    = idKeyword.Id.OriginalString.Split(new[] { '#' }, StringSplitOptions.None);
                var fragment = parts.Length > 1 ? parts[1] : null;
#pragma warning disable 8602
                if (string.IsNullOrEmpty(fragment) || fragment[0] == '/')
#pragma warning restore 8602
                {
                    registry.Register(currentUri, this);
                }
                else
                {
                    registry.RegisterAnchor(currentUri, fragment, this);
                }
            }

            var anchors = Keywords.OfType <IAnchorProvider>();
            foreach (var anchor in anchors)
            {
                anchor.RegisterAnchor(registry, currentUri, this);
            }

            var keywords = Keywords.OfType <IRefResolvable>().OrderBy(k => ((IJsonSchemaKeyword)k).Priority());
            foreach (var keyword in keywords)
            {
                keyword.RegisterSubschemas(registry, currentUri);
            }

            return(currentUri);
        }
예제 #3
0
 void IAnchorProvider.RegisterAnchor(SchemaRegistry registry, Uri currentUri, JsonSchema schema)
 {
     registry.RegisterAnchor(currentUri, Anchor, schema);
 }
예제 #4
0
 void IAnchorProvider.RegisterAnchor(SchemaRegistry registry, Uri currentUri, JsonSchema schema)
 {
     registry.RegisterAnchor(currentUri, Value, schema);
     registry.RegisterDynamicAnchor(currentUri, Value, schema);
 }