Exemple #1
0
 public WebApiMethodsGenerator(AmfModel raml, IDictionary <string, ApiObject> schemaResponseObjects,
                               IDictionary <string, ApiObject> schemaRequestObjects, IDictionary <string, string> linkKeysWithObjectNames,
                               IDictionary <string, ApiObject> schemaObjects, IDictionary <string, ApiEnum> enums)
     : base(raml, schemaResponseObjects, schemaRequestObjects, linkKeysWithObjectNames, schemaObjects, enums)
 {
     queryParametersParser = new QueryParametersParser(schemaObjects);
 }
        public RamlModelsGenerator(AmfModel ramlDoc, string targetNamespace, string templatesFolder,
                                   string targetFileName, string destinationFolder) : base(targetNamespace, templatesFolder, targetFileName, destinationFolder)
        {
            this.ramlDoc         = ramlDoc;
            this.targetNamespace = targetNamespace;

            TemplatesFolder = string.IsNullOrWhiteSpace(templatesFolder)
                ? GetDefaultTemplateFolder()
                : templatesFolder;
        }
 protected MethodsGeneratorBase(AmfModel raml, IDictionary <string, ApiObject> schemaResponseObjects,
                                IDictionary <string, ApiObject> schemaRequestObjects, IDictionary <string, string> linkKeysWithObjectNames, IDictionary <string, ApiObject> schemaObjects,
                                IDictionary <string, ApiEnum> enums)
 {
     this.raml = raml;
     this.schemaResponseObjects = schemaResponseObjects;
     this.schemaObjects         = schemaObjects;
     responseTypesService       = new ResponseTypesService(schemaObjects, schemaResponseObjects, linkKeysWithObjectNames, enums);
     requestTypesService        = new RequestTypesService(schemaObjects, schemaRequestObjects, linkKeysWithObjectNames, enums);
     uriParametersGenerator     = new UriParametersGenerator(schemaObjects);
 }
Exemple #4
0
 public ClientMethodsGenerator(AmfModel raml, IDictionary <string, ApiObject> schemaResponseObjects,
                               IDictionary <string, ApiObject> uriParameterObjects, IDictionary <string, ApiObject> queryObjects,
                               IDictionary <string, ApiObject> headerObjects, IDictionary <string, ApiObject> responseHeadersObjects,
                               IDictionary <string, ApiObject> schemaRequestObjects, IDictionary <string, string> linkKeysWithObjectNames,
                               IDictionary <string, ApiObject> schemaObjects, IDictionary <string, ApiEnum> enums)
     : base(raml, schemaResponseObjects, schemaRequestObjects, linkKeysWithObjectNames, schemaObjects, enums)
 {
     this.uriParameterObjects    = uriParameterObjects;
     this.queryObjects           = queryObjects;
     this.headerObjects          = headerObjects;
     this.responseHeadersObjects = responseHeadersObjects;
     queryParametersParser       = new QueryParametersParser(schemaObjects);
 }
Exemple #5
0
        public RamlServerGenerator(AmfModel ramlDoc, string targetNamespace, string templatesFolder,
                                   string targetFileName, string destinationFolder, bool useAsyncMethods, bool targetWebApi)
            : base(targetNamespace, templatesFolder, targetFileName, destinationFolder)
        {
            this.ramlDoc           = ramlDoc;
            this.targetNamespace   = targetNamespace;
            this.destinationFolder = destinationFolder;
            this.useAsyncMethods   = useAsyncMethods;

            TemplatesFolder = string.IsNullOrWhiteSpace(templatesFolder)
                ? GetDefaultTemplateFolder(targetWebApi)
                : templatesFolder;
        }
        public void Generate(AmfModel ramlDoc, string targetFileName, string targetNamespace, string templatesFolder,
                             string destinationFolder)
        {
            templatesFolder = string.IsNullOrWhiteSpace(templatesFolder)
                ? GetTemplateDefaultPath()
                : templatesFolder;


            var model = new ClientGeneratorService(ramlDoc, targetFileName + "Client", targetNamespace, targetNamespace + ".Models").BuildModel();

            var templateFilePath = Path.Combine(templatesFolder, ClientT4TemplateName);
            var extensionPath    = Path.GetDirectoryName(GetType().Assembly.Location) + Path.DirectorySeparatorChar;

            var host   = new CustomCmdLineHost();
            var engine = new Engine();

            host.TemplateFileValue = templateFilePath;

            // Read the T4 from disk into memory
            var templateFileContent = File.ReadAllText(templateFilePath);

            templateFileContent = templateFileContent.Replace("$(binDir)", extensionPath);
            templateFileContent = templateFileContent.Replace("$(ramlFile)", targetFileName.Replace("\\", "\\\\"));
            templateFileContent = templateFileContent.Replace("$(namespace)", targetNamespace);

            host.Session          = host.CreateSession();
            host.Session["model"] = model;

            var output = engine.ProcessTemplate(templateFileContent, host);

            foreach (CompilerError error in host.Errors)
            {
                Console.WriteLine(error.ToString());
            }

            //var t4Service = new T4Service(ServiceProvider.GlobalProvider);
            //var res = t4Service.TransformText(templateFilePath, model, extensionPath, opts.Source, targetNamespace);
            File.WriteAllText(Path.Combine(destinationFolder, targetFileName.Replace(".raml", ".cs")), output, host.FileEncoding);
        }
        private void SetPreview(AmfModel model)
        {
            _model = model;
            var document = model.WebApi;

            Execute.OnUIThreadAsync(() =>
            {
                try
                {
                    StartProgress();
                    ResourcesPreview = GetResourcesPreview(document);
                    StopProgress();
                    SetDefaultNamespaces(RamlTempFilePath);
                    if (document.Version != null)
                    {
                        ApiVersion = NetNamingMapper.GetVersionName(document.Version);
                    }
                    CanImport = true;

                    if (NetNamingMapper.HasIndalidChars(Filename))
                    {
                        ShowErrorAndStopProgress("The specied file name has invalid chars");
                        // txtFileName.Focus();
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorAndStopProgress("Error while parsing raml file. " + ex.Message);
                    logger.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, VisualStudioAutomationHelper.GetExceptionInfo(ex));
                }
                finally
                {
                    StopProgress();
                }
            });
        }
Exemple #8
0
        public void Initialize()
        {
            var parser = new AmfParser();

            model = parser.Load("./specs/account-aggregation-process-api-2.0.0-raml/banking_accounts_process_api.raml").Result;
        }
 protected GeneratorServiceBase(AmfModel raml)
 {
     this.raml = raml;
     //ApplyResourceTypesAndTraits(raml.WebApi.EndPoints);
     //raml1TypesParser = new RamlTypeParser(raml.Shapes, schemaObjects, targetNamespace, enums, warnings);
 }
 public ClientGeneratorService(AmfModel raml, string rootClassName, string baseNamespace, string modelsNamespace) : base(raml)
 {
     this.rootClassName   = rootClassName;
     this.modelsNamespace = modelsNamespace;
     this.baseNamespace   = baseNamespace;
 }
 public WebApiGeneratorService(AmfModel raml, string controllersNamespace, string modelsNamespace) : base(raml)
 {
     this.controllersNamespace = controllersNamespace;
     this.modelsNamespace      = modelsNamespace;
 }
Exemple #12
0
        public void Initialize()
        {
            var parser = new AmfParser();

            model = parser.Load("./specs/oas/json/petstore.json").Result;
        }
Exemple #13
0
        public void Initialize()
        {
            var parser = new AmfParser();

            model = parser.Load("./specs/arrayTypes.raml").Result;
        }
Exemple #14
0
        public void Initialize()
        {
            var parser = new AmfParser();

            model = parser.Load("./specs/typeexpressions.raml").Result;
        }
 public ModelsGeneratorService(AmfModel raml, string modelsNamespace) : base(raml)
 {
     this.modelsNamespace = modelsNamespace;
 }
Exemple #16
0
        public void Initialize()
        {
            var parser = new AmfParser();

            model = parser.Load("./specs/chinook-v1.raml").Result;
        }
Exemple #17
0
        public void Initialize()
        {
            var parser = new AmfParser();

            model = parser.Load("./specs/oas/yaml/api-with-examples.yaml").Result;
        }
Exemple #18
0
        public static async Task <RamlInfo> GetRamlInfo(string ramlSource, AmfModel model = null, string username = null, string password = null)
        {
            var info = new RamlInfo();

            string tempPath;

            var logger = new Logger();

            if (ramlSource.StartsWith("http"))
            {
                Uri uri;
                if (!Uri.TryCreate(ramlSource, UriKind.Absolute, out uri))
                {
                    info.ErrorMessage = "Invalid Url specified: " + uri.AbsoluteUri;
                    logger.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource, info.ErrorMessage);
                    return(info);
                }

                var absolutePath = uri.AbsoluteUri;
                if (absolutePath.Contains("/"))
                {
                    absolutePath = absolutePath.Substring(0, absolutePath.LastIndexOf("/", StringComparison.InvariantCulture) + 1);
                }

                info.AbsolutePath = absolutePath;

                try
                {
                    info.RamlContents = Downloader.GetContents(uri, username, password);
                    tempPath          = Path.GetTempFileName();
                    File.WriteAllText(tempPath, info.RamlContents);
                }
                catch (HttpRequestException rex)
                {
                    var errorMessage = rex.Message;
                    if (rex.InnerException != null)
                    {
                        errorMessage += " - " + rex.InnerException.Message;
                    }

                    if (errorMessage.Contains("404"))
                    {
                        errorMessage = "Url not found, could not load the specified url: " + uri.AbsoluteUri;
                    }

                    info.ErrorMessage = errorMessage;

                    logger.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                                    VisualStudioAutomationHelper.GetExceptionInfo(rex));

                    return(info);
                }
                catch (Exception ex)
                {
                    var errorMessage = ex.Message;
                    if (ex.InnerException != null)
                    {
                        errorMessage += " - " + ex.InnerException.Message;
                    }

                    info.ErrorMessage = "Error when trying to load specified url " + uri.AbsoluteUri + ". " + errorMessage;

                    logger.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                                    VisualStudioAutomationHelper.GetExceptionInfo(ex));

                    return(info);
                }
            }
            else
            {
                if (!File.Exists(ramlSource))
                {
                    info.ErrorMessage = "Error. File " + ramlSource + " does not exist.";
                    return(info);
                }

                info.AbsolutePath = Path.GetDirectoryName(ramlSource) + "\\";

                try
                {
                    info.RamlContents = File.ReadAllText(ramlSource);
                    tempPath          = ramlSource;
                }
                catch (Exception ex)
                {
                    var errorMessage = ex.Message;
                    if (ex.InnerException != null)
                    {
                        errorMessage += " - " + ex.InnerException.Message;
                    }

                    info.ErrorMessage = "Error when trying to read file " + ramlSource + ". " + errorMessage;

                    logger.LogError(VisualStudioAutomationHelper.RamlVsToolsActivityLogSource,
                                    VisualStudioAutomationHelper.GetExceptionInfo(ex));

                    return(info);
                }
            }

            if (model == null)
            {
                var task = new RamlParser().Load(tempPath);
                task.WaitWithPumping();
                info.RamlDocument = task.Result;
            }
            else
            {
                info.RamlDocument = model;
            }

            return(info);
        }