Beispiel #1
0
        private JsonSchemaType?method_13(JToken jtoken_0)
        {
            JTokenType type = jtoken_0.Type;

            if (type != JTokenType.Array)
            {
                if (type != JTokenType.String)
                {
                    throw JsonException.smethod_0(jtoken_0, jtoken_0.Path, "Expected array or JSON schema type string token, got {0}.".smethod_0(CultureInfo.InvariantCulture, jtoken_0.Type));
                }
                return(new JsonSchemaType?(smethod_0((string)jtoken_0)));
            }
            JsonSchemaType?nullable = new JsonSchemaType?(JsonSchemaType.None);

            foreach (JToken token in (IEnumerable <JToken>)jtoken_0)
            {
                if (token.Type != JTokenType.String)
                {
                    throw JsonException.smethod_0(token, token.Path, "Exception JSON schema type string token, got {0}.".smethod_0(CultureInfo.InvariantCulture, jtoken_0.Type));
                }
                JsonSchemaType?nullable2 = nullable;
                JsonSchemaType type2     = smethod_0((string)token);
                nullable = nullable2.HasValue ? new JsonSchemaType?(((JsonSchemaType)nullable2.GetValueOrDefault()) | type2) : null;
            }
            return(nullable);
        }
Beispiel #2
0
        internal static bool HasFlag(JsonSchemaType?value, JsonSchemaType flag)
        {
            if (!value.HasValue)
            {
                return(true);
            }
            JsonSchemaType?nullable1       = value;
            JsonSchemaType jsonSchemaType1 = flag;
            JsonSchemaType?nullable2       = nullable1.HasValue ? new JsonSchemaType?(nullable1.GetValueOrDefault() & jsonSchemaType1) : new JsonSchemaType?();
            JsonSchemaType jsonSchemaType2 = flag;

            if ((nullable2.GetValueOrDefault() == jsonSchemaType2 ? (nullable2.HasValue ? 1 : 0) : 0) != 0)
            {
                return(true);
            }
            if (flag == JsonSchemaType.Integer)
            {
                nullable1 = value;
                nullable2 = nullable1.HasValue ? new JsonSchemaType?(nullable1.GetValueOrDefault() & JsonSchemaType.Float) : new JsonSchemaType?();
                JsonSchemaType jsonSchemaType3 = JsonSchemaType.Float;
                if ((nullable2.GetValueOrDefault() == jsonSchemaType3 ? (nullable2.HasValue ? 1 : 0) : 0) != 0)
                {
                    return(true);
                }
            }
            return(false);
        }
        private void ValidateInEnumAndNotDisallowed(JsonSchemaModel schema)
        {
            if (schema == null)
            {
                return;
            }

            JToken value = new JValue(_reader.Value);

            if (schema.Enum != null)
            {
                StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
                value.WriteTo(new JsonTextWriter(sw));

                if (!schema.Enum.ContainsValue(value, new JTokenEqualityComparer()))
                {
                    RaiseError("Value {0} is not defined in enum.".FormatWith(CultureInfo.InvariantCulture, sw.ToString()),
                               schema);
                }
            }

            JsonSchemaType?currentNodeType = GetCurrentNodeSchemaType();

            if (currentNodeType != null)
            {
                if (JsonSchemaGenerator.HasFlag(schema.Disallow, currentNodeType.Value))
                {
                    RaiseError("Type {0} is disallowed.".FormatWith(CultureInfo.InvariantCulture, currentNodeType), schema);
                }
            }
        }
Beispiel #4
0
        private JsonSchemaType?ProcessType(JToken token)
        {
            switch (token.Type)
            {
            case JTokenType.Array:
                JsonSchemaType?nullable1 = new JsonSchemaType?(JsonSchemaType.None);
                foreach (JToken jtoken in (IEnumerable <JToken>)token)
                {
                    if (jtoken.Type != JTokenType.String)
                    {
                        throw JsonException.Create((IJsonLineInfo)jtoken, jtoken.Path,
                                                   "Expected JSON schema type string token, got {0}.".FormatWith(
                                                       (IFormatProvider)CultureInfo.InvariantCulture, (object)token.Type));
                    }
                    JsonSchemaType?nullable2      = nullable1;
                    JsonSchemaType jsonSchemaType = JsonSchemaBuilder.MapType((string)jtoken);
                    nullable1 = nullable2.HasValue
              ? new JsonSchemaType?(nullable2.GetValueOrDefault() | jsonSchemaType)
              : new JsonSchemaType?();
                }

                return(nullable1);

            case JTokenType.String:
                return(new JsonSchemaType?(JsonSchemaBuilder.MapType((string)token)));

            default:
                throw JsonException.Create((IJsonLineInfo)token, token.Path,
                                           "Expected array or JSON schema type string token, got {0}.".FormatWith(
                                               (IFormatProvider)CultureInfo.InvariantCulture, (object)token.Type));
            }
        }
Beispiel #5
0
        private JsonSchemaType?ProcessType()
        {
            switch (this._reader.TokenType)
            {
            case JsonToken.StartArray:
                JsonSchemaType?nullable1 = new JsonSchemaType?(JsonSchemaType.None);
                while (this._reader.Read() && this._reader.TokenType != JsonToken.EndArray)
                {
                    if (this._reader.TokenType != JsonToken.String)
                    {
                        throw JsonReaderException.Create(this._reader, StringUtils.FormatWith("Exception JSON schema type string token, got {0}.", (IFormatProvider)CultureInfo.InvariantCulture, (object)this._reader.TokenType));
                    }
                    JsonSchemaType?nullable2      = nullable1;
                    JsonSchemaType jsonSchemaType = JsonSchemaBuilder.MapType(this._reader.Value.ToString());
                    nullable1 = nullable2.HasValue ? new JsonSchemaType?(nullable2.GetValueOrDefault() | jsonSchemaType) : new JsonSchemaType?();
                }
                return(nullable1);

            case JsonToken.String:
                return(new JsonSchemaType?(JsonSchemaBuilder.MapType(this._reader.Value.ToString())));

            default:
                throw JsonReaderException.Create(this._reader, StringUtils.FormatWith("Expected array or JSON schema type string token, got {0}.", (IFormatProvider)CultureInfo.InvariantCulture, (object)this._reader.TokenType));
            }
        }
        private JsonSchemaType?ProcessType()
        {
            switch (_reader.TokenType)
            {
            case JsonToken.String:
                return(MapType(_reader.Value.ToString()));

            case JsonToken.StartArray:
            {
                JsonSchemaType?result = JsonSchemaType.None;
                while (_reader.Read() && _reader.TokenType != JsonToken.EndArray)
                {
                    if (_reader.TokenType != JsonToken.String)
                    {
                        throw new Exception("Exception JSON schema type string token, got {0}.".FormatWith(CultureInfo.InvariantCulture, _reader.TokenType));
                    }
                    result = ((!result.HasValue) ? null : new JsonSchemaType?(result.GetValueOrDefault() | MapType(_reader.Value.ToString())));
                }
                return(result);
            }

            default:
                throw new Exception("Expected array or JSON schema type string token, got {0}.".FormatWith(CultureInfo.InvariantCulture, _reader.TokenType));
            }
        }
Beispiel #7
0
        public static string ToJsonType(this JsonSchemaType?jsonSchemaType)
        {
            if (jsonSchemaType == null)
            {
                return("");
            }
            string jstString = jsonSchemaType.ToString();
            string splitJson = jstString.Split(',').Length > 1 ? jstString.Split(',')[0] : jstString;

            switch (splitJson)
            {
            case "Integer":
            case "Decimal":
                return("number");

            case "String":
                return("string");

            case "Object":
                return("object");

            default:
                return(splitJson);
            }
        }
Beispiel #8
0
        private void ValidateInEnumAndNotDisallowed(JsonSchemaModel schema)
        {
            if (schema == null)
            {
                return;
            }
            JToken jtoken = (JToken) new JValue(this._reader.Value);

            if (schema.Enum != null)
            {
                StringWriter stringWriter = new StringWriter((IFormatProvider)CultureInfo.InvariantCulture);
                jtoken.WriteTo((JsonWriter) new JsonTextWriter((TextWriter)stringWriter), new JsonConverter[0]);
                if (!CollectionUtils.ContainsValue <JToken>((IEnumerable <JToken>)schema.Enum, jtoken, (IEqualityComparer <JToken>) new JTokenEqualityComparer()))
                {
                    this.RaiseError(StringUtils.FormatWith("Value {0} is not defined in enum.", (IFormatProvider)CultureInfo.InvariantCulture, (object)stringWriter.ToString()), schema);
                }
            }
            JsonSchemaType?currentNodeSchemaType = this.GetCurrentNodeSchemaType();

            if (!currentNodeSchemaType.HasValue || !JsonSchemaGenerator.HasFlag(new JsonSchemaType?(schema.Disallow), currentNodeSchemaType.Value))
            {
                return;
            }
            this.RaiseError(StringUtils.FormatWith("Type {0} is disallowed.", (IFormatProvider)CultureInfo.InvariantCulture, (object)currentNodeSchemaType), schema);
        }
Beispiel #9
0
        private JsonSchemaType?ProcessType()
        {
            switch (_reader.TokenType)
            {
            case JsonToken.String:
                return(MapType(_reader.Value.ToString()));

            case JsonToken.StartArray:
                // ensure type is in blank state before ORing values
                JsonSchemaType?type = JsonSchemaType.None;

                while (_reader.Read() && _reader.TokenType != JsonToken.EndArray)
                {
                    if (_reader.TokenType != JsonToken.String)
                    {
                        throw new Exception("Exception JSON schema type string token, got {0}.".FormatWith(CultureInfo.InvariantCulture, _reader.TokenType));
                    }

                    type = type | MapType(_reader.Value.ToString());
                }

                return(type);

            default:
                throw new Exception("Expected array or JSON schema type string token, got {0}.".FormatWith(CultureInfo.InvariantCulture, _reader.TokenType));
            }
        }
        private JsonSchemaType?ProcessType()
        {
            JsonToken tokenType = this._reader.TokenType;

            if (tokenType == JsonToken.StartArray)
            {
                JsonSchemaType?result = new JsonSchemaType?(JsonSchemaType.None);
                while (this._reader.Read() && this._reader.TokenType != JsonToken.EndArray)
                {
                    if (this._reader.TokenType != JsonToken.String)
                    {
                        throw new Exception("Exception JSON schema type string token, got {0}.".FormatWith(CultureInfo.get_InvariantCulture(), new object[]
                        {
                            this._reader.TokenType
                        }));
                    }
                    result = ((!result.get_HasValue()) ? default(JsonSchemaType?) : new JsonSchemaType?(result.GetValueOrDefault() | JsonSchemaBuilder.MapType(this._reader.Value.ToString())));
                }
                return(result);
            }
            if (tokenType != JsonToken.String)
            {
                throw new Exception("Expected array or JSON schema type string token, got {0}.".FormatWith(CultureInfo.get_InvariantCulture(), new object[]
                {
                    this._reader.TokenType
                }));
            }
            return(new JsonSchemaType?(JsonSchemaBuilder.MapType(this._reader.Value.ToString())));
        }
Beispiel #11
0
        private void ValidateInEnumAndNotDisallowed(JsonSchemaModel schema)
        {
            if (schema == null)
            {
                return;
            }
            JToken jToken = new JValue(this._reader.Value);

            if (schema.Enum != null)
            {
                StringWriter stringWriter = new StringWriter(CultureInfo.get_InvariantCulture());
                jToken.WriteTo(new JsonTextWriter(stringWriter), new JsonConverter[0]);
                if (!schema.Enum.ContainsValue(jToken, new JTokenEqualityComparer()))
                {
                    this.RaiseError("Value {0} is not defined in enum.".FormatWith(CultureInfo.get_InvariantCulture(), new object[]
                    {
                        stringWriter.ToString()
                    }), schema);
                }
            }
            JsonSchemaType?currentNodeSchemaType = this.GetCurrentNodeSchemaType();

            if (currentNodeSchemaType.get_HasValue() && JsonSchemaGenerator.HasFlag(new JsonSchemaType?(schema.Disallow), currentNodeSchemaType.get_Value()))
            {
                this.RaiseError("Type {0} is disallowed.".FormatWith(CultureInfo.get_InvariantCulture(), new object[]
                {
                    currentNodeSchemaType
                }), schema);
            }
        }
Beispiel #12
0
        private JsonSchemaType?ProcessType(JToken token)
        {
            switch (token.Type)
            {
            case JTokenType.Array:
                // ensure type is in blank state before ORing values
                JsonSchemaType?type = JsonSchemaType.None;

                foreach (JToken typeToken in token)
                {
                    if (typeToken.Type != JTokenType.String)
                    {
                        throw JsonException.Create(typeToken, typeToken.Path, "Exception JSON schema type string token, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type));
                    }

                    type = type | MapType((string)typeToken);
                }

                return(type);

            case JTokenType.String:
                return(MapType((string)token));

            default:
                throw JsonException.Create(token, token.Path, "Expected array or JSON schema type string token, got {0}.".FormatWith(CultureInfo.InvariantCulture, token.Type));
            }
        }
Beispiel #13
0
        internal static bool HasFlag(JsonSchemaType?value, JsonSchemaType flag)
        {
            if (!value.HasValue)
            {
                return(true);
            }
            JsonSchemaType?nullable  = value;
            JsonSchemaType type      = flag;
            JsonSchemaType?nullable3 = nullable.HasValue ? new JsonSchemaType?(((JsonSchemaType)nullable.GetValueOrDefault()) & type) : null;
            JsonSchemaType @float    = flag;

            if ((((JsonSchemaType)nullable3.GetValueOrDefault()) == @float) ? nullable3.HasValue : false)
            {
                return(true);
            }
            if (flag == JsonSchemaType.Integer)
            {
                nullable3 = ((JsonSchemaType)value) & JsonSchemaType.Float;
                @float    = JsonSchemaType.Float;
                if ((((JsonSchemaType)nullable3.GetValueOrDefault()) == @float) ? nullable3.HasValue : false)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #14
0
 internal static bool HasFlag(JsonSchemaType?value, JsonSchemaType flag)
 {
     if (!value.HasValue)
     {
         return(true);
     }
     return((value & flag) == flag);
 }
        internal static bool HasFlag(JsonSchemaType?value, JsonSchemaType flag)
        {
            if (!value.HasValue)
            {
                return(true);
            }
            bool flag2 = (value & flag) == flag;

            return(flag2 || (flag == JsonSchemaType.Integer && (value & JsonSchemaType.Float) == JsonSchemaType.Float));
        }
        internal static bool HasFlag(JsonSchemaType?value, JsonSchemaType flag)
        {
            if (!value.get_HasValue())
            {
                return(true);
            }
            JsonSchemaType?jsonSchemaType = (!value.get_HasValue()) ? default(JsonSchemaType?) : new JsonSchemaType?(value.GetValueOrDefault() & flag);

            return(jsonSchemaType.GetValueOrDefault() == flag && jsonSchemaType.get_HasValue());
        }
        internal static bool HasFlag(JsonSchemaType?value, JsonSchemaType flag)
        {
            // default value is Any
            if (value == null)
            {
                return(true);
            }

            return((value & flag) == flag);
        }
Beispiel #18
0
        private static void smethod_1(Class120 class120_2, JsonSchema jsonSchema_0)
        {
            bool?required;
            bool?exclusiveMinimum;
            bool?exclusiveMaximum;

            if (!class120_2.Boolean_0)
            {
                required = jsonSchema_0.Required;
            }
            class120_2.Boolean_0 = required.HasValue;
            JsonSchemaType?type = jsonSchema_0.Type;

            class120_2.JsonSchemaType_0 &= (JsonSchemaType)(type.HasValue ? type.GetValueOrDefault() : JsonSchemaType.Any);
            class120_2.Nullable_0        = Class192.smethod_3(class120_2.Nullable_0, jsonSchema_0.MinimumLength);
            class120_2.Nullable_1        = Class192.smethod_2(class120_2.Nullable_1, jsonSchema_0.MaximumLength);
            class120_2.Nullable_2        = Class192.smethod_4(class120_2.Nullable_2, jsonSchema_0.DivisibleBy);
            class120_2.Nullable_3        = Class192.smethod_4(class120_2.Nullable_3, jsonSchema_0.Minimum);
            class120_2.Nullable_4        = Class192.smethod_4(class120_2.Nullable_4, jsonSchema_0.Maximum);
            if (!class120_2.Boolean_1)
            {
                exclusiveMinimum = jsonSchema_0.ExclusiveMinimum;
            }
            class120_2.Boolean_1 = exclusiveMinimum.HasValue;
            if (!class120_2.Boolean_2)
            {
                exclusiveMaximum = jsonSchema_0.ExclusiveMaximum;
            }
            class120_2.Boolean_2  = exclusiveMaximum.HasValue;
            class120_2.Nullable_5 = Class192.smethod_3(class120_2.Nullable_5, jsonSchema_0.MinimumItems);
            class120_2.Nullable_6 = Class192.smethod_2(class120_2.Nullable_6, jsonSchema_0.MaximumItems);
            class120_2.Boolean_3  = class120_2.Boolean_3 || jsonSchema_0.PositionalItemsValidation;
            class120_2.Boolean_4  = class120_2.Boolean_4 && jsonSchema_0.AllowAdditionalProperties;
            class120_2.Boolean_5  = class120_2.Boolean_5 && jsonSchema_0.AllowAdditionalItems;
            class120_2.Boolean_6  = class120_2.Boolean_6 || jsonSchema_0.UniqueItems;
            if (jsonSchema_0.Enum != null)
            {
                if (class120_2.IList_2 == null)
                {
                    class120_2.IList_2 = new List <JToken>();
                }
                class120_2.IList_2.smethod_7 <JToken>(jsonSchema_0.Enum, JToken.EqualityComparer);
            }
            JsonSchemaType?disallow = jsonSchema_0.Disallow;

            class120_2.JsonSchemaType_1 |= (JsonSchemaType)(disallow.HasValue ? disallow.GetValueOrDefault() : JsonSchemaType.None);
            if (jsonSchema_0.Pattern != null)
            {
                if (class120_2.IList_0 == null)
                {
                    class120_2.IList_0 = new List <string>();
                }
                class120_2.IList_0.smethod_4 <string>(jsonSchema_0.Pattern);
            }
        }
Beispiel #19
0
 private void ValidateNotDisallowed(JsonSchemaModel schema)
 {
     if (schema != null)
     {
         JsonSchemaType?currentNodeSchemaType = this.GetCurrentNodeSchemaType();
         if (currentNodeSchemaType.HasValue && JsonSchemaGenerator.HasFlag(new JsonSchemaType?(schema.Disallow), currentNodeSchemaType.GetValueOrDefault()))
         {
             this.RaiseError("Type {0} is disallowed.".FormatWith(CultureInfo.InvariantCulture, currentNodeSchemaType), schema);
         }
     }
 }
Beispiel #20
0
 private void method_18(Class120 class120_1)
 {
     if (class120_1 != null)
     {
         JsonSchemaType?nullable = this.method_19();
         if (nullable.HasValue && JsonSchemaGenerator.smethod_0(new JsonSchemaType?(class120_1.JsonSchemaType_1), nullable.Value))
         {
             this.method_16("Type {0} is disallowed.".smethod_0(CultureInfo.InvariantCulture, nullable), class120_1);
         }
     }
 }
        private void ValidateNotDisallowed(JsonSchemaModel schema)
        {
            if (schema == null)
                return;

            JsonSchemaType? currentNodeType = GetCurrentNodeSchemaType();
            if (currentNodeType != null)
            {
                if (JsonSchemaGenerator.HasFlag(schema.Disallow, currentNodeType.Value))
                    RaiseError("Type {0} is disallowed.".FormatWith(CultureInfo.InvariantCulture, currentNodeType), schema);
            }
        }
Beispiel #22
0
        private static void Combine(JsonSchemaModel model, JsonSchema schema)
        {
            bool?required;

            if (!model.Required)
            {
                required = schema.Required;
            }
            model.Required = required.HasValue;
            JsonSchemaType?type = schema.Type;

            model.Type         &= (JsonSchemaType)(type.HasValue ? type.GetValueOrDefault() : JsonSchemaType.Any);
            model.MinimumLength = MathUtils.Max(model.MinimumLength, schema.MinimumLength);
            model.MaximumLength = MathUtils.Min(model.MaximumLength, schema.MaximumLength);
            model.DivisibleBy   = MathUtils.Max(model.DivisibleBy, schema.DivisibleBy);
            model.Minimum       = MathUtils.Max(model.Minimum, schema.Minimum);
            model.Maximum       = MathUtils.Max(model.Maximum, schema.Maximum);
            if (!model.ExclusiveMinimum)
            {
                required = schema.ExclusiveMinimum;
            }
            model.ExclusiveMinimum = required.HasValue;
            if (!model.ExclusiveMaximum)
            {
                required = schema.ExclusiveMaximum;
            }
            model.ExclusiveMaximum          = required.HasValue;
            model.MinimumItems              = MathUtils.Max(model.MinimumItems, schema.MinimumItems);
            model.MaximumItems              = MathUtils.Min(model.MaximumItems, schema.MaximumItems);
            model.PositionalItemsValidation = model.PositionalItemsValidation || schema.PositionalItemsValidation;
            model.AllowAdditionalProperties = model.AllowAdditionalProperties && schema.AllowAdditionalProperties;
            model.AllowAdditionalItems      = model.AllowAdditionalItems && schema.AllowAdditionalItems;
            model.UniqueItems = model.UniqueItems || schema.UniqueItems;
            if (schema.Enum != null)
            {
                if (model.Enum == null)
                {
                    model.Enum = new List <JToken>();
                }
                model.Enum.AddRangeDistinct <JToken>(schema.Enum, JToken.EqualityComparer);
            }
            type            = schema.Disallow;
            model.Disallow |= (JsonSchemaType)(type.HasValue ? type.GetValueOrDefault() : JsonSchemaType.None);
            if (schema.Pattern != null)
            {
                if (model.Patterns == null)
                {
                    model.Patterns = new List <string>();
                }
                model.Patterns.AddDistinct <string>(schema.Pattern);
            }
        }
Beispiel #23
0
        internal static bool smethod_0(JsonSchemaType?nullable_0, JsonSchemaType jsonSchemaType_0)
        {
            if (!nullable_0.HasValue)
            {
                return(true);
            }
            JsonSchemaType?nullable  = nullable_0;
            JsonSchemaType type      = jsonSchemaType_0;
            JsonSchemaType?nullable3 = nullable.HasValue ? new JsonSchemaType?(((JsonSchemaType)nullable.GetValueOrDefault()) & type) : null;
            JsonSchemaType type2     = jsonSchemaType_0;

            return(((((JsonSchemaType)nullable3.GetValueOrDefault()) == type2) && nullable3.HasValue) || ((((JsonSchemaType)nullable_0) == JsonSchemaType.Float) && (jsonSchemaType_0 == JsonSchemaType.Integer)));
        }
        internal static bool HasFlag(JsonSchemaType?value, JsonSchemaType flag)
        {
            JsonSchemaType?nullable;
            JsonSchemaType?nullable1;
            JsonSchemaType?nullable2;

            if (!value.HasValue)
            {
                return(true);
            }
            JsonSchemaType?nullable3      = value;
            JsonSchemaType jsonSchemaType = flag;

            if (nullable3.HasValue)
            {
                nullable1 = new JsonSchemaType?(nullable3.GetValueOrDefault() & jsonSchemaType);
            }
            else
            {
                nullable  = null;
                nullable1 = nullable;
            }
            JsonSchemaType?nullable4 = nullable1;

            if (nullable4.GetValueOrDefault() == flag & nullable4.HasValue)
            {
                return(true);
            }
            if (flag == JsonSchemaType.Integer)
            {
                nullable3 = value;
                if (nullable3.HasValue)
                {
                    nullable2 = new JsonSchemaType?(nullable3.GetValueOrDefault() & JsonSchemaType.Float);
                }
                else
                {
                    nullable  = null;
                    nullable2 = nullable;
                }
                nullable4 = nullable2;
                if (nullable4.GetValueOrDefault() == JsonSchemaType.Float & nullable4.HasValue)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #25
0
        internal static bool HasFlag(JsonSchemaType? value, JsonSchemaType flag)
        {
            // default value is Any
            if (value == null)
                return true;

            bool match = ((value & flag) == flag);
            if (match)
                return true;

            // integer is a subset of float
            if (flag == JsonSchemaType.Integer && (value & JsonSchemaType.Float) == JsonSchemaType.Float)
                return true;

            return false;
        }
        public static string GetNetType(JsonSchemaType?jsonSchemaType, string format)
        {
            string netType;

            if (!string.IsNullOrWhiteSpace(format) &&
                (NumberFormatConversion.ContainsKey(format.ToLowerInvariant()) || DateFormatConversion.ContainsKey(format.ToLowerInvariant())))
            {
                netType = NumberFormatConversion.ContainsKey(format.ToLowerInvariant())
                    ? NumberFormatConversion[format.ToLowerInvariant()]
                    : DateFormatConversion[format.ToLowerInvariant()];
            }
            else
            {
                netType = Map(jsonSchemaType);
            }
            return(netType);
        }
Beispiel #27
0
        private void ValidateNotDisallowed(JsonSchemaModel schema)
        {
            if (schema == null)
            {
                return;
            }
            JsonSchemaType?currentNodeSchemaType = this.GetCurrentNodeSchemaType();

            if (!currentNodeSchemaType.HasValue || !JsonSchemaGenerator.HasFlag(new JsonSchemaType?(schema.Disallow),
                                                                                currentNodeSchemaType.GetValueOrDefault()))
            {
                return;
            }
            this.RaiseError(
                "Type {0} is disallowed.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture,
                                                     (object)currentNodeSchemaType), schema);
        }
Beispiel #28
0
        internal static bool HasFlag(JsonSchemaType?value, JsonSchemaType flag)
        {
            if (!value.HasValue)
            {
                return(true);
            }
            JsonSchemaType?nullable1       = value;
            JsonSchemaType jsonSchemaType1 = flag;
            JsonSchemaType?nullable2       = nullable1.HasValue ? new JsonSchemaType?(nullable1.GetValueOrDefault() & jsonSchemaType1) : new JsonSchemaType?();
            JsonSchemaType jsonSchemaType2 = flag;

            if (nullable2.GetValueOrDefault() == jsonSchemaType2 && nullable2.HasValue)
            {
                return(true);
            }
            JsonSchemaType?nullable3 = value;

            return((nullable3.GetValueOrDefault() != JsonSchemaType.Float ? 0 : (nullable3.HasValue ? 1 : 0)) != 0 && flag == JsonSchemaType.Integer);
        }
Beispiel #29
0
        internal static bool HasFlag(JsonSchemaType?value, JsonSchemaType flag)
        {
            JsonSchemaType?nullable;
            JsonSchemaType?nullable1;

            if (!value.HasValue)
            {
                return(true);
            }
            if (!value.HasValue)
            {
                nullable  = null;
                nullable1 = nullable;
            }
            else
            {
                nullable1 = new JsonSchemaType?(value.GetValueOrDefault() & flag);
            }
            nullable = nullable1;
            return(nullable.GetValueOrDefault() != flag ? false : nullable.HasValue);
        }
Beispiel #30
0
        // Token: 0x060013D2 RID: 5074 RVA: 0x000691D0 File Offset: 0x000673D0
        internal static bool HasFlag(JsonSchemaType?value, JsonSchemaType flag)
        {
            if (value == null)
            {
                return(true);
            }
            JsonSchemaType?jsonSchemaType = value & flag;

            if (jsonSchemaType.GetValueOrDefault() == flag & jsonSchemaType != null)
            {
                return(true);
            }
            if (flag == JsonSchemaType.Integer)
            {
                jsonSchemaType = (value & JsonSchemaType.Float);
                if (jsonSchemaType.GetValueOrDefault() == JsonSchemaType.Float & jsonSchemaType != null)
                {
                    return(true);
                }
            }
            return(false);
        }
 // Token: 0x06000B73 RID: 2931
 // RVA: 0x000428D0 File Offset: 0x00040AD0
 private JsonSchemaType? ProcessType(JToken token)
 {
     JTokenType type = token.Type;
     if (type == JTokenType.Array)
     {
         JsonSchemaType? jsonSchemaType = new JsonSchemaType?(JsonSchemaType.None);
         foreach (JToken current in ((IEnumerable<JToken>)token))
         {
             if (current.Type != JTokenType.String)
             {
                 throw JsonException.Create(current, current.Path, StringUtils.FormatWith("Exception JSON schema type string token, got {0}.", CultureInfo.InvariantCulture, token.Type));
             }
             jsonSchemaType |= JsonSchemaBuilder.MapType((string)current);
         }
         return jsonSchemaType;
     }
     if (type != JTokenType.String)
     {
         throw JsonException.Create(token, token.Path, StringUtils.FormatWith("Expected array or JSON schema type string token, got {0}.", CultureInfo.InvariantCulture, token.Type));
     }
     return new JsonSchemaType?(JsonSchemaBuilder.MapType((string)token));
 }
Beispiel #32
0
 private JsonSchemaType? ProcessType()
 {
   switch (this._reader.TokenType)
   {
     case JsonToken.StartArray:
       JsonSchemaType? nullable1 = new JsonSchemaType?(JsonSchemaType.None);
       while (this._reader.Read() && this._reader.TokenType != JsonToken.EndArray)
       {
         if (this._reader.TokenType != JsonToken.String)
           throw JsonReaderException.Create(this._reader, StringUtils.FormatWith("Exception JSON schema type string token, got {0}.", (IFormatProvider) CultureInfo.InvariantCulture, (object) this._reader.TokenType));
         JsonSchemaType? nullable2 = nullable1;
         JsonSchemaType jsonSchemaType = JsonSchemaBuilder.MapType(this._reader.Value.ToString());
         nullable1 = nullable2.HasValue ? new JsonSchemaType?(nullable2.GetValueOrDefault() | jsonSchemaType) : new JsonSchemaType?();
       }
       return nullable1;
     case JsonToken.String:
       return new JsonSchemaType?(JsonSchemaBuilder.MapType(this._reader.Value.ToString()));
     default:
       throw JsonReaderException.Create(this._reader, StringUtils.FormatWith("Expected array or JSON schema type string token, got {0}.", (IFormatProvider) CultureInfo.InvariantCulture, (object) this._reader.TokenType));
   }
 }