Exemple #1
0
        public void ParseCompleteSwagger()
        {
            var vocab = OpenApiVocab.Create();

            var stream = this.GetType().Assembly
                         .GetManifestResourceStream(this.GetType(), "forecast.io.swagger.json");

            var swaggerDoc = new OpenApiDocument();

            JsonStreamingParser.ParseStream(stream, swaggerDoc, vocab);

            Assert.Equal("2.0", swaggerDoc.Version);
            Assert.Equal(1, swaggerDoc.Schemes.Count);
            Assert.Equal("https", swaggerDoc.Schemes.First());

            Assert.Equal(1, swaggerDoc.Paths.Count);
            Assert.Equal(swaggerDoc.Paths.Keys.First(), "/forecast/{apiKey}/{latitude},{longitude}");
            var path = swaggerDoc.Paths.Values.First();

            Assert.Equal(1, path.Operations.Count);
            var operation = path.Operations.Values.First();

            Assert.Equal("Forecast", operation.Id);

            Assert.False(String.IsNullOrEmpty(swaggerDoc.Info.Description));
            Assert.False(String.IsNullOrEmpty(swaggerDoc.Info.Title));
            Assert.True(String.IsNullOrEmpty(swaggerDoc.Info.Version));
        }
        public void ParseSwaggerPaths()
        {
            var swaggerDoc = new OpenApiDocument();

            swaggerDoc.AddPath("foo", p => {
                p.AddOperation("get", "fooget");
            });

            swaggerDoc.AddPath("bar", p => {
                p.AddOperation("get", "barget");
            });

            swaggerDoc.AddPath("baz", p => {
                p.AddOperation("get", "bazget");
                p.AddOperation("put", "bazput");
            });


            var swaggerstring = swaggerDoc.ToString();

            _Output.WriteLine(swaggerstring);

            var newDoc = new OpenApiDocument();

            JsonStreamingParser.ParseStream(swaggerstring.ToMemoryStream(), newDoc, OpenApiVocab.Create());
        }
        public void ParseSimpleSwagger()
        {
            var jObject = new JObject(new JProperty("swagger", "2.0"),
                                      new JProperty("x-unknown", "blah"),
                                      new JProperty("info",
                                                    new JObject(
                                                        new JProperty("title", "This is the title"),
                                                        new JProperty("description", "This is the description"),
                                                        new JProperty("version", "1.1")
                                                        ))
                                      );

            var doc = new OpenApiDocument();

            JsonStreamingParser.ParseStream(jObject.ToMemoryStream(), doc, OpenApiVocab.Create());
        }
        public void ParseCompleteSwagger()
        {
            DiagnosticListener listener = new DiagnosticListener("Testing");

            JsonStreamingParser.DiagSource = listener;
            listener.Subscribe(new ConsoleLogger(this.output));

            Vocabulary vocab = OpenApiVocab.Create();

            var stream = typeof(ParsingTests).Assembly
                         .GetManifestResourceStream(typeof(ParsingTests), "forecast.io.swagger.json");

            var swaggerDoc = new OpenApiDocument();

            JsonStreamingParser.ParseStream(stream, swaggerDoc, vocab);

            Assert.Equal("2.0", swaggerDoc.Version);
            Assert.Equal(1, swaggerDoc.Schemes.Count);
            Assert.Equal("https", swaggerDoc.Schemes.First());
            Assert.True(swaggerDoc.Paths.Count > 0);
            Assert.False(String.IsNullOrEmpty(swaggerDoc.Info.Description));
            Assert.False(String.IsNullOrEmpty(swaggerDoc.Info.Title));
            Assert.True(String.IsNullOrEmpty(swaggerDoc.Info.Version));
        }
        public void ParseEmbeddedSwagger()
        {
            var stream = typeof(ParsingTests).Assembly.GetManifestResourceStream(typeof(ParsingTests), "forecast.io.swagger.json");

            JsonStreamingParser.ParseStream(stream, new OpenApiDocument(), OpenApiVocab.Create());
        }