Esempio n. 1
0
        internal static void ValidateOpenApiDocument(string input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            var stream = GetStream(input);

            OpenApiDocument document;

            document = new OpenApiStreamReader(new OpenApiReaderSettings
            {
                RuleSet = ValidationRuleSet.GetDefaultRuleSet()
            }
                                               ).Read(stream, out var context);

            if (context.Errors.Count != 0)
            {
                foreach (var error in context.Errors)
                {
                    Console.WriteLine(error.ToString());
                }
            }

            var statsVisitor = new StatsVisitor();
            var walker       = new OpenApiWalker(statsVisitor);

            walker.Walk(document);

            Console.WriteLine(statsVisitor.GetStatisticsReport());
        }
Esempio n. 2
0
        internal static async void ValidateOpenApiDocument(string openapi, LogLevel loglevel)
        {
            if (string.IsNullOrEmpty(openapi))
            {
                throw new ArgumentNullException(nameof(openapi));
            }
            var logger = ConfigureLoggerInstance(loglevel);
            var stream = await GetStream(openapi, logger);

            OpenApiDocument document;

            logger.LogTrace("Parsing the OpenApi file");
            document = new OpenApiStreamReader(new OpenApiReaderSettings
            {
                RuleSet = ValidationRuleSet.GetDefaultRuleSet()
            }
                                               ).Read(stream, out var context);

            if (context.Errors.Count != 0)
            {
                foreach (var error in context.Errors)
                {
                    Console.WriteLine(error.ToString());
                }
            }

            var statsVisitor = new StatsVisitor();
            var walker       = new OpenApiWalker(statsVisitor);

            walker.Walk(document);

            logger.LogTrace("Finished walking through the OpenApi document. Generating a statistics report..");
            Console.WriteLine(statsVisitor.GetStatisticsReport());
        }