public static SchemaScope CreateTokenScope(JsonToken token, JSchema schema, ContextBase context, Scope parent, int depth)
        {
            SchemaScope scope;

            switch (token)
            {
            case JsonToken.StartObject:
                var objectScope = new ObjectScope(context, parent, depth, schema);
                context.Scopes.Add(objectScope);

                objectScope.InitializeScopes(token);

                scope = objectScope;
                break;

            case JsonToken.StartArray:
            case JsonToken.StartConstructor:
                scope = new ArrayScope(context, parent, depth, schema);
                context.Scopes.Add(scope);
                break;

            default:
                scope = new PrimativeScope(context, parent, depth, schema);
                context.Scopes.Add(scope);
                break;
            }

            if (schema._allOf != null && schema._allOf.Count > 0)
            {
                AllOfScope allOfScope = new AllOfScope(scope, context, depth);
                context.Scopes.Add(allOfScope);

                allOfScope.InitializeScopes(token, schema._allOf);
            }
            if (schema._anyOf != null && schema._anyOf.Count > 0)
            {
                AnyOfScope anyOfScope = new AnyOfScope(scope, context, depth);
                context.Scopes.Add(anyOfScope);

                anyOfScope.InitializeScopes(token, schema._anyOf);
            }
            if (schema._oneOf != null && schema._oneOf.Count > 0)
            {
                OneOfScope oneOfScope = new OneOfScope(scope, context, depth);
                context.Scopes.Add(oneOfScope);

                oneOfScope.InitializeScopes(token, schema._oneOf);
            }
            if (schema.Not != null)
            {
                NotScope notScope = new NotScope(scope, context, depth);
                context.Scopes.Add(notScope);

                notScope.InitializeScopes(token, Enumerable.Repeat(schema.Not, 1));
            }

            return(scope);
        }
        public static SchemaScope CreateTokenScope(JsonToken token, JSchema schema, ContextBase context, Scope parent, int depth)
        {
            SchemaScope scope;

            switch (token)
            {
                case JsonToken.StartObject:
                    var objectScope = new ObjectScope(context, parent, depth, schema);
                    context.Scopes.Add(objectScope);

                    objectScope.InitializeScopes(token);

                    scope = objectScope;
                    break;
                case JsonToken.StartArray:
                case JsonToken.StartConstructor:
                    scope = new ArrayScope(context, parent, depth, schema);
                    context.Scopes.Add(scope);
                    break;
                default:
                    scope = new PrimativeScope(context, parent, depth, schema);
                    context.Scopes.Add(scope);
                    break;
            }

            if (schema._allOf != null && schema._allOf.Count > 0)
            {
                AllOfScope allOfScope = new AllOfScope(scope, context, depth);
                context.Scopes.Add(allOfScope);

                allOfScope.InitializeScopes(token, schema._allOf);
            }
            if (schema._anyOf != null && schema._anyOf.Count > 0)
            {
                AnyOfScope anyOfScope = new AnyOfScope(scope, context, depth);
                context.Scopes.Add(anyOfScope);

                anyOfScope.InitializeScopes(token, schema._anyOf);
            }
            if (schema._oneOf != null && schema._oneOf.Count > 0)
            {
                OneOfScope oneOfScope = new OneOfScope(scope, context, depth);
                context.Scopes.Add(oneOfScope);

                oneOfScope.InitializeScopes(token, schema._oneOf);
            }
            if (schema.Not != null)
            {
                NotScope notScope = new NotScope(scope, context, depth);
                context.Scopes.Add(notScope);

                notScope.InitializeScopes(token, Enumerable.Repeat(schema.Not, 1));
            }

            return scope;
        }
Пример #3
0
        public static SchemaScope CreateTokenScope(JsonToken token, JSchema schema, ContextBase context, SchemaScope parent, int depth)
        {
            SchemaScope scope;

            switch (token)
            {
            case JsonToken.StartObject:
                ObjectScope objectScope = context.Validator.GetCachedScope <ObjectScope>(ScopeType.Object);
                if (objectScope == null)
                {
                    objectScope = new ObjectScope();
                }
                objectScope.Initialize(context, parent, depth, schema);
                context.Scopes.Add(objectScope);

                objectScope.InitializeScopes(token);

                scope = objectScope;
                break;

            case JsonToken.StartArray:
            case JsonToken.StartConstructor:
                ArrayScope arrayScope = context.Validator.GetCachedScope <ArrayScope>(ScopeType.Array);
                if (arrayScope == null)
                {
                    arrayScope = new ArrayScope();
                }
                arrayScope.Initialize(context, parent, depth, schema);

                context.Scopes.Add(arrayScope);
                scope = arrayScope;
                break;

            default:
                PrimativeScope primativeScope = context.Validator.GetCachedScope <PrimativeScope>(ScopeType.Primitive);
                if (primativeScope == null)
                {
                    primativeScope = new PrimativeScope();
                }
                primativeScope.Initialize(context, parent, depth, schema);

                scope = primativeScope;
                context.Scopes.Add(scope);
                break;
            }

            if (!schema._allOf.IsNullOrEmpty())
            {
                AllOfScope allOfScope = context.Validator.GetCachedScope <AllOfScope>(ScopeType.AllOf);
                if (allOfScope == null)
                {
                    allOfScope = new AllOfScope();
                }
                allOfScope.Initialize(context, scope, depth, ScopeType.AllOf);
                context.Scopes.Add(allOfScope);

                allOfScope.InitializeScopes(token, schema._allOf.GetInnerList());
            }
            if (!schema._anyOf.IsNullOrEmpty())
            {
                AnyOfScope anyOfScope = context.Validator.GetCachedScope <AnyOfScope>(ScopeType.AnyOf);
                if (anyOfScope == null)
                {
                    anyOfScope = new AnyOfScope();
                }
                anyOfScope.Initialize(context, scope, depth, ScopeType.AnyOf);
                context.Scopes.Add(anyOfScope);

                anyOfScope.InitializeScopes(token, schema._anyOf.GetInnerList());
            }
            if (!schema._oneOf.IsNullOrEmpty())
            {
                OneOfScope oneOfScope = context.Validator.GetCachedScope <OneOfScope>(ScopeType.OneOf);
                if (oneOfScope == null)
                {
                    oneOfScope = new OneOfScope();
                }
                oneOfScope.Initialize(context, scope, depth, ScopeType.OneOf);
                context.Scopes.Add(oneOfScope);

                oneOfScope.InitializeScopes(token, schema._oneOf.GetInnerList());
            }
            if (schema.Not != null)
            {
                NotScope notScope = context.Validator.GetCachedScope <NotScope>(ScopeType.Not);
                if (notScope == null)
                {
                    notScope = new NotScope();
                }
                notScope.Initialize(context, scope, depth, ScopeType.Not);
                context.Scopes.Add(notScope);

                notScope.InitializeScopes(token, new List <JSchema> {
                    schema.Not
                });
            }

            return(scope);
        }
Пример #4
0
        public static SchemaScope CreateTokenScope(JsonToken token, JSchema schema, ContextBase context, SchemaScope parent, int depth)
        {
            SchemaScope scope;

            switch (token)
            {
            case JsonToken.StartObject:
                ObjectScope objectScope = context.Validator.GetCachedScope <ObjectScope>(ScopeType.Object);
                if (objectScope == null)
                {
                    objectScope = new ObjectScope();
                }
                objectScope.Initialize(context, parent, depth, schema);
                context.Scopes.Add(objectScope);

                objectScope.InitializeScopes(token);

                scope = objectScope;
                break;

            case JsonToken.StartArray:
            case JsonToken.StartConstructor:
                ArrayScope arrayScope = context.Validator.GetCachedScope <ArrayScope>(ScopeType.Array);
                if (arrayScope == null)
                {
                    arrayScope = new ArrayScope();
                }
                arrayScope.Initialize(context, parent, depth, schema);

                context.Scopes.Add(arrayScope);
                scope = arrayScope;
                break;

            default:
                PrimativeScope primativeScope = context.Validator.GetCachedScope <PrimativeScope>(ScopeType.Primitive);
                if (primativeScope == null)
                {
                    primativeScope = new PrimativeScope();
                }
                primativeScope.Initialize(context, parent, depth, schema);

                scope = primativeScope;
                context.Scopes.Add(scope);
                break;
            }

            if (!schema._allOf.IsNullOrEmpty())
            {
                AllOfScope allOfScope = context.Validator.GetCachedScope <AllOfScope>(ScopeType.AllOf);
                if (allOfScope == null)
                {
                    allOfScope = new AllOfScope();
                }
                allOfScope.Initialize(context, scope, depth, ScopeType.AllOf);
                scope.AddChildScope(allOfScope);

                allOfScope.InitializeScopes(token, schema._allOf.GetInnerList(), context.Scopes.Count - 1);
            }
            if (!schema._anyOf.IsNullOrEmpty())
            {
                AnyOfScope anyOfScope = context.Validator.GetCachedScope <AnyOfScope>(ScopeType.AnyOf);
                if (anyOfScope == null)
                {
                    anyOfScope = new AnyOfScope();
                }
                anyOfScope.Initialize(context, scope, depth, ScopeType.AnyOf);
                scope.AddChildScope(anyOfScope);

                anyOfScope.InitializeScopes(token, schema._anyOf.GetInnerList(), context.Scopes.Count - 1);
            }
            if (!schema._oneOf.IsNullOrEmpty())
            {
                OneOfScope oneOfScope = context.Validator.GetCachedScope <OneOfScope>(ScopeType.OneOf);
                if (oneOfScope == null)
                {
                    oneOfScope = new OneOfScope();
                }
                oneOfScope.Initialize(context, scope, depth, ScopeType.OneOf);
                scope.AddChildScope(oneOfScope);

                oneOfScope.InitializeScopes(token, schema._oneOf.GetInnerList(), context.Scopes.Count - 1);
            }
            if (schema.Not != null)
            {
                NotScope notScope = context.Validator.GetCachedScope <NotScope>(ScopeType.Not);
                if (notScope == null)
                {
                    notScope = new NotScope();
                }
                notScope.Initialize(context, scope, depth, ScopeType.Not);
                scope.AddChildScope(notScope);

                notScope.InitializeScopes(token, new List <JSchema> {
                    schema.Not
                }, context.Scopes.Count - 1);
            }
            // only makes sense to eval if/then/else when there is an if and either a then or a else
            if (schema.If != null && (schema.Then != null || schema.Else != null))
            {
                IfThenElseScope ifThenElseScope = context.Validator.GetCachedScope <IfThenElseScope>(ScopeType.IfThenElse);
                if (ifThenElseScope == null)
                {
                    ifThenElseScope = new IfThenElseScope();
                }
                ifThenElseScope.Initialize(context, scope, depth, ScopeType.IfThenElse);
                scope.AddChildScope(ifThenElseScope);

                ifThenElseScope.If = schema.If;
                if (schema.Then != null)
                {
                    ifThenElseScope.Then        = schema.Then;
                    ifThenElseScope.ThenContext = ConditionalContext.Create(context);
                }
                if (schema.Else != null)
                {
                    ifThenElseScope.Else        = schema.Else;
                    ifThenElseScope.ElseContext = ConditionalContext.Create(context);
                }

                ifThenElseScope.InitializeScopes(token, context.Scopes.Count - 1);
            }

            return(scope);
        }