Пример #1
0
        private static void GenerateCodeInto(Action <IEnumerable <LogMessage> > processMessages)
        {
            using (NewContext)
            {
                var plugin   = ExtensionsLoader.GetPlugin();
                var modeler  = ExtensionsLoader.GetModeler();
                var messages = new List <LogMessage>();
                Logger.Instance.AddListener(new SignalingLogListener(Category.Info, message => messages.Add(message)));
                try
                {
                    var codeModel = modeler.Build();

                    using (plugin.Activate())
                    {
                        // load model into language-specific code model
                        codeModel = plugin.Serializer.Load(codeModel);

                        // apply language-specific tranformation (more than just language-specific types)
                        // used to be called "NormalizeClientModel" .
                        codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                        // Generate code from CodeModel.
                        plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
                    }
                }
                finally
                {
                    processMessages(messages);
                }
            }
        }
Пример #2
0
        public void ModelerLoadsFromJsonFile()
        {
            var settings = new Settings {Modeler = "Swagger", Input = "RedisResource.json", FileSystem = _fileSystem};
            Modeler modeler = ExtensionsLoader.GetModeler(settings);

            Assert.Equal("Swagger", modeler.Name);
        }
Пример #3
0
        public void TestParameterizedHostFromSwagger()
        {
            var settings = new Settings
            {
                Namespace     = "Test",
                Modeler       = "Swagger",
                CodeGenerator = "CSharp",
                Input         = Path.Combine("Swagger", "swagger-x-ms-parameterized-host.json"),
                Header        = "NONE"
            };

            var modeler = ExtensionsLoader.GetModeler(settings);
            var client  = modeler.Build();

            var hostExtension = client.Extensions["x-ms-parameterized-host"] as JObject;

            Assert.NotNull(hostExtension);

            var hostTemplate     = (string)hostExtension["hostTemplate"];
            var jArrayParameters = hostExtension["parameters"] as JArray;

            Assert.NotNull(jArrayParameters);

            Assert.Equal(2, jArrayParameters.Count);
            Assert.Equal("{accountName}.{host}", hostTemplate);
        }
Пример #4
0
 public void InvalidModelerNameThrowsException()
 {
     string modeler = "Foo.Bar";
     AssertThrows<CodeGenerationException>(
         () => ExtensionsLoader.GetModeler(new Settings {Modeler = modeler, FileSystem = _fileSystem}),
         string.Format("Plugin {0} does not have an assembly name in AutoRest.json", modeler));
 }
Пример #5
0
        internal static MemoryFileSystem GenerateCodeInto(this string inputFile, MemoryFileSystem fileSystem, Settings settings)
        {
            string fileName = Path.GetFileName(inputFile);

            // If inputFile does not contain a path use the local Resource folder
            if (inputFile == fileName)
            {
                fileSystem.Copy(Path.Combine("Resource", inputFile));
            }
            else
            {
                fileSystem.Copy(inputFile);
            }

            settings.Input = fileName;

            var codeGenerator = new CSharpCodeGenerator(settings);
            var modeler       = ExtensionsLoader.GetModeler(settings);
            var sc            = modeler.Build();

            codeGenerator.NormalizeClientModel(sc);
            codeGenerator.Generate(sc).GetAwaiter().GetResult();

            return(fileSystem);
        }
Пример #6
0
        /// <summary>
        /// Generates client using provided settings.
        /// </summary>
        /// <param name="settings">Code generator settings.</param>
        public static void Generate(Settings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            Logger.Entries.Clear();
            Logger.LogInfo(Resources.AutoRestCore, Version);
            CodeGenerator codeGenerator = ExtensionsLoader.GetCodeGenerator(settings);
            Modeler       modeler       = ExtensionsLoader.GetModeler(settings);

            settings.Validate();
            ServiceClient serviceClient;

            try
            {
                serviceClient = modeler.Build();
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorGeneratingClientModel, exception.Message);
            }
            try
            {
                codeGenerator.NormalizeClientModel(serviceClient);
                codeGenerator.Generate(serviceClient).GetAwaiter().GetResult();
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorSavingGeneratedCode, exception.Message);
            }
        }
Пример #7
0
        public void NullOrEmptyAutoRestSettings()
        {
            Assert.Throws<ArgumentNullException>(() => ExtensionsLoader.GetCodeGenerator(null));
            Assert.Throws<ArgumentException>(() => ExtensionsLoader.GetCodeGenerator(
                new Settings {CodeGenerator = string.Empty, FileSystem = _fileSystem}));

            Assert.Throws<ArgumentNullException>(() => ExtensionsLoader.GetModeler(null));
            Assert.Throws<ArgumentException>(() => ExtensionsLoader.GetModeler(
                new Settings {Modeler = string.Empty, FileSystem = _fileSystem}));
        }
Пример #8
0
        internal static MemoryFileSystem GenerateCodeInto(this string testName, MemoryFileSystem fileSystem, Settings settings)
        {
            // copy the whole input directory into the memoryfilesystem.
            fileSystem.CopyFolder("Resource", testName, "");

            // find the appropriately named .yaml or .json file for the swagger.
            foreach (var ext in new[] { ".yaml", ".json", ".md" })
            {
                var name = testName + ext;
                if (fileSystem.FileExists(name))
                {
                    settings.Input = name;
                }
            }

            if (string.IsNullOrWhiteSpace(settings.Input))
            {
                throw new Exception($"Can't find swagger file ${testName} [.yaml] [.json] [.md]");
            }

            var plugin    = ExtensionsLoader.GetPlugin();
            var modeler   = ExtensionsLoader.GetModeler();
            var codeModel = modeler.Build();

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.AfterModelCreation, codeModel);

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.BeforeLoadingLanguageSpecificModel, codeModel);

            using (plugin.Activate())
            {
                // load model into language-specific code model
                codeModel = plugin.Serializer.Load(codeModel);

                // we've loaded the model, run the extensions for after it's loaded
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLoadingLanguageSpecificModel, codeModel);

                // apply language-specific tranformation (more than just language-specific types)
                // used to be called "NormalizeClientModel" .
                codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLanguageSpecificTransform, codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.BeforeGeneratingCode, codeModel);

                // Generate code from CodeModel.
                plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
            }

            return(fileSystem);
        }
Пример #9
0
 public void InvalidModelerNameThrowsException()
 {
     using (NewContext)
     {
         string modeler  = "Foo.Bar";
         var    settings = new Settings {
             Modeler = modeler, FileSystem = _fileSystem
         };
         AssertThrows <CodeGenerationException>(
             () => ExtensionsLoader.GetModeler(),
             string.Format("Plugin {0} not found", modeler));
     }
 }
Пример #10
0
        internal static MemoryFileSystem GenerateCodeInto(this string inputFile, MemoryFileSystem fileSystem, Settings settings)
        {
            string fileName = Path.GetFileName(inputFile);

            // If inputFile does not contain a path use the local Resource folder
            if (inputFile == fileName)
            {
                fileSystem.Copy(Path.Combine("Resource", inputFile));
            }
            else
            {
                fileSystem.Copy(inputFile);
            }

            settings.Input = fileName;


            var plugin    = ExtensionsLoader.GetPlugin();
            var modeler   = ExtensionsLoader.GetModeler();
            var codeModel = modeler.Build();

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.AfterModelCreation, codeModel);

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.BeforeLoadingLanguageSpecificModel, codeModel);

            using (plugin.Activate())
            {
                // load model into language-specific code model
                codeModel = plugin.Serializer.Load(codeModel);

                // we've loaded the model, run the extensions for after it's loaded
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLoadingLanguageSpecificModel, codeModel);

                // apply language-specific tranformation (more than just language-specific types)
                // used to be called "NormalizeClientModel" .
                codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLanguageSpecificTransform, codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.BeforeGeneratingCode, codeModel);

                // Generate code from CodeModel.
                plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
            }

            return(fileSystem);
        }
Пример #11
0
        /// <summary>
        /// Generates client using provided settings.
        /// </summary>
        /// <param name="settings">Code generator settings.</param>
        public static void Generate(Settings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            Logger.Entries.Clear();
            Logger.LogInfo(Resources.AutoRestCore, Version);
            Modeler       modeler       = ExtensionsLoader.GetModeler(settings);
            ServiceClient serviceClient = null;

            IEnumerable <ValidationMessage> messages = new List <ValidationMessage>();

            try
            {
                serviceClient = modeler.Build(out messages);
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorGeneratingClientModel, exception.Message);
            }
            finally
            {
                // Make sure to log any validation messages
                foreach (var message in messages)
                {
                    Logger.Entries.Add(new LogEntry(message.Severity, message.ToString()));
                }
                if (messages.Any(entry => entry.Severity >= settings.ValidationLevel))
                {
                    throw ErrorManager.CreateError(null, Resources.ErrorGeneratingClientModel, Resources.CodeGenerationError);
                }
            }

            CodeGenerator codeGenerator = ExtensionsLoader.GetCodeGenerator(settings);

            Logger.WriteOutput(codeGenerator.UsageInstructions);

            settings.Validate();
            try
            {
                codeGenerator.NormalizeClientModel(serviceClient);
                codeGenerator.Generate(serviceClient).GetAwaiter().GetResult();
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorSavingGeneratedCode, exception.Message);
            }
        }
Пример #12
0
 public void NullOrEmptyAutoRestSettings()
 {
     using (NewContext)
     {
         var settings = new Settings {
             CodeGenerator = string.Empty, FileSystem = _fileSystem
         };
         Assert.Throws <ArgumentException>(() => ExtensionsLoader.GetPlugin());
     }
     using (NewContext)
     {
         var settings = new Settings {
             Modeler = string.Empty, FileSystem = _fileSystem
         };
         Assert.Throws <ArgumentException>(() => ExtensionsLoader.GetModeler());
     }
 }
Пример #13
0
        private static void GenerateCodeInto(Action <IEnumerable <LogMessage> > processMessages)
        {
            using (NewContext)
            {
                var plugin   = ExtensionsLoader.GetPlugin();
                var modeler  = ExtensionsLoader.GetModeler();
                var messages = new List <LogMessage>();
                Logger.Instance.AddListener(new SignalingLogListener(Category.Info, message => messages.Add(message)));
                try
                {
                    var codeModel = modeler.Build();

                    // After swagger Parser
                    codeModel = AutoRestController.RunExtensions(Trigger.AfterModelCreation, codeModel);

                    // After swagger Parser
                    codeModel = AutoRestController.RunExtensions(Trigger.BeforeLoadingLanguageSpecificModel, codeModel);

                    using (plugin.Activate())
                    {
                        // load model into language-specific code model
                        codeModel = plugin.Serializer.Load(codeModel);

                        // we've loaded the model, run the extensions for after it's loaded
                        codeModel = AutoRestController.RunExtensions(Trigger.AfterLoadingLanguageSpecificModel, codeModel);

                        // apply language-specific tranformation (more than just language-specific types)
                        // used to be called "NormalizeClientModel" .
                        codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                        // next set of extensions
                        codeModel = AutoRestController.RunExtensions(Trigger.AfterLanguageSpecificTransform, codeModel);

                        // next set of extensions
                        codeModel = AutoRestController.RunExtensions(Trigger.BeforeGeneratingCode, codeModel);

                        // Generate code from CodeModel.
                        plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
                    }
                }
                finally
                {
                    processMessages(messages);
                }
            }
        }
Пример #14
0
        public void TestSettingsFromSwagger()
        {
            var settings = new Settings
            {
                Namespace = "Test",
                Modeler = "Swagger",
                CodeGenerator = "CSharp",
                Input = Path.Combine("Swagger", "swagger-x-ms-code-generation-settings.json"),
                Header = "NONE"
            };
            var modeler = ExtensionsLoader.GetModeler(settings);
            var client = modeler.Build();
            var codeGenerator = ExtensionsLoader.GetCodeGenerator(settings) as CSharpCodeGenerator;
            settings.Validate();

            Assert.Equal("MIT", settings.Header);
            Assert.Equal(true, codeGenerator.InternalConstructors);
        }
Пример #15
0
        internal static MemoryFileSystem GenerateCodeInto(this string inputDir, MemoryFileSystem fileSystem, Settings settings)
        {
            fileSystem.Copy(Path.Combine("Resource", inputDir));
            var fileExt = (File.Exists(Path.Combine("Resource", Path.Combine(inputDir, inputDir + ".yaml"))) ? ".yaml" : ".json");

            settings.Input = Path.Combine("Resource", Path.Combine(inputDir, inputDir + fileExt));


            var plugin    = ExtensionsLoader.GetPlugin();
            var modeler   = ExtensionsLoader.GetModeler();
            var codeModel = modeler.Build();

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.AfterModelCreation, codeModel);

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.BeforeLoadingLanguageSpecificModel, codeModel);

            using (plugin.Activate())
            {
                // load model into language-specific code model
                codeModel = plugin.Serializer.Load(codeModel);

                // we've loaded the model, run the extensions for after it's loaded
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLoadingLanguageSpecificModel, codeModel);

                // apply language-specific tranformation (more than just language-specific types)
                // used to be called "NormalizeClientModel" .
                codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLanguageSpecificTransform, codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.BeforeGeneratingCode, codeModel);

                // Generate code from CodeModel.
                plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
            }

            return(fileSystem);
        }
Пример #16
0
        /// <summary>
        /// Compares two specifications.
        /// </summary>
        public static void Compare()
        {
            if (Settings.Instance == null)
            {
                throw new ArgumentNullException("settings");
            }
            Logger.Instance.Log(Category.Info, Resources.AutoRestCore, Version);
            Modeler modeler = ExtensionsLoader.GetModeler();

            try
            {
                foreach (var message in modeler.Compare())
                {
                    Logger.Instance.Log(message);
                }
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(Resources.ErrorGeneratingClientModel, exception);
            }
        }
Пример #17
0
        internal static MemoryFileSystem GenerateCodeInto(this string testName, MemoryFileSystem inputFileSystem, Settings settings)
        {
            Settings.Instance.FileSystemInput = inputFileSystem;
            // copy the whole input directory into the memoryfilesystem.
            inputFileSystem.CopyFolder("Resource", testName, "");

            // find the appropriately named .yaml or .json file for the swagger.
            foreach (var ext in new[] { ".yaml", ".json", ".md" })
            {
                var name = testName + ext;
                if (inputFileSystem.FileExists(name))
                {
                    settings.Input = name;
                }
            }

            if (string.IsNullOrWhiteSpace(settings.Input))
            {
                throw new Exception($"Can't find swagger file ${testName} [.yaml] [.json] [.md]");
            }

            var plugin    = ExtensionsLoader.GetPlugin();
            var modeler   = ExtensionsLoader.GetModeler();
            var codeModel = modeler.Build();

            using (plugin.Activate())
            {
                // load model into language-specific code model
                codeModel = plugin.Serializer.Load(codeModel);

                // apply language-specific tranformation (more than just language-specific types)
                // used to be called "NormalizeClientModel" .
                codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                // Generate code from CodeModel.
                plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();

                return(settings.FileSystemOutput);
            }
        }
Пример #18
0
        internal static MemoryFileSystem GenerateCodeInto(this string inputFile, MemoryFileSystem fileSystem)
        {
            fileSystem.Copy(Path.Combine("Resource", inputFile));

            var settings = new Settings
            {
                Modeler         = "Swagger",
                CodeGenerator   = "CSharp",
                FileSystem      = fileSystem,
                OutputDirectory = "GeneratedCode",
                Input           = inputFile,
            };

            var     codeGenerator = new CSharpCodeGenerator(settings);
            Modeler modeler       = ExtensionsLoader.GetModeler(settings);
            var     sc            = modeler.Build();

            codeGenerator.NormalizeClientModel(sc);
            codeGenerator.Generate(sc).GetAwaiter().GetResult();

            return(fileSystem);
        }
Пример #19
0
        public void TestSettingsFromSwagger()
        {
            using (NewContext)
            {
                var settings = new Settings
                {
                    Namespace     = "Test",
                    Modeler       = "Swagger",
                    CodeGenerator = "CSharp",
                    Input         = Path.Combine("Swagger", "swagger-x-ms-code-generation-settings.json"),
                    Header        = "NONE"
                };
                var modeler = ExtensionsLoader.GetModeler();
                var client  = modeler.Build();
                var plugin  = ExtensionsLoader.GetPlugin() as PluginCs;
                Assert.NotNull(plugin);
                settings.Validate();

                Assert.Equal("MIT", settings.Header);
                Assert.Equal(true, plugin.Settings.InternalConstructors);
            }
        }
Пример #20
0
        private static MemoryFileSystem GenerateCodeInto(MemoryFileSystem fileSystem, Settings settings)
        {
            var plugin    = ExtensionsLoader.GetPlugin();
            var modeler   = ExtensionsLoader.GetModeler();
            var codeModel = modeler.Build();

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.AfterModelCreation, codeModel);

            // After swagger Parser
            codeModel = AutoRestController.RunExtensions(Trigger.BeforeLoadingLanguageSpecificModel, codeModel);

            using (plugin.Activate())
            {
                // load model into language-specific code model
                codeModel = plugin.Serializer.Load(codeModel);

                // we've loaded the model, run the extensions for after it's loaded
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLoadingLanguageSpecificModel, codeModel);

                // apply language-specific tranformation (more than just language-specific types)
                // used to be called "NormalizeClientModel" .
                codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.AfterLanguageSpecificTransform, codeModel);

                // next set of extensions
                codeModel = AutoRestController.RunExtensions(Trigger.BeforeGeneratingCode, codeModel);

                // Generate code from CodeModel.
                plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
            }

            return(fileSystem);
        }
Пример #21
0
        /// <summary>
        /// Compares two specifications.
        /// </summary>
        public static void Compare()
        {
            if (Settings.Instance == null)
            {
                throw new ArgumentNullException("settings");
            }
            Logger.Entries.Clear();
            Logger.LogInfo(Resources.AutoRestCore, Version);
            Modeler modeler = ExtensionsLoader.GetModeler();

            try
            {
                IEnumerable <ComparisonMessage> messages = modeler.Compare();

                foreach (var message in messages)
                {
                    Logger.Entries.Add(new LogEntry(message.Severity, message.ToString()));
                }
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorGeneratingClientModel, exception.Message);
            }
        }
Пример #22
0
        /// <summary>
        /// Generates client using provided settings.
        /// </summary>
        public static void Generate()
        {
            if (Settings.Instance == null)
            {
                throw new ArgumentNullException("settings");
            }
            Logger.Entries.Clear();
            Logger.LogInfo(Resources.AutoRestCore, Version);

            CodeModel codeModel = null;

            var modeler = ExtensionsLoader.GetModeler();

            try
            {
                IEnumerable <ValidationMessage> messages = new List <ValidationMessage>();

                // generate model from swagger
                codeModel = modeler.Build(out messages);

                // After swagger Parser
                codeModel = RunExtensions(Trigger.AfterModelCreation, codeModel);

                // After swagger Parser
                codeModel = RunExtensions(Trigger.BeforeLoadingLanguageSpecificModel, codeModel);

                foreach (var message in messages)
                {
                    Logger.Entries.Add(new LogEntry(message.Severity, message.ToString()));
                }

                if (messages.Any(entry => entry.Severity >= Settings.Instance.ValidationLevel))
                {
                    throw ErrorManager.CreateError(null, Resources.ErrorGeneratingClientModel, "Errors found during Swagger validation");
                }
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorGeneratingClientModel, exception.Message);
            }

            var plugin = ExtensionsLoader.GetPlugin();

            Logger.WriteOutput(plugin.CodeGenerator.UsageInstructions);

            Settings.Instance.Validate();
            try
            {
                var genericSerializer = new ModelSerializer <CodeModel>();
                var modelAsJson       = genericSerializer.ToJson(codeModel);

                // ensure once we're doing language-specific work, that we're working
                // in context provided by the language-specific transformer.
                using (plugin.Activate())
                {
                    // load model into language-specific code model
                    codeModel = plugin.Serializer.Load(modelAsJson);

                    // we've loaded the model, run the extensions for after it's loaded
                    codeModel = RunExtensions(Trigger.AfterLoadingLanguageSpecificModel, codeModel);

                    // apply language-specific tranformation (more than just language-specific types)
                    // used to be called "NormalizeClientModel" .
                    codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                    // next set of extensions
                    codeModel = RunExtensions(Trigger.AfterLanguageSpecificTransform, codeModel);


                    // next set of extensions
                    codeModel = RunExtensions(Trigger.BeforeGeneratingCode, codeModel);

                    // Generate code from CodeModel.
                    plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
                }
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(exception, Resources.ErrorSavingGeneratedCode, exception.Message);
            }
        }
Пример #23
0
        /// <summary>
        /// Generates client using provided settings.
        /// </summary>
        public static void Generate()
        {
            if (Settings.Instance == null)
            {
                throw new ArgumentNullException("settings");
            }
            Logger.Instance.Log(Category.Info, Resources.AutoRestCore, Version);

            CodeModel codeModel = null;

            var modeler = ExtensionsLoader.GetModeler();

            try
            {
                using (NewContext)
                {
                    bool validationErrorFound = false;
                    Logger.Instance.AddListener(new SignalingLogListener(Settings.Instance.ValidationLevel, _ => validationErrorFound = true));

                    // generate model from swagger
                    codeModel = modeler.Build();

                    if (validationErrorFound)
                    {
                        Logger.Instance.Log(Category.Error, "Errors found during Swagger validation");
                    }
                }
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(Resources.ErrorGeneratingClientModel, exception);
            }

            if (Settings.Instance.JsonValidationMessages)
            {
                return; // no code gen in Json validation mode
            }

            var plugin = ExtensionsLoader.GetPlugin();

            Console.ResetColor();

            try
            {
                var genericSerializer = new ModelSerializer <CodeModel>();
                var modelAsJson       = genericSerializer.ToJson(codeModel);

                // ensure once we're doing language-specific work, that we're working
                // in context provided by the language-specific transformer.
                using (plugin.Activate())
                {
                    // load model into language-specific code model
                    codeModel = plugin.Serializer.Load(modelAsJson);

                    // apply language-specific tranformation (more than just language-specific types)
                    // used to be called "NormalizeClientModel" .
                    codeModel = plugin.Transformer.TransformCodeModel(codeModel);

                    // Generate code from CodeModel.
                    plugin.CodeGenerator.Generate(codeModel).GetAwaiter().GetResult();
                }
            }
            catch (Exception exception)
            {
                throw ErrorManager.CreateError(Resources.ErrorSavingGeneratedCode, exception);
            }
        }