Exemple #1
0
        public void external_docs_pet_check()
        {
            var parser = new AmfParser();
            var model  = parser.Load("./specs/oas/yaml/petstore-with-external-docs.yaml").GetAwaiter().GetResult();

            Assert.IsNotNull(model);
        }
Exemple #2
0
        public static AmfModel Load(this AmfParser parser, string file)
        {
            var task = parser.Load(file);

            task.Wait();
            return(task.Result);
        }
Exemple #3
0
        private async static Task <AmfModel> Test()
        {
            var parser = new AmfParser();
            var a      = await parser.Load("/desarrollo/mulesoft/raml-dotnet-parser-2/source/Raml.Parser.Tests/Specifications/movies-v1.raml");

            return(a);
        }
        public static void Main(string[] args)
        {
            FileStream str    = File.OpenRead(args[0]);
            AmfParser  parser = new AmfParser(str);

            ObjectReader reader;

            if (args.Length > 1)
            {
                reader = GetTypeReader(args[1]);
            }
            else
            {
                reader = DefaultReader;
            }

            object root;

            try {
                root = reader(parser);
            } catch (Exception) {
                Console.WriteLine("Exception at file location {0}", str.Position);
                throw;
            }

            Console.WriteLine("Parsing completed.  At position {0}/{1}.", str.Position, str.Length);
            Console.WriteLine();

            using (XmlTextWriter w = new XmlTextWriter(Console.Out)) {
                w.Formatting = Formatting.Indented;

                Visualizer.Visualize(root).WriteTo(w);
            }
        }
        public void Decode(byte[] bytes)
        {
            using (var ms = new MemoryStream(bytes))
            {
                var ap = new AmfParser(ms);

                Name = (string) ap.ReadNextObject();
                Data = new List<object>();
                while (ms.Length != ms.Position)
                {
                    Data.Add(ap.ReadNextObject());
                }
            }
        }
Exemple #6
0
        public void Decode(byte[] bytes)
        {
            using (var ms = new MemoryStream(bytes))
            {
                var ap = new AmfParser(ms);

                Name = (string)ap.ReadNextObject();
                Data = new List <object>();
                while (ms.Length != ms.Position)
                {
                    Data.Add(ap.ReadNextObject());
                }
            }
        }
Exemple #7
0
        public void Decode(byte[] bytes)
        {
            using (var ms = new MemoryStream(bytes))
            {
                var ap = new AmfParser(ms);
                CommandName   = (string)ap.ReadNextObject();
                TransactionID = (int)((double)ap.ReadNextObject());
                CommandObject = (AmfObject)ap.ReadNextObject();

                while (ms.Length != ms.Position)
                {
                    Arguments.Add(ap.ReadNextObject());
                }
            }
        }
        public void Decode(byte[] bytes)
        {
            using (var ms = new MemoryStream(bytes))
            {
                var ap = new AmfParser(ms);
                CommandName = (string) ap.ReadNextObject();
                TransactionID = (int) ((double) ap.ReadNextObject());
                CommandObject = (AmfObject) ap.ReadNextObject();

                while (ms.Length != ms.Position)
                {
                    Arguments.Add(ap.ReadNextObject());
                }
            }
        }
        private static async Task <AmfModel> GetRamlDocument(Options opts, string destinationFolder, string targetFileName)
        {
            var result = new RamlIncludesManager().Manage(opts.Source, destinationFolder, destinationFolder, opts.Overwrite);

            if (!result.IsSuccess && result.StatusCode != HttpStatusCode.OK)
            {
                throw new HttpSourceErrorException("Error trying to get " + opts.Source + " - status code: " + result.StatusCode);
            }

            if (!Directory.Exists(destinationFolder))
            {
                Directory.CreateDirectory(destinationFolder);
            }

            var path = Path.Combine(destinationFolder, targetFileName);

            File.WriteAllText(path, result.ModifiedContents);
            var parser  = new AmfParser();
            var ramlDoc = await parser.Load(path);

            return(ramlDoc);
        }
 private static object DefaultReader(AmfParser parser)
 {
     return(parser.ReadNextObject());
 }
Exemple #11
0
        public void Initialize()
        {
            var parser = new AmfParser();

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

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

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

            model = parser.Load("./specs/oas/yaml/api-with-examples.yaml").Result;
        }
Exemple #15
0
 public void Initialize()
 {
     parser = new AmfParser();
 }
Exemple #16
0
        public void Initialize()
        {
            var parser = new AmfParser();

            model = parser.Load("./specs/arrayTypes.raml").Result;
        }
Exemple #17
0
        public async Task Should_detect_OAS_type_from_json_file()
        {
            var type = await AmfParser.DetectType("specs/oas/json/api-with-examples.json");

            Assert.AreEqual(SpecificationType.OASJSON, type);
        }
Exemple #18
0
        public async Task Should_detect_OAS_type_from_yaml_file()
        {
            var type = await AmfParser.DetectType("specs/oas/yaml/api-with-examples.yaml");

            Assert.AreEqual(SpecificationType.OASYAML, type);
        }
Exemple #19
0
        public async Task Should_detect_RAML_type_from_file_contents()
        {
            var type = await AmfParser.DetectType("specs/movies-v1.yaml");

            Assert.AreEqual(SpecificationType.RAML, type);
        }
Exemple #20
0
        public async Task Should_detect_RAML_08()
        {
            var type = await AmfParser.DetectType("specs/raml08/chinook.raml");

            Assert.AreEqual(SpecificationType.RAML08, type);
        }
Exemple #21
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 AmfParser().Load(tempPath);
                task.WaitWithPumping();
                info.RamlDocument = task.Result;
            }
            else
            {
                info.RamlDocument = model;
            }

            return(info);
        }
Exemple #22
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;
        }