コード例 #1
0
        /// <summary>
        /// 递归获取 Body 示例
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        private object GetExapmple(string key)
        {
            if (key == null || Schemas.ContainsKey(key) == false)
            {
                return(null);
            }
            var schema = Schemas.SingleOrDefault(x => x.Key == key).Value;

            if (schema.Properties.Any() == false)
            {
                return(null);
            }
            var exapmle = new ModelExample();

            foreach (var item in schema.Properties)
            {
                if (item.Value.IsObject(Schemas))
                {
                    var objKey = item.Value.Reference.Id;
                    if (objKey == key)
                    {
                        exapmle.Add(item.Key, null);
                    }
                    else
                    {
                        exapmle.Add(item.Key, GetExapmple(objKey));
                    }
                }
                else if (item.Value.IsArray())
                {
                    if (item.Value.IsBaseTypeArray())
                    {
                        exapmle.Add(item.Key, new[] { GetExapmple(item.Value.Items.Type) });
                    }
                    else
                    {
                        exapmle.Add(item.Key, new[] { GetExapmple(item.Value.Items.Reference.Id) });
                    }
                }
                else
                {
                    if (item.Value.IsEnum(Schemas))
                    {
                        exapmle.Add(item.Key, GetEnumValues(item.Value.Reference.Id).Min());
                    }
                    else
                    {
                        exapmle.Add(item.Key, GetDefaultValue(item.Value.Format ?? item.Value.Type));
                    }
                }
            }
            return(exapmle);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Valvula/Useful-Classes
 static void repInsert()
 {
     using (Repository <ModelExample> rep = new Repository <ModelExample>())
     {
         ModelExample example = new ModelExample
         {
             Name    = "Some Name",
             Age     = 18,
             Address = "Some Address"
         };
         rep.Insert(example);
     }
 }
コード例 #3
0
 public ModelExample Post(ModelExample inputData)
 {
     return(new ModelExample {
         ModelValue = inputData.ModelValue
     });
 }