示例#1
0
        public void WriteEmptyObjectWorks2()
        {
            // Arrange
            Action <IOpenApiWriter> writerAction = writer =>
            {
                writer.WriteObject(() =>
                {
                    writer.WriteProperty("security", () =>
                    {
                        writer.WriteArray(() =>
                        {
                            writer.WriteObject(() =>
                            {
                                writer.WriteProperty("petstore_auth", () =>
                                {
                                    writer.WriteArray(() =>
                                    {
                                        writer.WriteValue("write:pets");
                                        writer.WriteValue("read:pets");
                                    });
                                });
                            });
                        });
                    });
                });
            };

            string actual = OpenApiWriterTestHelper.Write(OpenApiTarget.Json, writerAction);

            output.WriteLine(actual);

            // Act & Assert
            Assert.Equal("{ }", actual);
        }
        public void WriteExtensionWithNullValueWorks()
        {
            // Arrange
            OpenApiExtension        ex     = new OpenApiExtension("x-name", null);
            Action <IOpenApiWriter> action = writer =>
            {
                writer.WriteStartObject(); // for valid JSON/Yaml object
                {
                    ex.Write(writer);
                }

                writer.WriteEndObject();
                writer.Flush();
            };

            // Act & Assert
            Assert.Equal("{\n  \"x-name\": null\n}",
                         OpenApiWriterTestHelper.Write(OpenApiTarget.Json, action));
        }