public void Merge(IJsonSchemaValidator obj)
        {
            var rhs = obj as JsonObjectValidator;

            if (rhs == null)
            {
                throw new ArgumentException();
            }

            foreach (var x in rhs.Properties)
            {
                if (Properties.ContainsKey(x.Key))
                {
                    Properties[x.Key] = x.Value;
                }
                else
                {
                    Properties.Add(x.Key, x.Value);
                }
            }

            foreach (var x in rhs.Required)
            {
                Required.Add(x);
            }

            if (rhs.AdditionalProperties != null)
            {
                if (AdditionalProperties != null)
                {
                    throw new NotImplementedException();
                }
                AdditionalProperties = rhs.AdditionalProperties;
            }
        }
예제 #2
0
파일: SchemaObject.cs 프로젝트: TGDaley/TGE
        public SchemaObject(EventSchema eventSchema, string name, string @namespace)
            : this()
        {
            Type        = SchemaObjectType.Object;
            Title       = name;
            Description = string.Format("JSON schema for {0}/{1}.", @namespace, name);

            if (eventSchema.Properties == null)
            {
                return;
            }

            if (eventSchema.ValidateByQuery)
            {
                ValidationQueryUrl = eventSchema.ValidationQueryUrl;
            }

            foreach (var property in eventSchema.Properties)
            {
                var validated = isPropertyValidated(property.Value);

                var propertyType = getPropertyType(property.Value);

                ISchemaPropertyMetadata metadata;

                if (validated)
                {
                    var validationMetadata = getValidatedPropertyMetadata(property.Value, propertyType);

                    if (validationMetadata.Required.HasValue && validationMetadata.Required.Value)
                    {
                        Required.Add(property.Key);
                    }

                    metadata = validationMetadata;
                }
                else
                {
                    metadata = new SimplePropertyMetadata(propertyType);
                }

                Properties.Add(property.Key, metadata);
            }
        }
        public void Merge(IJsonSchemaValidator obj)
        {
            var rhs = obj as JsonObjectValidator;

            if (rhs == null)
            {
                throw new ArgumentException();
            }

            foreach (var x in rhs.Required)
            {
                Required.Add(x);
            }

            if (rhs.AdditionalProperties != null)
            {
                if (AdditionalProperties != null)
                {
                    throw new NotImplementedException();
                }
                AdditionalProperties = rhs.AdditionalProperties;
            }
        }
        /// <summary>
        /// Add the provided required property names to this JSON schema's list of required property names.
        /// </summary>
        /// <param name="requiredPropertyName"></param>
        /// <param name="extraRequiredPropertyNames"></param>
        public JsonSchema AddRequired(string requiredPropertyName, params string[] extraRequiredPropertyNames)
        {
            if (Properties == null || !Properties.ContainsKey(requiredPropertyName))
            {
                throw new ArgumentException("No property exists with the provided requiredPropertyName (" + requiredPropertyName + ")", nameof(requiredPropertyName));
            }

            if (Required == null)
            {
                Required = new List <string>();
            }

            if (Required.Contains(requiredPropertyName))
            {
                throw new ArgumentException("'" + requiredPropertyName + "' is already a required property.", "requiredPropertyName");
            }
            Required.Add(requiredPropertyName);

            if (extraRequiredPropertyNames != null)
            {
                foreach (string extraRequiredPropertyName in extraRequiredPropertyNames)
                {
                    if (Properties == null || !Properties.ContainsKey(extraRequiredPropertyName))
                    {
                        throw new ArgumentException("No property exists with the provided extraRequiredPropertyName (" + extraRequiredPropertyName + ")", "extraRequiredPropertyNames");
                    }
                    if (Required.Contains(extraRequiredPropertyName))
                    {
                        throw new ArgumentException("'" + extraRequiredPropertyName + "' is already a required property.", "extraRequiredPropertyNames");
                    }
                    Required.Add(extraRequiredPropertyName);
                }
            }

            return(this);
        }
예제 #5
0
 public ApiPermissionsSet AddAll(ApiPermission[] perms)
 {
     Array.ForEach(perms, x => Required.Add(x));
     return(this);
 }
예제 #6
0
 public ApiPermissionsSet Add(ApiPermission permission)
 {
     Required.Add(permission);
     return(this);
 }
예제 #7
0
 internal QueryCommand(CommandLineTextInterface clti, IDatabase db) : base(clti)
 {
     this.db = db;
     Required.Add(typeToken);
     HasAnonymousArg = true;
 }
예제 #8
0
 internal void Require(string source, T value)
 {
     Required.Add(new ValueAndSource <T>(source, value));
 }