示例#1
0
        /// <summary>Gets a value indicating whether the validated data can be null.</summary>
        /// <param name="schemaType">The schema type.</param>
        /// <returns>true if the type can be null.</returns>
        public virtual bool IsNullable(SchemaType schemaType)
        {
            if (IsNullableRaw == true)
            {
                return(true);
            }

            if (IsEnumeration && Enumeration.Contains(null))
            {
                return(true);
            }

            if (Type.HasFlag(JsonObjectType.Null))
            {
                return(true);
            }

            if ((Type == JsonObjectType.None || Type.HasFlag(JsonObjectType.Null)) && OneOf.Any(o => o.IsNullable(schemaType)))
            {
                return(true);
            }

            if (ActualSchema != this && ActualSchema.IsNullable(schemaType))
            {
                return(true);
            }

            if (ActualTypeSchema != this && ActualTypeSchema.IsNullable(schemaType))
            {
                return(true);
            }

            return(false);
        }
示例#2
0
        /// <summary>Gets a value indicating whether the validated data can be null.</summary>
        /// <param name="schemaType">The schema type.</param>
        /// <returns>true if the type can be null.</returns>
        public virtual bool IsNullable(SchemaType schemaType)
        {
            if (schemaType == SchemaType.OpenApi3 && IsNullableRaw.HasValue)
                return IsNullableRaw.Value;

            if (IsEnumeration && Enumeration.Contains(null))
                return true;

            if (Type.HasFlag(JsonObjectType.Null) && OneOf.Count == 0)
                return true;

            return (Type == JsonObjectType.None || Type.HasFlag(JsonObjectType.Null)) && OneOf.Any(o => o.IsNullable(schemaType));
        }
示例#3
0
        /// <summary>Gets a value indicating whether the validated data can be null.</summary>
        /// <param name="schemaType">The schema type.</param>
        /// <returns>true if the type can be null.</returns>
        public virtual bool IsNullable(SchemaType schemaType)
        {
            if (IsEnumeration && Enumeration.Contains(null))
            {
                return(true);
            }

            if (Type.HasFlag(JsonObjectType.Null) && OneOf.Count == 0)
            {
                return(true);
            }

            return((Type == JsonObjectType.None || Type.HasFlag(JsonObjectType.Null)) && OneOf.Any(o => o.IsNullable(schemaType)));
        }
示例#4
0
        /// <summary>Determines whether the specified property null handling is nullable.</summary>
        /// <param name="schemaType">The schema type.</param>
        /// <returns>true if the type can be null.</returns>
        public override bool IsNullable(SchemaType schemaType)
        {
            if (IsEnumeration && Enumeration.Contains(null))
            {
                return(true);
            }

            if (schemaType == SchemaType.Swagger2)
            {
                return(IsRequired == false);
            }

            return(base.IsNullable(schemaType));
        }
示例#5
0
        /// <summary>Determines whether the specified property null handling is nullable.</summary>
        /// <param name="nullHandling">The property null handling.</param>
        /// <returns></returns>
        public override bool IsNullable(NullHandling nullHandling)
        {
            if (IsEnumeration && Enumeration.Contains(null))
            {
                return(true);
            }

            if (nullHandling == NullHandling.Swagger)
            {
                return(IsRequired == false);
            }

            return(base.IsNullable(nullHandling));
        }