Ejemplo n.º 1
0
        static SchemaRegistry()
        {
            Global = new SchemaRegistry();

            Global.Register(MetaSchemas.Draft6Id, MetaSchemas.Draft6);
            Global.Register(MetaSchemas.Draft7Id, MetaSchemas.Draft7);
            Global.Register(MetaSchemas.Draft201909Id, MetaSchemas.Draft201909);
            Global.Register(MetaSchemas.Core201909Id, MetaSchemas.Core201909);
            Global.Register(MetaSchemas.Applicator201909Id, MetaSchemas.Applicator201909);
            Global.Register(MetaSchemas.Validation201909Id, MetaSchemas.Validation201909);
            Global.Register(MetaSchemas.Metadata201909Id, MetaSchemas.Metadata201909);
            Global.Register(MetaSchemas.Format201909Id, MetaSchemas.Format201909);
            Global.Register(MetaSchemas.Content201909Id, MetaSchemas.Content201909);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
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);
        }