Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // Parse options and show helptext if insufficient
            Options o = new Options();

            Parser.Default.ParseArguments(args, o);
            if (!o.IsValid())
            {
                var help = HelpText.AutoBuild(o);
                Console.WriteLine(help.ToString());
                return;
            }

            // First parse the file
            SwaggerRenderTask task = ParseRenderTask(o);

            if (task == null)
            {
                return;
            }

            // Download the swagger file
            SwaggerInfo api = DownloadSwaggerJson(o, task);

            if (api == null)
            {
                return;
            }

            // Render output
            Console.WriteLine($"***** Beginning render stage");
            Render(task, api);
        }
Ejemplo n.º 2
0
        public static void Render(SwaggerRenderTask task, SwaggerInfo api)
        {
            // Render each target
            foreach (var target in task.targets)
            {
                Console.WriteLine($"***** Rendering {target.name}");
                target.Render(api);
            }

            // Done
            Console.WriteLine("***** Done");
        }
Ejemplo n.º 3
0
        private static SwaggerRenderTask ParseRenderTask(Options o)
        {
            SwaggerRenderTask task = null;

            try {
                Console.WriteLine($"***** Parsing render file: {o.SwaggerRenderPath}");
                var contents = File.ReadAllText(o.SwaggerRenderPath);
                task = JsonConvert.DeserializeObject <SwaggerRenderTask>(contents);

                // Create all razor templates
                string baseFolder = Path.GetDirectoryName(o.SwaggerRenderPath);
                foreach (var target in task.targets)
                {
                    target.ParseRazorTemplates(baseFolder);
                }
                return(task);

                // If anything blew up, refuse to continue
            } catch (Exception ex) {
                Console.WriteLine($"Exception parsing render task: {ex.Message}");
                return(null);
            }
        }
Ejemplo n.º 4
0
        private static SwaggerInfo DownloadSwaggerJson(Options o, SwaggerRenderTask task)
        {
            string      swaggerJson = null;
            SwaggerInfo api         = null;

            // Download the swagger JSON file from the server
            try {
                Console.WriteLine($"***** Downloading swagger JSON from {task.swaggerUri}");
                var response = _client.GetAsync(task.swaggerUri).Result;
                swaggerJson = response.Content.ReadAsStringAsync().Result;
            } catch (Exception ex) {
                Console.WriteLine($"Exception downloading swagger JSON file: {ex.ToString()}");
                return(null);
            }

            // Parse the swagger JSON file
            try {
                Console.WriteLine($"***** Processing swagger JSON");
                api = ProcessSwagger(swaggerJson);
            } catch (Exception ex) {
                Console.WriteLine($"Exception processing swagger JSON file: {ex.ToString()}");
            }
            return(api);
        }