public static void ForAll(Assembly assembly, string servicePrefix) { var generator = new AssemblyTypeToSwaggerGenerator(assembly.CodeBase); var allClassNames = generator.GetAbpServiceBaseClasses(); foreach (var item in allClassNames) { var service = generator.FromAbpApplicationMoudleAssembly(item, UrlTemplate.Replace("{servicePrefix}", servicePrefix)); if (service == null) continue; var converter = new SwaggerOperationsExtendedConverter(typeof(SwaggerOperationsExtended)); var jsontext = service.ToJson(converter); //gen json file if (HttpContext.Current != null) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/apidoc/")); var file = HttpContext.Current.Server.MapPath("~/apidoc/") + "/" + item + ".js"; if (File.Exists(file)) { File.Delete(file); } var writer = File.CreateText(file); writer.Write(jsontext); writer.Close(); } } }
static void GenJsonForOneClass(string classname, string url, string swagpath, AssemblyTypeToSwaggerGenerator generator, string controllernameused = null) { var swobj = generator.FromAbpApplicationMoudleAssembly(classname, url, controllernameused); if (swobj != null) { //gen json file var jsontext = swobj.ToJson(); if (!string.IsNullOrEmpty(swagpath)) { System.IO.Directory.CreateDirectory(swagpath); //取得类名 var clsplit = classname.Split('.'); //去除AppSerivce if (clsplit != null && clsplit.Length > 0) { classname = clsplit[clsplit.Length - 1]; classname = classname.Replace("AppService", ""); classname = classname.Replace("Service", ""); } if (!string.IsNullOrEmpty(controllernameused)) { classname = controllernameused; } var file = swagpath + "\\" + classname + ".js"; if (File.Exists(file)) { File.Delete(file); } var writer = File.CreateText(file); writer.Write(jsontext); writer.Close(); } } }
public static void ForAll(Assembly assembly, string servicePrefix) { var generator = new AssemblyTypeToSwaggerGenerator(assembly.CodeBase); var allClassNames = generator.GetAbpServiceBaseClasses(); foreach (var item in allClassNames) { var service = generator.FromAbpApplicationMoudleAssembly(item, UrlTemplate.Replace("{servicePrefix}", servicePrefix)); if (service == null) { continue; } var converter = new SwaggerOperationsExtendedConverter(typeof(SwaggerOperationsExtended)); var jsontext = service.ToJson(converter); //gen json file if (HttpContext.Current != null) { Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/apidoc/")); var file = HttpContext.Current.Server.MapPath("~/apidoc/") + "/" + item + ".js"; if (File.Exists(file)) { File.Delete(file); } var writer = File.CreateText(file); writer.Write(jsontext); writer.Close(); } } }