Beispiel #1
0
        private void RenderSingleFile(SwaggerInfo api, RenderTemplateTask template)
        {
            var outputPath = Path.Combine(rootFolder, template.output);

            Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
            var output = template.razor.ExecuteTemplate(api, null, null, null);

            File.WriteAllText(outputPath, output);
        }
Beispiel #2
0
 private void RenderMethods(SwaggerInfo api, RenderTemplateTask template)
 {
     foreach (var method in api.Methods)
     {
         var outputPath = Path.Combine(rootFolder, QuickStringMerge(template.output, method));
         Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
         var output = template.razor.ExecuteTemplate(api, method, null, null);
         File.WriteAllText(outputPath, output);
     }
 }
 private void RenderEnums(SwaggerInfo api, RenderTemplateTask template)
 {
     foreach (var enumDataType in api.Enums)
     {
         var outputPath = Path.Combine(rootFolder, QuickStringMerge(template.output, enumDataType));
         Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
         var output = template.razor.ExecuteTemplate(api, null, null, enumDataType);
         File.WriteAllText(outputPath, output);
     }
 }
Beispiel #4
0
        private void RenderFetchModel(SwaggerInfo api, RenderTemplateTask template)
        {
            var oldModels = api.Models;

            api.Models = (from m in api.Models where m.SchemaName.StartsWith("FetchResult") select m).ToList();
            foreach (var model in api.Models)
            {
                var outputPath = Path.Combine(rootFolder, QuickStringMerge(template.output, model));
                Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                var output = template.razor.ExecuteTemplate(api, null, model, null);
                File.WriteAllText(outputPath, output);
            }
            api.Models = oldModels;
        }
Beispiel #5
0
        private void RenderEnums(SwaggerInfo api, RenderTemplateTask template)
        {
            foreach (var enumInfo in api.Enums)
            {
                // ErrorCodeId is not needed in Apex, all error codes are handled as String
                if ((template.file.Contains("apex_enum_class") || template.file.Contains("apex_meta")) && enumInfo.Name == "ErrorCodeId")
                {
                    continue;
                }

                var outputPath = Path.Combine(rootFolder, QuickStringMerge(template.output, enumInfo));
                Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                var output = template.razor.ExecuteTemplate(api, null, null, enumInfo);
                File.WriteAllText(outputPath, output);
            }
        }
Beispiel #6
0
        private void RenderMethodCategories(SwaggerInfo api, RenderTemplateTask template)
        {
            var categories = (from m in api.Methods select m.Category).Distinct();

            foreach (var c in categories)
            {
                var oldMethods = api.Methods;
                api.Methods = (from m in api.Methods where m.Category == c select m).ToList();
                var outputPath = Path.Combine(rootFolder, QuickStringMerge(template.output, c));
                Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                template.razor.Category = c;
                var output = template.razor.ExecuteTemplate(api, null, null, null);
                template.razor.Category = null;
                File.WriteAllText(outputPath, output);
                api.Methods = oldMethods;
            }
        }
Beispiel #7
0
 private void RenderListModels(SwaggerInfo api, RenderTemplateTask template)
 {
     foreach (var method in api.Methods)
     {
         if (method.ResponseType == "array")
         {
             string modelName = method.parseBracket(method.ResponseTypeName).Substring(4);
             foreach (var model in api.Models)
             {
                 if (model.SchemaName.Contains(modelName) && !model.SchemaName.Contains("FetchResult"))
                 {
                     var outputPath = Path.Combine(rootFolder, QuickStringMerge(template.output, model));
                     Directory.CreateDirectory(Path.GetDirectoryName(outputPath));
                     var output = template.razor.ExecuteTemplate(api, null, model, null);
                     File.WriteAllText(outputPath, output);
                     break;
                 }
             }
         }
     }
 }
Beispiel #8
0
        private SwaggerInfo HandleFilter(SwaggerInfo api, RenderTemplateTask template)
        {
            string templateName = template.file;

            // handle all Apex related filtering
            if (templateName.Contains("apex"))
            {
                ApexFilters filter = new ApexFilters();

                // filtering for Apex enum & model classes
                if (templateName.Contains("apex_enum_class"))
                {
                    return(filter.KeyWordFilter(api, "enum"));
                }
                else if (templateName.Contains("apex_model_class"))
                {
                    return(filter.KeyWordFilter(api, "model"));
                }
            }

            // echo back the original api file if no changes is required
            return(api);
        }