Пример #1
0
        static void Run(string filePath)
        {
            var jsonFile    = new FileInfo(filePath);
            var fileContent = jsonFile.OpenText().ReadToEnd();

            var model = PostManJson.FromJson(fileContent);
            var api   = new PythonModel
            {
                Name = model.Info.Name,
            };

            if (IsChs(api.Name))
            {
                var firstItem = model.Item.Skip(1).Take(1).FirstOrDefault();
                var path      = firstItem?.Request?.Url?.Path;
                if (path?.Count > 0)
                {
                    api.Name = path.FirstOrDefault();
                    api.Name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(api.Name.ToLower());
                }
            }

            string content = api.BuildClassContent(model.Item);

            api.GenerateClassFile(Path.Combine("python", "RequestServices", api.Name + "Service.py"), api.Name, content);
            api.GenerateTestFile(Path.Combine("python", "ServiceTests", api.Name + "Test.py"), api.Name);

            Console.WriteLine("生成代码成功:" + api.Name);
        }
Пример #2
0
        public void ToNgService(string filePath = "./test.json")
        {
            var jsonFile    = new FileInfo(filePath);
            var fileContent = jsonFile.OpenText().ReadToEnd();

            try
            {
                var project = PostManJson.FromJson(fileContent);

                foreach (var service in project.Item)
                {
                    var model = new NgServiceModel
                    {
                        Introduction = service.Name,
                        Methods      = service.Children
                    };

                    var serviceContent = model.BuildServiceContent();

                    // 创建服务文件
                    Console.WriteLine(serviceContent);
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Пример #3
0
        /// <summary>
        /// 生成md文档
        /// </summary>
        /// <param name="filePath">源文件</param>
        /// <param name="outputPath">目标保存文件</param>
        /// <param name="author">作者名</param>
        public void Run(string filePath, string outputPath, string author = "CIMS")
        {
            var jsonFile    = new FileInfo(filePath);
            var fileContent = jsonFile.OpenText().ReadToEnd();

            try
            {
                var model = PostManJson.FromJson(fileContent);
                var api   = new ApiModel
                {
                    Name   = model.Info.Name,
                    Email  = $"{author}@cissdata.com",
                    Author = author
                };


                //设置返回对象
                var successResult = new Result
                {
                    Data      = "",
                    ErrorCode = 0,
                    Status    = 1,
                    Count     = 1,
                    Msg       = ""
                };
                var errorResult = new Result
                {
                    Data      = "",
                    ErrorCode = 1,
                    Status    = 0,
                    Count     = 0,
                    Msg       = ""
                };
                //设置说明内容
                api.Introduction = @"";
                //设置环境变量
                api.Env = new Dictionary <string, string>
                {
                    { "{{header_token}}", "Access-Token" },
                    { "{{header_uuid}}", "UUID" }
                };
                //            api.Common = @"成功返回:
                //```json
                //" + JsonConvert.SerializeObject(successResult, Formatting.Indented) + @"
                //```
                //";
                //            api.Common += @"失败返回:
                //```json
                //" + JsonConvert.SerializeObject(errorResult, Formatting.Indented) + @"
                //```
                //";
                api.WriteToMarkdown(outputPath, model.Item);
            }
            catch (Exception e)
            {
                throw;
                MessageBox.Show("内容解析出错:" + e.Message);
            }
        }
Пример #4
0
        public string ToMarkdown(string fileContent, string author = "niltor")
        {
            var localSettings = ApplicationData.Current.LocalSettings;

            author = localSettings.Values["Author"] as string;
            var    LocalUrl  = localSettings.Values["LocalUrl"] as string;
            var    ActualUrl = localSettings.Values["ActualUrl"] as string;
            string result    = null;

            try
            {
                var model = PostManJson.FromJson(fileContent);
                var api   = new ApiModel
                {
                    Name       = model.Info.Name,
                    Email      = $"{author}@msdev.cc",
                    Author     = author,
                    LocalUrl   = LocalUrl,
                    ReplaceUrl = ActualUrl
                };
                //设置说明内容
                api.Introduction = @"";
                //设置环境变量
                api.Env = new Dictionary <string, string>
                {
                    { "{{header_token}}", "Access-Token" },
                    { "{{header_uuid}}", "UUID" }
                };
                result = api.ToMarkdown(model.Item);
            }
            catch (Exception e)
            {
                //Console.WriteLine("内容解析出错");

                var dialog = new MessageDialog("内容解析出错");
                dialog.ShowAsync();
            }
            return(result);
        }