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); }
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); }
protected virtual MemoryFileSystem CreateMockFilesystem() { var fs = new MemoryFileSystem(); fs.Copy(Path.Combine("Resource", "AutoRest.json")); return(fs); }
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); }
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); }