public string Gen(SwaggerDocument service,string root,SwaggerToolSettings setting) { var collectionId = PostMan.GetId(); var apis = service.Operations; var requests = GetPostmanRequests(apis, collectionId, root,setting); var collection = new PostmanCollection { id = collectionId, name = setting.PostmanGen.name, description = "", //在文件夹出现的order Id不能出现该order中 // order = requests.Select(x => x.id).ToList(), timestamp = DateTime.Now.DateTimeToStamp(), requests = requests }; //按照tag分组 List<Postfolder> folders = new List<Postfolder>(); var groups = requests.GroupBy(s => s.tagname); foreach (var item in groups) { Postfolder floder = new Postfolder(); floder.id = PostMan.GetId(); if (service.Tags != null) { var desc = service.Tags.Where(p => p.Name == item.Key).FirstOrDefault(); if (desc!=null) { floder.name = desc.Description; } else { floder.name = item.Key; } } else { floder.name = item.Key; } floder.order = requests.Where(p => p.tagname == item.Key).Select(s => s.id).ToList(); foreach (var req in requests.Where(p => p.tagname == item.Key).ToList()) { req.folder = floder.id; } folders.Add(floder); } collection.folders = folders; return JsonConvert.SerializeObject(collection); }
public string Gen(SwaggerDocument service, string root, SwaggerToolSettings setting) { var collectionId = PostMan.GetId(); var apis = service.Operations; var requests = GetPostmanRequests(apis, collectionId, root, setting); var collection = new PostmanCollection { id = collectionId, name = setting.PostmanGen.name, description = "", //在文件夹出现的order Id不能出现该order中 // order = requests.Select(x => x.id).ToList(), timestamp = DateTime.Now.DateTimeToStamp(), requests = requests }; //按照tag分组 List <Postfolder> folders = new List <Postfolder>(); var groups = requests.GroupBy(s => s.tagname); foreach (var item in groups) { Postfolder floder = new Postfolder(); floder.id = PostMan.GetId(); if (service.Tags != null) { var desc = service.Tags.Where(p => p.Name == item.Key).FirstOrDefault(); if (desc != null) { floder.name = desc.Description; } else { floder.name = item.Key; } } else { floder.name = item.Key; } floder.order = requests.Where(p => p.tagname == item.Key).Select(s => s.id).ToList(); foreach (var req in requests.Where(p => p.tagname == item.Key).ToList()) { req.folder = floder.id; } folders.Add(floder); } collection.folders = folders; return(JsonConvert.SerializeObject(collection)); }