/// <summary> /// 获取 Body 示例 /// </summary> /// <param name="apiSchema"></param> /// <returns></returns> private object GetExapmple(OpenApiSchema apiSchema) { object exapmle = null; if (apiSchema.IsObject(Schemas)) { var key = apiSchema.Reference.Id; exapmle = GetExapmple(key); } else if (apiSchema.IsArray()) { if (apiSchema.IsBaseTypeArray()) { exapmle = new[] { GetDefaultValue(apiSchema.Items.Type) } } ; else { exapmle = new[] { GetExapmple(apiSchema.Items.Reference.Id) } }; } else if (apiSchema.IsEnum(Schemas)) { var key = apiSchema.Reference.Id; exapmle = GetEnum(key).Select(x => x.Value).Min(); } else { exapmle = GetDefaultValue(apiSchema.Type); } return(exapmle); }
/// <summary> /// 获取 Body 参数说明 /// </summary> /// <param name="apiSchema"></param> /// <param name="func"></param> /// <returns></returns> private object GetModelInfo(OpenApiSchema apiSchema, Func <string, object> func) { object info = null; var key = ""; if (apiSchema.IsObject(Schemas) || apiSchema.IsEnum(Schemas)) { key = apiSchema.Reference.Id; } else if (apiSchema.IsArray()) { key = apiSchema.Items.Type ?? apiSchema.Items.Reference.Id; } else if (apiSchema.IsBaseType()) { key = apiSchema.Type; } if (key != null) { info = func(key); } return(info); }