private void ValidateCurrentToken()
        {
            // first time validate has been called. build model
            if (_model == null)
            {
                JsonSchemaModelBuilder builder = new JsonSchemaModelBuilder();
                _model = builder.Build(_schema);

                if (!JsonTokenUtils.IsStartToken(_reader.TokenType))
                {
                    Push(new SchemaScope(JTokenType.None, CurrentMemberSchemas));
                }
            }

            switch (_reader.TokenType)
            {
            case JsonToken.StartObject:
                ProcessValue();
                IList <JsonSchemaModel> objectSchemas = CurrentMemberSchemas.Where(ValidateObject).ToList();
                Push(new SchemaScope(JTokenType.Object, objectSchemas));
                WriteToken(CurrentSchemas);
                break;

            case JsonToken.StartArray:
                ProcessValue();
                IList <JsonSchemaModel> arraySchemas = CurrentMemberSchemas.Where(ValidateArray).ToList();
                Push(new SchemaScope(JTokenType.Array, arraySchemas));
                WriteToken(CurrentSchemas);
                break;

            case JsonToken.StartConstructor:
                ProcessValue();
                Push(new SchemaScope(JTokenType.Constructor, null));
                WriteToken(CurrentSchemas);
                break;

            case JsonToken.PropertyName:
                WriteToken(CurrentSchemas);
                foreach (JsonSchemaModel schema in CurrentSchemas)
                {
                    ValidatePropertyName(schema);
                }
                break;

            case JsonToken.Raw:
                ProcessValue();
                break;

            case JsonToken.Integer:
                ProcessValue();
                WriteToken(CurrentMemberSchemas);
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateInteger(schema);
                }
                break;

            case JsonToken.Float:
                ProcessValue();
                WriteToken(CurrentMemberSchemas);
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateFloat(schema);
                }
                break;

            case JsonToken.String:
                ProcessValue();
                WriteToken(CurrentMemberSchemas);
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateString(schema);
                }
                break;

            case JsonToken.Boolean:
                ProcessValue();
                WriteToken(CurrentMemberSchemas);
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateBoolean(schema);
                }
                break;

            case JsonToken.Null:
                ProcessValue();
                WriteToken(CurrentMemberSchemas);
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateNull(schema);
                }
                break;

            case JsonToken.EndObject:
                WriteToken(CurrentSchemas);
                foreach (JsonSchemaModel schema in CurrentSchemas)
                {
                    ValidateEndObject(schema);
                }
                Pop();
                break;

            case JsonToken.EndArray:
                WriteToken(CurrentSchemas);
                foreach (JsonSchemaModel schema in CurrentSchemas)
                {
                    ValidateEndArray(schema);
                }
                Pop();
                break;

            case JsonToken.EndConstructor:
                WriteToken(CurrentSchemas);
                Pop();
                break;

            case JsonToken.Undefined:
            case JsonToken.Date:
            case JsonToken.Bytes:
                // these have no equivalent in JSON schema
                WriteToken(CurrentMemberSchemas);
                break;

            case JsonToken.None:
                // no content, do nothing
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        private void ValidateCurrentToken()
        {
            if (_model == null)
            {
                JsonSchemaModelBuilder jsonSchemaModelBuilder = new JsonSchemaModelBuilder();
                _model = jsonSchemaModelBuilder.Build(_schema);
            }
            switch (_reader.TokenType)
            {
            case JsonToken.StartObject:
            {
                ProcessValue();
                IList <JsonSchemaModel> schemas2 = CurrentMemberSchemas.Where(ValidateObject).ToList();
                Push(new SchemaScope(JTokenType.Object, schemas2));
                break;
            }

            case JsonToken.StartArray:
            {
                ProcessValue();
                IList <JsonSchemaModel> schemas = CurrentMemberSchemas.Where(ValidateArray).ToList();
                Push(new SchemaScope(JTokenType.Array, schemas));
                break;
            }

            case JsonToken.StartConstructor:
                Push(new SchemaScope(JTokenType.Constructor, null));
                break;

            case JsonToken.PropertyName:
                foreach (JsonSchemaModel currentSchema in CurrentSchemas)
                {
                    ValidatePropertyName(currentSchema);
                }
                break;

            case JsonToken.Raw:
                break;

            case JsonToken.Integer:
                ProcessValue();
                foreach (JsonSchemaModel currentMemberSchema in CurrentMemberSchemas)
                {
                    ValidateInteger(currentMemberSchema);
                }
                break;

            case JsonToken.Float:
                ProcessValue();
                foreach (JsonSchemaModel currentMemberSchema2 in CurrentMemberSchemas)
                {
                    ValidateFloat(currentMemberSchema2);
                }
                break;

            case JsonToken.String:
                ProcessValue();
                foreach (JsonSchemaModel currentMemberSchema3 in CurrentMemberSchemas)
                {
                    ValidateString(currentMemberSchema3);
                }
                break;

            case JsonToken.Boolean:
                ProcessValue();
                foreach (JsonSchemaModel currentMemberSchema4 in CurrentMemberSchemas)
                {
                    ValidateBoolean(currentMemberSchema4);
                }
                break;

            case JsonToken.Null:
                ProcessValue();
                foreach (JsonSchemaModel currentMemberSchema5 in CurrentMemberSchemas)
                {
                    ValidateNull(currentMemberSchema5);
                }
                break;

            case JsonToken.Undefined:
                break;

            case JsonToken.EndObject:
                foreach (JsonSchemaModel currentSchema2 in CurrentSchemas)
                {
                    ValidateEndObject(currentSchema2);
                }
                Pop();
                break;

            case JsonToken.EndArray:
                foreach (JsonSchemaModel currentSchema3 in CurrentSchemas)
                {
                    ValidateEndArray(currentSchema3);
                }
                Pop();
                break;

            case JsonToken.EndConstructor:
                Pop();
                break;

            case JsonToken.Date:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 3
0
        private void ValidateCurrentToken()
        {
            // first time validate has been called. build model
            if (_model == null)
            {
                JsonSchemaModelBuilder builder = new JsonSchemaModelBuilder();
                _model = builder.Build(_schema);
            }

            //ValidateValueToken();

            switch (_reader.TokenType)
            {
            case JsonToken.StartObject:
                ProcessValue();
                IList <JsonSchemaModel> objectSchemas = CurrentMemberSchemas.Where(ValidateObject).ToList();
                Push(new SchemaScope(JTokenType.Object, objectSchemas));
                break;

            case JsonToken.StartArray:
                ProcessValue();
                IList <JsonSchemaModel> arraySchemas = CurrentMemberSchemas.Where(ValidateArray).ToList();
                Push(new SchemaScope(JTokenType.Array, arraySchemas));
                break;

            case JsonToken.StartConstructor:
                Push(new SchemaScope(JTokenType.Constructor, null));
                break;

            case JsonToken.PropertyName:
                foreach (JsonSchemaModel schema in CurrentSchemas)
                {
                    ValidatePropertyName(schema);
                }
                break;

            case JsonToken.Raw:
                break;

            case JsonToken.Integer:
                ProcessValue();
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateInteger(schema);
                }
                break;

            case JsonToken.Float:
                ProcessValue();
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateFloat(schema);
                }
                break;

            case JsonToken.String:
                ProcessValue();
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateString(schema);
                }
                break;

            case JsonToken.Boolean:
                ProcessValue();
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateBoolean(schema);
                }
                break;

            case JsonToken.Null:
                ProcessValue();
                foreach (JsonSchemaModel schema in CurrentMemberSchemas)
                {
                    ValidateNull(schema);
                }
                break;

            case JsonToken.Undefined:
                break;

            case JsonToken.EndObject:
                foreach (JsonSchemaModel schema in CurrentSchemas)
                {
                    ValidateEndObject(schema);
                }
                Pop();
                break;

            case JsonToken.EndArray:
                foreach (JsonSchemaModel schema in CurrentSchemas)
                {
                    ValidateEndArray(schema);
                }
                Pop();
                break;

            case JsonToken.EndConstructor:
                Pop();
                break;

            case JsonToken.Date:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 4
0
        private void ValidateCurrentToken()
        {
            // first time validate has been called.
            if (_stack.Count == 0)
            {
                if (!JsonWriter.IsStartToken(_reader.TokenType))
                    Push(new SchemaScope(JTokenType.None, CurrentMemberSchemas));
            }

            IList<SchemaReport> tokenSchemas;

            switch (_reader.TokenType)
            {
                case JsonToken.StartObject:
                    ProcessValue();
                    tokenSchemas = CurrentMemberSchemas.Where(ValidateObject).ToList();
                    Push(new SchemaScope(JTokenType.Object, tokenSchemas));
                    WriteToken(tokenSchemas);
                    break;
                case JsonToken.StartArray:
                    ProcessValue();
                    tokenSchemas = CurrentMemberSchemas.Where(ValidateArray).ToList();
                    Push(new SchemaScope(JTokenType.Array, tokenSchemas));
                    WriteToken(tokenSchemas);
                    break;
                case JsonToken.StartConstructor:
                    ProcessValue();
                    Push(new SchemaScope(JTokenType.Constructor, null));
                    WriteToken(CurrentSchemas);
                    break;
                case JsonToken.PropertyName:
                    WriteToken(CurrentSchemas);
                    foreach (SchemaReport report in CurrentSchemas)
                    {
                        ValidatePropertyName(report);
                    }
                    break;
                case JsonToken.Raw:
                    ProcessValue();
                    break;
                case JsonToken.Integer:
                    ProcessValue();
                    tokenSchemas = CurrentMemberSchemas;
                    WriteToken(tokenSchemas);
                    foreach (SchemaReport report in tokenSchemas)
                    {
                        ValidateInteger(report);
                    }
                    ValidateConditionalResults(tokenSchemas);
                    break;
                case JsonToken.Float:
                    ProcessValue();
                    tokenSchemas = CurrentMemberSchemas;
                    WriteToken(tokenSchemas);
                    foreach (SchemaReport report in tokenSchemas)
                    {
                        ValidateFloat(report);
                    }
                    ValidateConditionalResults(tokenSchemas);
                    break;
                case JsonToken.String:
                    ProcessValue();
                    tokenSchemas = CurrentMemberSchemas;
                    WriteToken(tokenSchemas);
                    foreach (SchemaReport report in tokenSchemas)
                    {
                        ValidateString(report);
                    }
                    ValidateConditionalResults(tokenSchemas);
                    break;
                case JsonToken.Boolean:
                    ProcessValue();
                    tokenSchemas = CurrentMemberSchemas;
                    WriteToken(tokenSchemas);
                    foreach (SchemaReport report in tokenSchemas)
                    {
                        ValidateBoolean(report);
                    }
                    ValidateConditionalResults(tokenSchemas);
                    break;
                case JsonToken.Null:
                    ProcessValue();
                    tokenSchemas = CurrentMemberSchemas;
                    WriteToken(tokenSchemas);
                    foreach (SchemaReport report in tokenSchemas)
                    {
                        ValidateNull(report);
                    }
                    ValidateConditionalResults(tokenSchemas);
                    break;
                case JsonToken.EndObject:
                    WriteToken(CurrentSchemas);
                    foreach (SchemaReport report in CurrentSchemas)
                    {
                        ValidateEndObject(report);
                    }
                    ValidateConditionalResults(CurrentSchemas);
                    Pop();
                    break;
                case JsonToken.EndArray:
                    WriteToken(CurrentSchemas);
                    foreach (SchemaReport report in CurrentSchemas)
                    {
                        ValidateEndArray(report);
                    }
                    ValidateConditionalResults(CurrentSchemas);
                    Pop();
                    break;
                case JsonToken.EndConstructor:
                    WriteToken(CurrentSchemas);
                    Pop();
                    break;
                case JsonToken.Undefined:
                case JsonToken.Date:
                case JsonToken.Bytes:
                    // these have no equivalent in JSON schema
                    WriteToken(CurrentMemberSchemas);
                    break;
                case JsonToken.None:
                    // no content, do nothing
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }