예제 #1
0
        internal static bool HasAttribute <T>(this JsonProperty jsonProperty)
            where T : Attribute
        {
            var propInfo = jsonProperty.PropertyInfo();

            return(propInfo != null && propInfo.GetCustomAttribute <T>() != null);
        }
예제 #2
0
        internal static Schema AssignValidationProperties(this Schema schema, JsonProperty jsonProperty)
        {
            var propInfo = jsonProperty.PropertyInfo();

            if (propInfo == null)
            {
                return(schema);
            }

            foreach (var attribute in propInfo.GetCustomAttributes(false))
            {
                var regex = attribute as RegularExpressionAttribute;
                if (regex != null)
                {
                    schema.Pattern = regex.Pattern;
                }

                var range = attribute as RangeAttribute;
                if (range != null)
                {
                    int maximum;
                    if (Int32.TryParse(range.Maximum.ToString(), out maximum))
                    {
                        schema.Maximum = maximum;
                    }

                    int minimum;
                    if (Int32.TryParse(range.Minimum.ToString(), out minimum))
                    {
                        schema.Minimum = minimum;
                    }
                }

                var minLength = attribute as MinLengthAttribute;
                if (minLength != null)
                {
                    schema.MinLength = minLength.Length;
                }

                var maxLength = attribute as MaxLengthAttribute;
                if (maxLength != null)
                {
                    schema.MaxLength = maxLength.Length;
                }

                var stringLength = attribute as StringLengthAttribute;
                if (stringLength != null)
                {
                    schema.MinLength = stringLength.MinimumLength;
                    schema.MaxLength = stringLength.MaximumLength;
                }
            }

            if (!jsonProperty.Writable)
            {
                schema.ReadOnly = true;
            }

            return(schema);
        }
예제 #3
0
        public static Schema WithValidationProperties(this Schema schema, JsonProperty jsonProperty)
        {
            var propInfo = jsonProperty.PropertyInfo();

            if (propInfo == null)
            {
                return(schema);
            }

            var metadata = propInfo.DeclaringType.GetCustomAttributes(typeof(MetadataTypeAttribute), true).OfType <MetadataTypeAttribute>().ToArray().FirstOrDefault();

            if (metadata != null)
            {
                propInfo = metadata.MetadataClassType.GetProperties().SingleOrDefault(x => x.Name == propInfo.Name);
                if (propInfo == null)
                {
                    return(schema);
                }
            }

            foreach (var attribute in propInfo.GetCustomAttributes(false))
            {
                var regex = attribute as RegularExpressionAttribute;
                if (regex != null)
                {
                    schema.pattern = regex.Pattern;
                }

                var range = attribute as RangeAttribute;
                if (range != null)
                {
                    int maximum;
                    if (Int32.TryParse(range.Maximum.ToString(), out maximum))
                    {
                        schema.maximum = maximum;
                    }

                    int minimum;
                    if (Int32.TryParse(range.Minimum.ToString(), out minimum))
                    {
                        schema.minimum = minimum;
                    }
                }

                var length = attribute as StringLengthAttribute;
                if (length != null)
                {
                    schema.maxLength = length.MaximumLength;
                    schema.minLength = length.MinimumLength;
                }
            }

            if (!jsonProperty.Writable)
            {
                schema.readOnly = true;
            }

            return(schema);
        }
예제 #4
0
        internal static Schema AssignValidationProperties(this Schema schema, JsonProperty jsonProperty)
        {
            var propInfo = jsonProperty.PropertyInfo();

            if (propInfo == null)
            {
                return(schema);
            }

            foreach (var attribute in propInfo.GetCustomAttributes(false))
            {
                if (attribute is DefaultValueAttribute defaultValue)
                {
                    schema.Default = defaultValue.Value;
                }

                if (attribute is RegularExpressionAttribute regex)
                {
                    schema.Pattern = regex.Pattern;
                }

                if (attribute is RangeAttribute range)
                {
                    if (Int32.TryParse(range.Maximum.ToString(), out var maximum))
                    {
                        schema.Maximum = maximum;
                    }

                    if (Int32.TryParse(range.Minimum.ToString(), out var minimum))
                    {
                        schema.Minimum = minimum;
                    }
                }

                if (attribute is MinLengthAttribute minLength)
                {
                    schema.MinLength = minLength.Length;
                }

                if (attribute is MaxLengthAttribute maxLength)
                {
                    schema.MaxLength = maxLength.Length;
                }

                if (attribute is StringLengthAttribute stringLength)
                {
                    schema.MinLength = stringLength.MinimumLength;
                    schema.MaxLength = stringLength.MaximumLength;
                }
            }

            if (!jsonProperty.Writable)
            {
                schema.ReadOnly = true;
            }

            return(schema);
        }
예제 #5
0
        public static bool HasAttribute <T>(this JsonProperty jsonProperty)
        {
            PropertyInfo propertyInfo = jsonProperty.PropertyInfo();

            if (propertyInfo != (PropertyInfo)null)
            {
                return(Attribute.IsDefined((MemberInfo)propertyInfo, typeof(T)));
            }
            return(false);
        }
        public static bool HasAttribute <T>(this JsonProperty jsonProperty)
        {
            var propInfo = jsonProperty.PropertyInfo();
            var metadata = propInfo.DeclaringType.GetCustomAttributes(typeof(MetadataTypeAttribute), true).OfType <MetadataTypeAttribute>().ToArray().FirstOrDefault();

            if (metadata != null)
            {
                propInfo = metadata.MetadataClassType.GetProperties().SingleOrDefault(x => x.Name == propInfo.Name);
            }
            return(propInfo != null && Attribute.IsDefined(propInfo, typeof(T)));
        }
        public static bool HasAttribute <T>(this JsonProperty jsonProperty)
        {
            var propInfo = jsonProperty.PropertyInfo();

            if (propInfo != null)
            {
                return(Attribute.IsDefined(propInfo, typeof(T)));
            }
            else
            {
                var fieldInfo = jsonProperty.FieldInfo();
                return(fieldInfo != null && Attribute.IsDefined(fieldInfo, typeof(T)));;
            }
        }
예제 #8
0
        public static Schema WithDescriptionProperty(this Schema schema, JsonProperty jsonProperty)
        {
            var propInfo = jsonProperty.PropertyInfo();

            if (propInfo == null)
            {
                return(schema);
            }

            var attrib = propInfo.GetCustomAttributes(false).OfType <SwaggerDescriptionAttribute>().FirstOrDefault();

            schema.description = attrib?.Description;
            return(schema);
        }
예제 #9
0
        public static Schema WithValidationProperties(this Schema schema, JsonProperty jsonProperty)
        {
            var propInfo = jsonProperty.PropertyInfo();

            if (propInfo == null)
            {
                return(schema);
            }

            schema = GetAttributeDetails(schema, propInfo);

            if (!jsonProperty.Writable)
            {
                schema.readOnly = true;
            }
            return(schema);
        }
예제 #10
0
        public static Schema WithValidationProperties(
            this Schema schema,
            JsonProperty jsonProperty)
        {
            PropertyInfo propertyInfo = jsonProperty.PropertyInfo();

            if (propertyInfo == (PropertyInfo)null)
            {
                return(schema);
            }
            foreach (object customAttribute in propertyInfo.GetCustomAttributes(false))
            {
                RegularExpressionAttribute expressionAttribute = customAttribute as RegularExpressionAttribute;
                if (expressionAttribute != null)
                {
                    schema.pattern = expressionAttribute.Pattern;
                }
                RangeAttribute rangeAttribute = customAttribute as RangeAttribute;
                if (rangeAttribute != null)
                {
                    int result1;
                    if (int.TryParse(rangeAttribute.Maximum.ToString(), out result1))
                    {
                        schema.maximum = new int?(result1);
                    }
                    int result2;
                    if (int.TryParse(rangeAttribute.Minimum.ToString(), out result2))
                    {
                        schema.minimum = new int?(result2);
                    }
                }
                StringLengthAttribute stringLengthAttribute = customAttribute as StringLengthAttribute;
                if (stringLengthAttribute != null)
                {
                    schema.maxLength = new int?(stringLengthAttribute.MaximumLength);
                    schema.minLength = new int?(stringLengthAttribute.MinimumLength);
                }
            }
            if (!jsonProperty.get_Writable())
            {
                schema.readOnly = new bool?(true);
            }
            return(schema);
        }
예제 #11
0
        public static Schema WithValidationProperties(this Schema schema, JsonProperty jsonProperty)
        {
            PropertyInfo propertyInfo = jsonProperty.PropertyInfo();

            if (propertyInfo == null)
            {
                return(schema);
            }
            object[] customAttributes = propertyInfo.GetCustomAttributes(false);
            for (int i = 0; i < customAttributes.Length; i++)
            {
                //object obj = customAttributes[i];
                //RegularExpressionAttribute regularExpressionAttribute = obj as RegularExpressionAttribute;
                //if (regularExpressionAttribute != null)
                //{
                //	schema.pattern = regularExpressionAttribute.Pattern;
                //}
                //RangeAttribute rangeAttribute = obj as RangeAttribute;
                //if (rangeAttribute != null)
                //{
                //	int value;
                //	if (int.TryParse(rangeAttribute.Maximum.ToString(), out value))
                //	{
                //		schema.maximum = new int?(value);
                //	}
                //	int value2;
                //	if (int.TryParse(rangeAttribute.Minimum.ToString(), out value2))
                //	{
                //		schema.minimum = new int?(value2);
                //	}
                //}
                //StringLengthAttribute stringLengthAttribute = obj as StringLengthAttribute;
                //if (stringLengthAttribute != null)
                //{
                //	schema.maxLength = new int?(stringLengthAttribute.MaximumLength);
                //	schema.minLength = new int?(stringLengthAttribute.MinimumLength);
                //}
            }
            if (!jsonProperty.Writable)
            {
                schema.readOnly = new bool?(true);
            }
            return(schema);
        }
예제 #12
0
        public static Schema WithValidationProperties(this Schema schema, JsonProperty jsonProperty)
        {
            var propInfo = jsonProperty.PropertyInfo();

            if (propInfo == null)
            {
                return(schema);
            }

            foreach (var attribute in propInfo.GetCustomAttributes(false))
            {
                var regex = attribute as RegularExpressionAttribute;
                if (regex != null)
                {
                    schema.pattern = regex.Pattern;
                }

                var range = attribute as RangeAttribute;
                if (range != null)
                {
                    int maximum;
                    if (Int32.TryParse(range.Maximum.ToString(), out maximum))
                    {
                        schema.maximum = maximum;
                    }

                    int minimum;
                    if (Int32.TryParse(range.Minimum.ToString(), out minimum))
                    {
                        schema.minimum = minimum;
                    }
                }
            }

            if (!jsonProperty.Writable)
            {
                schema.readOnly = true;
            }

            return(schema);
        }
예제 #13
0
        public void Apply(Schema model, ModelFilterContext context)
        {
            string         commentIdForType = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType);
            XPathNavigator xPathNavigator   = this._navigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", commentIdForType));

            if (xPathNavigator != null)
            {
                XPathNavigator xPathNavigator2 = xPathNavigator.SelectSingleNode("summary");
                if (xPathNavigator2 != null)
                {
                    model.description = xPathNavigator2.ExtractContent();
                }
            }
            foreach (KeyValuePair <string, Schema> current in model.properties)
            {
                JsonProperty jsonProperty = context.JsonObjectContract.Properties[current.Key];
                if (jsonProperty != null)
                {
                    this.ApplyPropertyComments(current.Value, jsonProperty.PropertyInfo());
                }
            }
        }
예제 #14
0
        public static Schema WithValidationProperties(this Schema schema, JsonProperty jsonProperty)
        {
            var propInfo  = jsonProperty.PropertyInfo();
            var fieldInfo = jsonProperty.FieldInfo();

            if (propInfo == null && fieldInfo == null)
            {
                return(schema);
            }

            if (propInfo != null)
            {
                foreach (var attribute in propInfo.GetCustomAttributes(false))
                {
                    schema.AddDefault(attribute);
                    schema.AddPattern(attribute);
                    schema.AddRange(attribute);
                    schema.AddLength(attribute);
                }
            }
            if (fieldInfo != null)
            {
                foreach (var attribute in fieldInfo.GetCustomAttributes(false))
                {
                    schema.AddDefault(attribute);
                    schema.AddPattern(attribute);
                    schema.AddRange(attribute);
                    schema.AddLength(attribute);
                }
            }

            if (!jsonProperty.Writable)
            {
                schema.readOnly = true;
            }

            return(schema);
        }
예제 #15
0
 public static bool HasAttribute<T>(this JsonProperty jsonProperty)
 {
     var propInfo = jsonProperty.PropertyInfo();
     return propInfo != null && Attribute.IsDefined(propInfo, typeof (T));
 }
        internal static Schema AssignXmlProperties(this Schema schema, JsonProperty jsonProperty)
        {
            var propInfo = jsonProperty.PropertyInfo();

            if (propInfo == null)
            {
                return(schema);
            }

            foreach (var attribute in propInfo.GetCustomAttributes(false))
            {
                var xmlAttribute = attribute as XmlAttributeAttribute;
                if (xmlAttribute != null)
                {
                    if (schema.Xml == null)
                    {
                        schema.Xml = new Xml();
                    }

                    schema.Xml.Attribute = true;

                    if (!string.IsNullOrWhiteSpace(xmlAttribute.AttributeName))
                    {
                        schema.Xml.Name = xmlAttribute.AttributeName;
                    }
                }

                var xmlElement = attribute as XmlElementAttribute;
                if (xmlElement != null)
                {
                    if (schema.Xml == null)
                    {
                        schema.Xml = new Xml();
                    }

                    schema.Xml.Attribute = false;

                    if (!string.IsNullOrWhiteSpace(xmlElement.ElementName))
                    {
                        schema.Xml.Name = xmlElement.ElementName;
                    }

                    if (!string.IsNullOrWhiteSpace(xmlElement.Namespace))
                    {
                        schema.Xml.Namespace = xmlElement.Namespace;
                    }
                }

                var xmlArrayItem = attribute as XmlArrayItemAttribute;
                if (xmlArrayItem != null)
                {
                    if (schema.Items.Xml == null)
                    {
                        schema.Items.Xml = new Xml();
                    }

                    if (!string.IsNullOrWhiteSpace(xmlArrayItem.ElementName))
                    {
                        schema.Items.Xml.Name = xmlArrayItem.ElementName;
                    }

                    if (!string.IsNullOrWhiteSpace(xmlArrayItem.Namespace))
                    {
                        schema.Items.Xml.Namespace = xmlArrayItem.Namespace;
                    }
                }

                var xmlArray = attribute as XmlArrayAttribute;
                if (xmlArray != null)
                {
                    if (schema.Xml == null)
                    {
                        schema.Xml = new Xml();
                    }

                    if (!string.IsNullOrWhiteSpace(xmlArray.ElementName))
                    {
                        schema.Xml.Name    = xmlArray.ElementName;
                        schema.Xml.Wrapped = true;
                    }

                    if (!string.IsNullOrWhiteSpace(xmlArray.Namespace))
                    {
                        schema.Xml.Namespace = xmlArray.Namespace;
                    }
                }
            }

            return(schema);
        }
예제 #17
0
        public void Apply(Schema model, ModelFilterContext context)
        {
            XPathNavigator navigator;

            lock (this._xmlDoc)
                navigator = this._xmlDoc.CreateNavigator();
            string         commentIdForType = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType);
            XPathNavigator xpathNavigator   = navigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", (object)commentIdForType));

            if (xpathNavigator != null)
            {
                XPathNavigator node = xpathNavigator.SelectSingleNode("summary");
                if (node != null)
                {
                    model.description = node.ExtractContent();
                }
            }
            if (model.properties == null)
            {
                return;
            }
            foreach (KeyValuePair <string, Schema> property1 in (IEnumerable <KeyValuePair <string, Schema> >)model.properties)
            {
                JsonProperty property2 = ((KeyedCollection <string, JsonProperty>)context.JsonObjectContract.get_Properties())[property1.Key];
                if (property2 != null)
                {
                    ApplyXmlTypeComments.ApplyPropertyComments(navigator, property1.Value, property2.PropertyInfo());
                }
            }
        }