public void Initialize(ContextBase context, SchemaScope parent, int initialDepth, ScopeType type) { base.Initialize(context, parent, initialDepth, type); ParentSchemaScope = parent; ConditionalContext = ConditionalContext.Create(context); }
protected void Initialize(ContextBase context, Scope parent, int initialDepth, ScopeType type) { Context = context; Parent = parent; InitialDepth = initialDepth; Type = type; Complete = false; }
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 ObjectScope(ContextBase context, Scope parent, int initialDepth, JSchema schema) : base(context, parent, initialDepth, schema) { if (schema._required != null) _requiredProperties = schema._required.ToList(); if (schema._dependencies != null && schema._dependencies.Count > 0) { _readProperties = new List<string>(); if (schema._dependencies.Values.OfType<JSchema>().Any()) _dependencyScopes = new Dictionary<string, SchemaScope>(); } }
public void Initialize(ContextBase context, Scope parent, int initialDepth, JSchema schema) { Initialize(context, parent, initialDepth, ScopeType.Object); InitializeSchema(schema); _propertyCount = 0; _currentPropertyName = null; if (!schema._required.IsNullOrEmpty()) { if (_requiredProperties != null) { _requiredProperties.Clear(); } else { _requiredProperties = new List<string>(schema._required.Count); } foreach (string required in schema._required) { _requiredProperties.Add(required); } } if (!schema._dependencies.IsNullOrEmpty()) { if (_readProperties != null) { _readProperties.Clear(); } else { _readProperties = new List<string>(); } if (schema._dependencies.HasSchemas) { if (_dependencyScopes != null) { _dependencyScopes.Clear(); } else { _dependencyScopes = new Dictionary<string, SchemaScope>(StringComparer.Ordinal); } } } }
public void Initialize(ContextBase context, Scope parent, int initialDepth, JSchema schema) { Initialize(context, parent, initialDepth, ScopeType.Array); InitializeSchema(schema); _index = -1; if (schema.UniqueItems) { if (_uniqueArrayItems != null) { _uniqueArrayItems.Clear(); } else { _uniqueArrayItems = new List<JToken>(); } } }
public ObjectScope(ContextBase context, Scope parent, int initialDepth, JSchema schema) : base(context, parent, initialDepth, schema) { if (schema._required != null) _requiredProperties = schema._required.ToList(); if (schema._dependencies != null && schema._dependencies.Count > 0) { _readProperties = new List<string>(); foreach (KeyValuePair<string, object> dependency in schema._dependencies) { if (dependency.Value is JSchema) { _dependencyScopes = new Dictionary<string, SchemaScope>(StringComparer.Ordinal); break; } } } }
protected Scope(ContextBase context, Scope parent, int initialDepth) { Context = context; Parent = parent; InitialDepth = initialDepth; }
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(), 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); context.Scopes.Add(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); context.Scopes.Add(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); context.Scopes.Add(notScope); notScope.InitializeScopes(token, new List <JSchema> { schema.Not }, context.Scopes.Count - 1); } return(scope); }
public void Initialize(ContextBase context, SchemaScope parent, int initialDepth, JSchema schema) { Initialize(context, parent, initialDepth, ScopeType.Object); InitializeSchema(schema); _propertyCount = 0; _currentPropertyName = null; if (!schema._required.IsNullOrEmpty()) { if (_requiredProperties != null) { _requiredProperties.Clear(); } else { _requiredProperties = new List <string>(schema._required.Count); } foreach (string required in schema._required) { _requiredProperties.Add(required); } } // Need to track the properties read when: // - Schema has dependencies or, // - Need to validate unevaluated properties if (HasDependencies()) { if (_readProperties != null) { _readProperties.Clear(); } else { _readProperties = new List <string>(); } if ((schema._dependencies != null && schema._dependencies.HasSchemas) || !schema._dependentSchemas.IsNullOrEmpty()) { if (_dependencyScopes != null) { _dependencyScopes.Clear(); } else { _dependencyScopes = new Dictionary <string, SchemaScope>(StringComparer.Ordinal); } } } if (ShouldValidateUnevaluated()) { if (_unevaluatedScopes != null) { _unevaluatedScopes.Clear(); } else { _unevaluatedScopes = new Dictionary <string, UnevaluatedContext>(StringComparer.Ordinal); } } }
protected ConditionalScope(ContextBase context, SchemaScope parent, int initialDepth) : base(context, parent, initialDepth) { ParentSchemaScope = parent; ConditionalContext = ConditionalContext.Create(context); }
public void Initialize(ContextBase context, Scope parent, int initialDepth, JSchema schema) { Initialize(context, parent, initialDepth, ScopeType.Primitive); InitializeSchema(schema); }
protected SchemaScope CreateScopesAndEvaluateToken(JsonToken token, object?value, int depth, JSchema schema, SchemaScope?parent, ContextBase context) { int startCount = Context.Scopes.Count; SchemaScope createdScope = CreateTokenScope(token, schema, context, parent, depth); int start = Context.Scopes.Count - 1; int end = startCount; for (int i = start; i >= end; i--) { Scope newScope = Context.Scopes[i]; newScope.EvaluateToken(token, value, depth); } return(createdScope); }
public OneOfScope(SchemaScope parent, ContextBase context, int depth) : base(context, parent, depth) { }
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); 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.Ref != null) { RefScope?refScope = context.Validator.GetCachedScope <RefScope>(ScopeType.Ref); if (refScope == null) { refScope = new RefScope(); } refScope.Initialize(context, scope, depth, ScopeType.Ref); scope.AddChildScope(refScope); refScope.InitializeScopes(token, new List <JSchema> { schema.Ref }, context.Scopes.Count - 1); } 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 = scope.CreateConditionalContext(); } if (schema.Else != null) { ifThenElseScope.Else = schema.Else; ifThenElseScope.ElseContext = scope.CreateConditionalContext(); } ifThenElseScope.InitializeScopes(token, context.Scopes.Count - 1); } if (!schema._dependencies.IsNullOrEmpty()) { foreach (KeyValuePair <string, object> dependency in schema._dependencies.GetInnerDictionary()) { if (dependency.Value is JSchema dependencySchema) { CreateDependentSchemaScope(token, context, depth, scope, dependency.Key, dependencySchema); } } } if (!schema._dependentSchemas.IsNullOrEmpty()) { foreach (KeyValuePair <string, JSchema> dependency in schema._dependentSchemas) { CreateDependentSchemaScope(token, context, depth, scope, dependency.Key, dependency.Value); } } return(scope); }
protected void CreateScopesAndEvaluateToken(JsonToken token, object value, int depth, JSchema schema, ContextBase context) { int startCount = Context.Scopes.Count; CreateTokenScope(token, schema, context, this, depth); int start = Context.Scopes.Count - 1; int end = startCount; for (int i = start; i >= end; i--) { Scope newScope = Context.Scopes[i]; newScope.EvaluateToken(token, value, depth); } }
public static ConditionalContext Create(ContextBase context) { return(new ConditionalContext(context.Validator)); }
public static ConditionalContext Create(ContextBase context) { return new ConditionalContext(context.Validator); }
public ArrayScope(ContextBase context, Scope parent, int initialDepth, JSchema schema) : base(context, parent, initialDepth, schema) { if (schema.UniqueItems) _uniqueArrayItems = new List<JToken>(); }
protected SchemaScope(ContextBase context, Scope parent, int initialDepth, JSchema schema) : base(context, parent, initialDepth) { Schema = schema; IsValid = true; }
public PrimativeScope(ContextBase context, Scope parent, int initialDepth, JSchema schema) : base(context, parent, initialDepth, schema) { }