/// <summary> /// Return list of validations for primary, map, sequence and rest of the types. /// </summary> /// <param name="p"></param> /// <param name="name"></param> /// <param name="method"></param> /// <param name="isCompositeProperties"></param> /// <returns></returns> public static List <string> ValidateType(this IParameter p, string name, HttpMethod method, bool isCompositeProperties = false) { List <string> x = new List <string>(); if (method != HttpMethod.Patch || !p.IsBodyParameter() || isCompositeProperties) { x.AddRange(p.Constraints.Select(c => GetConstraint(name, c.Key.ToString(), c.Value)).ToList()); } List <string> y = new List <string>(); if (x.Count > 0) { if (p.CheckNull() || isCompositeProperties) { y.AddRange(x.AddChain(name, NullConstraint, p.IsRequired)); } else { y.AddRange(x); } } else { if (p.IsRequired && (p.CheckNull() || isCompositeProperties)) { y.AddNullValidation(name, p.IsRequired); } } return(y); }
/// <summary> /// Return list of validations for composite type. /// </summary> /// <param name="p"></param> /// <param name="name"></param> /// <param name="method"></param> /// <param name="ancestors"></param> /// <param name="isCompositeProperties"></param> /// <returns></returns> public static List <string> ValidateCompositeType(this IParameter p, string name, HttpMethod method, HashSet <string> ancestors, bool isCompositeProperties = false) { List <string> x = new List <string>(); if (method != HttpMethod.Patch || !p.IsBodyParameter() || isCompositeProperties) { foreach (var prop in ((CompositeType)p.Type).Properties) { var primary = prop.Type as PrimaryType; var sequence = prop.Type as SequenceType; var map = prop.Type as MapType; var composite = prop.Type as CompositeType; if (primary != null || sequence != null || map != null) { x.AddRange(prop.ValidateType(prop.Name, method, true)); } else if (composite != null) { if (ancestors.Contains(composite.Name)) { x.AddNullValidation(name, p.IsRequired); } else { ancestors.Add(composite.Name); x.AddRange(prop.ValidateCompositeType(prop.Name, method, ancestors, true)); ancestors.Remove(composite.Name); } } } } x.AddRange(from prop in ((CompositeType)p.Type).Properties where prop.IsReadOnly select GetConstraint(prop.Name, ReadOnlyConstraint, "true")); List <string> y = new List <string>(); if (x.Count > 0) { if (p.CheckNull() || isCompositeProperties) { y.AddRange(x.AddChain(name, NullConstraint, p.IsRequired)); } else { y.AddRange(x); } } else { if (p.IsRequired && (p.CheckNull() || isCompositeProperties)) { y.AddNullValidation(name, p.IsRequired); } } return(y); }
/// <summary> /// Return list of validations for composite type. /// </summary> /// <param name="p"></param> /// <param name="name"></param> /// <param name="method"></param> /// <param name="ancestors"></param> /// <param name="isCompositeProperties"></param> /// <returns></returns> public static List <string> ValidateCompositeType(this IVariable p, string name, HttpMethod method, HashSet <string> ancestors, bool isCompositeProperties = false) { List <string> x = new List <string>(); if (method != HttpMethod.Patch || !p.IsBodyParameter() || isCompositeProperties) { foreach (var prop in ((CompositeType)p.ModelType).Properties) { var primary = prop.ModelType as PrimaryType; var sequence = prop.ModelType as SequenceType; var map = prop.ModelType as DictionaryTypeGo; var composite = prop.ModelType as CompositeType; var propName = prop.Name; if (primary != null || sequence != null || map != null) { x.AddRange(prop.ValidateType($"{name}.{propName}", method, true)); } else if (composite != null) { if (ancestors.Contains(composite.Name)) { x.AddNullValidation($"{name}.{propName}", p.IsRequired); } else { ancestors.Add(composite.Name); x.AddRange(prop.ValidateCompositeType($"{name}.{propName}", method, ancestors, true)); ancestors.Remove(composite.Name); } } } } List <string> y = new List <string>(); if (x.Count > 0) { if (p.CheckNull() || isCompositeProperties) { y.AddRange(x.AddChain(name, NullConstraint, p.IsRequired)); } else { y.AddRange(x); } } else { if (p.IsRequired && (p.CheckNull() || isCompositeProperties)) { y.AddNullValidation(name, p.IsRequired); } } return(y); }
/// <summary> /// Return list of validations for composite type. /// </summary> /// <param name="p"></param> /// <param name="name"></param> /// <param name="method"></param> /// <param name="ancestors"></param> /// <param name="isCompositeProperties"></param> /// <returns></returns> public static List<string> ValidateCompositeType(this IParameter p, string name, HttpMethod method, HashSet<string> ancestors, bool isCompositeProperties = false) { List<string> x = new List<string>(); if (method != HttpMethod.Patch || !p.IsBodyParameter() || isCompositeProperties) { foreach (var prop in ((CompositeType)p.Type).Properties) { var primary = prop.Type as PrimaryType; var sequence = prop.Type as SequenceType; var map = prop.Type as MapType; var composite = prop.Type as CompositeType; if (primary != null || sequence != null || map != null) x.AddRange(prop.ValidateType($"{name}.{prop.Name}", method, true)); else if (composite != null) { if (ancestors.Contains(composite.Name)) { x.AddNullValidation($"{name}.{prop.Name}", p.IsRequired); } else { ancestors.Add(composite.Name); x.AddRange(prop.ValidateCompositeType($"{name}.{prop.Name}", method, ancestors, true)); ancestors.Remove(composite.Name); } } } } x.AddRange(from prop in ((CompositeType)p.Type).Properties where prop.IsReadOnly select GetConstraint($"{name}.{prop.Name}", ReadOnlyConstraint, "true")); List<string> y = new List<string>(); if (x.Count > 0) { if (p.CheckNull() || isCompositeProperties) y.AddRange(x.AddChain(name, NullConstraint, p.IsRequired)); else y.AddRange(x); } else { if (p.IsRequired && (p.CheckNull() || isCompositeProperties)) y.AddNullValidation(name, p.IsRequired); } return y; }
/// <summary> /// Return list of validations for primary, map, sequence and rest of the types. /// </summary> /// <param name="p"></param> /// <param name="name"></param> /// <param name="method"></param> /// <param name="isCompositeProperties"></param> /// <returns></returns> public static List<string> ValidateType(this IParameter p, string name, HttpMethod method, bool isCompositeProperties = false) { List<string> x = new List<string>(); if (method != HttpMethod.Patch || !p.IsBodyParameter() || isCompositeProperties) { x.AddRange(p.Constraints.Select(c => GetConstraint(name, c.Key.ToString(), c.Value)).ToList()); } List<string> y = new List<string>(); if (x.Count > 0) { if (p.CheckNull() || isCompositeProperties) y.AddRange(x.AddChain(name, NullConstraint, p.IsRequired)); else y.AddRange(x); } else { if (p.IsRequired && (p.CheckNull() || isCompositeProperties)) y.AddNullValidation(name, p.IsRequired); } return y; }
/// <summary> /// Return list of validations for composite type. /// </summary> /// <param name="p"></param> /// <param name="name"></param> /// <param name="method"></param> /// <param name="ancestors"></param> /// <param name="isCompositeProperties"></param> /// <returns></returns> public static List <string> ValidateCompositeType(this IVariable p, string name, HttpMethod method, HashSet <string> ancestors, bool isCompositeProperties = false) { List <string> x = new List <string>(); if (method != HttpMethod.Patch || !p.IsBodyParameter() || isCompositeProperties) { foreach (var prop in ((CompositeType)p.ModelType).Properties) { var primary = prop.ModelType as PrimaryType; var sequence = prop.ModelType as SequenceType; var map = prop.ModelType as DictionaryTypeGo; var composite = prop.ModelType as CompositeType; // if this type was flattened use the name of the type instead of // the property name as it's been embedded as an anonymous field var propName = prop.Name; if (prop.WasFlattened()) { propName = prop.ModelType.Name; } if (primary != null || sequence != null || map != null) { x.AddRange(prop.ValidateType($"{name}.{propName}", method, true)); } else if (composite != null) { if (ancestors.Contains(composite.Name)) { x.AddNullValidation($"{name}.{propName}", p.IsRequired); } else { ancestors.Add(composite.Name); x.AddRange(prop.ValidateCompositeType($"{name}.{propName}", method, ancestors, true)); ancestors.Remove(composite.Name); } } } } x.AddRange(from prop in ((CompositeType)p.ModelType).Properties where prop.IsReadOnly select GetConstraint(string.Format("{0}.{1}", name, prop.WasFlattened() ? prop.ModelType.Name : prop.Name), ReadOnlyConstraint, "true")); List <string> y = new List <string>(); if (x.Count > 0) { if (p.CheckNull() || isCompositeProperties) { y.AddRange(x.AddChain(name, NullConstraint, p.IsRequired)); } else { y.AddRange(x); } } else { if (p.IsRequired && (p.CheckNull() || isCompositeProperties)) { y.AddNullValidation(name, p.IsRequired); } } return(y); }
/// <summary> /// Return list of validations for composite type. /// </summary> /// <param name="p"></param> /// <param name="name"></param> /// <param name="method"></param> /// <param name="ancestors"></param> /// <param name="isCompositeProperties"></param> /// <returns></returns> public static List <string> ValidateCompositeType(this IVariable p, string name, HttpMethod method, HashSet <string> ancestors, bool isCompositeProperties = false) { List <string> x = new List <string>(); if (method != HttpMethod.Patch || !p.IsBodyParameter() || isCompositeProperties) { foreach (var prop in ((CompositeType)p.ModelType).Properties.Cast <PropertyGo>()) { var primary = prop.ModelType as PrimaryType; var sequence = prop.ModelType as SequenceType; var map = prop.ModelType as DictionaryTypeGo; var composite = prop.ModelType as CompositeType; var propName = prop.FieldName; if (primary != null || sequence != null || map != null) { x.AddRange(prop.ValidateType($"{name}.{propName}", method, true)); } else if (composite != null) { if (composite.IsPolymorphic) { // we do not generate validation for the polymophic types for now. // There is an issue in go-autorest that causes that we could not properly handle null value of a polymophic type continue; } if (ancestors.Contains(composite.Name)) { x.AddNullValidation($"{name}.{propName}", p.ModelTypeName, p.IsRequired); } else { ancestors.Add(composite.Name); x.AddRange(prop.ValidateCompositeType($"{name}.{propName}", method, ancestors, true)); ancestors.Remove(composite.Name); } } } } List <string> y = new List <string>(); if (x.Count > 0) { if (p.CheckNull() || isCompositeProperties) { y.AddRange(x.AddChain(name, p.ModelTypeName, NullConstraint, p.IsRequired)); } else { y.AddRange(x); } } else { if (p.IsRequired && (p.CheckNull() || isCompositeProperties)) { y.AddNullValidation(name, p.ModelTypeName, p.IsRequired); } } return(y); }