diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs
index 069f8cd67..c7bf1a558 100644
--- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs
+++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs
@@ -113,7 +113,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog
var walker = new OpenApiWalker(powerShellFormatter);
walker.Walk(document);
}
- WriteOpenApi(options, openApiFormat, openApiVersion, document, logger);
+ await WriteOpenApiAsync(options, openApiFormat, openApiVersion, document, logger, cancellationToken).ConfigureAwait(false);
}
catch (TaskCanceledException)
{
@@ -191,7 +191,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger,
return document;
}
- private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger)
+ private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken)
{
using (logger.BeginScope("Output"))
{
@@ -216,11 +216,11 @@ private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiForma
var stopwatch = new Stopwatch();
stopwatch.Start();
- document.Serialize(writer, openApiVersion);
+ await document.SerializeAsync(writer, openApiVersion, cancellationToken).ConfigureAwait(false);
stopwatch.Stop();
logger.LogTrace("Finished serializing in {ElapsedMilliseconds}ms", stopwatch.ElapsedMilliseconds);
- textWriter.Flush();
+ await textWriter.FlushAsync(cancellationToken).ConfigureAwait(false);
}
}
@@ -769,7 +769,7 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg
// Write OpenAPI to Output folder
options.Output = new(Path.Combine(options.OutputFolder, "openapi.json"));
options.TerseOutput = true;
- WriteOpenApi(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger);
+ await WriteOpenApiAsync(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false);
// Create OpenAIPluginManifest from ApiDependency and OpenAPI document
var manifest = new OpenAIPluginManifest(document.Info?.Title ?? "Title", document.Info?.Title ?? "Title", "https://go.microsoft.com/fwlink/?LinkID=288890", document.Info?.Contact?.Email ?? "placeholder@contoso.com", document.Info?.License?.Url.ToString() ?? "https://placeholderlicenseurl.com")
diff --git a/src/Microsoft.OpenApi.Workbench/MainModel.cs b/src/Microsoft.OpenApi.Workbench/MainModel.cs
index 1cd4f24ac..7eee12251 100644
--- a/src/Microsoft.OpenApi.Workbench/MainModel.cs
+++ b/src/Microsoft.OpenApi.Workbench/MainModel.cs
@@ -270,7 +270,7 @@ internal async Task ParseDocumentAsync()
stopwatch.Reset();
stopwatch.Start();
- Output = WriteContents(document);
+ Output = await WriteContentsAsync(document);
stopwatch.Stop();
RenderTime = $"{stopwatch.ElapsedMilliseconds} ms";
@@ -299,15 +299,15 @@ internal async Task ParseDocumentAsync()
///
/// Write content from the given document based on the format and version set in this class.
///
- private string WriteContents(OpenApiDocument document)
+ private async Task WriteContentsAsync(OpenApiDocument document)
{
var outputStream = new MemoryStream();
- document.Serialize(
+ await document.SerializeAsync(
outputStream,
Version,
Format,
- new()
+ (Writers.OpenApiWriterSettings)new()
{
InlineLocalReferences = InlineLocal,
InlineExternalReferences = InlineExternal
@@ -315,7 +315,7 @@ private string WriteContents(OpenApiDocument document)
outputStream.Position = 0;
- return new StreamReader(outputStream).ReadToEnd();
+ return await new StreamReader(outputStream).ReadToEndAsync();
}
private static MemoryStream CreateStream(string text)
diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs
index 5d59a8de2..9d284db1a 100755
--- a/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs
+++ b/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs
@@ -3,6 +3,8 @@
using System.Globalization;
using System.IO;
+using System.Threading;
+using System.Threading.Tasks;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Properties;
@@ -22,10 +24,11 @@ public static class OpenApiSerializableExtensions
/// The Open API element.
/// The output stream.
/// The Open API specification version.
- public static void SerializeAsJson(this T element, Stream stream, OpenApiSpecVersion specVersion)
+ /// The cancellation token.
+ public static Task SerializeAsJsonAsync(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
- element.Serialize(stream, specVersion, OpenApiFormat.Json);
+ return element.SerializeAsync(stream, specVersion, OpenApiFormat.Json, cancellationToken);
}
///
@@ -35,10 +38,11 @@ public static void SerializeAsJson(this T element, Stream stream, OpenApiSpec
/// The Open API element.
/// The output stream.
/// The Open API specification version.
- public static void SerializeAsYaml(this T element, Stream stream, OpenApiSpecVersion specVersion)
+ /// The cancellation token.
+ public static Task SerializeAsYamlAsync(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
- element.Serialize(stream, specVersion, OpenApiFormat.Yaml);
+ return element.SerializeAsync(stream, specVersion, OpenApiFormat.Yaml, cancellationToken);
}
///
@@ -50,14 +54,16 @@ public static void SerializeAsYaml(this T element, Stream stream, OpenApiSpec
/// The given stream.
/// The Open API specification version.
/// The output format (JSON or YAML).
- public static void Serialize(
+ /// The cancellation token.
+ public static Task SerializeAsync(
this T element,
Stream stream,
OpenApiSpecVersion specVersion,
- OpenApiFormat format)
+ OpenApiFormat format,
+ CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
- element.Serialize(stream, specVersion, format, null);
+ return element.SerializeAsync(stream, specVersion, format, null, cancellationToken);
}
///
@@ -70,12 +76,14 @@ public static void Serialize(
/// The Open API specification version.
/// The output format (JSON or YAML).
/// Provide configuration settings for controlling writing output
- public static void Serialize(
+ /// The cancellation token.
+ public static Task SerializeAsync(
this T element,
Stream stream,
OpenApiSpecVersion specVersion,
OpenApiFormat format,
- OpenApiWriterSettings settings)
+ OpenApiWriterSettings settings,
+ CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
Utils.CheckArgumentNull(stream);
@@ -88,7 +96,7 @@ public static void Serialize(
OpenApiFormat.Yaml => new OpenApiYamlWriter(streamWriter, settings),
_ => throw new OpenApiException(string.Format(SRResource.OpenApiFormatNotSupported, format)),
};
- element.Serialize(writer, specVersion);
+ return element.SerializeAsync(writer, specVersion, cancellationToken);
}
///
@@ -98,7 +106,8 @@ public static void Serialize(
/// The Open API element.
/// The output writer.
/// Version of the specification the output should conform to
- public static void Serialize(this T element, IOpenApiWriter writer, OpenApiSpecVersion specVersion)
+ /// The cancellation token.
+ public static Task SerializeAsync(this T element, IOpenApiWriter writer, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
Utils.CheckArgumentNull(element);
@@ -122,7 +131,7 @@ public static void Serialize(this T element, IOpenApiWriter writer, OpenApiSp
throw new OpenApiException(string.Format(SRResource.OpenApiSpecVersionNotSupported, specVersion));
}
- writer.Flush();
+ return writer.FlushAsync(cancellationToken);
}
///
@@ -131,12 +140,14 @@ public static void Serialize(this T element, IOpenApiWriter writer, OpenApiSp
/// the
/// The Open API element.
/// The Open API specification version.
- public static string SerializeAsJson(
+ /// The cancellation token.
+ public static Task SerializeAsJsonAsync(
this T element,
- OpenApiSpecVersion specVersion)
+ OpenApiSpecVersion specVersion,
+ CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
- return element.Serialize(specVersion, OpenApiFormat.Json);
+ return element.SerializeAsync(specVersion, OpenApiFormat.Json, cancellationToken);
}
///
@@ -145,12 +156,14 @@ public static string SerializeAsJson(
/// the
/// The Open API element.
/// The Open API specification version.
- public static string SerializeAsYaml(
+ /// The cancellation token.
+ public static Task SerializeAsYamlAsync(
this T element,
- OpenApiSpecVersion specVersion)
+ OpenApiSpecVersion specVersion,
+ CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
- return element.Serialize(specVersion, OpenApiFormat.Yaml);
+ return element.SerializeAsync(specVersion, OpenApiFormat.Yaml, cancellationToken);
}
///
@@ -160,20 +173,26 @@ public static string SerializeAsYaml(
/// The Open API element.
/// The Open API specification version.
/// Open API document format.
- public static string Serialize(
+ /// The cancellation token.
+ public static async Task SerializeAsync(
this T element,
OpenApiSpecVersion specVersion,
- OpenApiFormat format)
+ OpenApiFormat format,
+ CancellationToken cancellationToken = default)
where T : IOpenApiSerializable
{
Utils.CheckArgumentNull(element);
using var stream = new MemoryStream();
- element.Serialize(stream, specVersion, format);
+ await element.SerializeAsync(stream, specVersion, format, cancellationToken).ConfigureAwait(false);
stream.Position = 0;
using var streamReader = new StreamReader(stream);
- return streamReader.ReadToEnd();
+#if NET7_0_OR_GREATER
+ return await streamReader.ReadToEndAsync(cancellationToken).ConfigureAwait(false);
+#else
+ return await streamReader.ReadToEndAsync().ConfigureAwait(false);
+#endif
}
}
}
diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
index e0b815f5d..8753755ac 100644
--- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
+++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
@@ -1,6 +1,6 @@
- netstandard2.0
+ netstandard2.0;net8.0
Latest
true
2.0.0-preview4
diff --git a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs
index 0db85ed77..5b43b5187 100644
--- a/src/Microsoft.OpenApi/Models/OpenApiComponents.cs
+++ b/src/Microsoft.OpenApi/Models/OpenApiComponents.cs
@@ -318,7 +318,7 @@ private void RenderComponents(IOpenApiWriter writer, Action schemas))
+ if (loops.TryGetValue(typeof(OpenApiSchema), out var schemas))
{
writer.WriteOptionalMap(OpenApiConstants.Schemas, Schemas, callback);
}
diff --git a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs
index 8cc1fda6c..cf7e53cae 100644
--- a/src/Microsoft.OpenApi/Models/OpenApiDocument.cs
+++ b/src/Microsoft.OpenApi/Models/OpenApiDocument.cs
@@ -83,11 +83,6 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IOpenAp
///
public IDictionary? Extensions { get; set; } = new Dictionary();
- ///
- /// The unique hash code of the generated OpenAPI document
- ///
- public string HashCode => GenerateHashValue(this);
-
///
public IDictionary? Annotations { get; set; }
@@ -243,7 +238,7 @@ public void SerializeAsV2(IOpenApiWriter writer)
{
var loops = writer.GetSettings().LoopDetector.Loops;
- if (loops.TryGetValue(typeof(OpenApiSchema), out List
///
///
- public OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings)
+ protected OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings)
{
Writer = textWriter;
Writer.NewLine = "\n";
@@ -119,12 +121,14 @@ public OpenApiWriterBase(TextWriter textWriter, OpenApiWriterSettings settings)
///
public abstract void WriteRaw(string value);
- ///
- /// Flush the writer.
- ///
- public void Flush()
+ ///
+ public Task FlushAsync(CancellationToken cancellationToken = default)
{
- Writer.Flush();
+#if NET8_OR_GREATER
+ return Writer.FlushAsync(cancellationToken);
+#else
+ return Writer.FlushAsync();
+#endif
}
///
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs
index 4142e9fcd..948c6544c 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiOperationTests.cs
@@ -5,6 +5,7 @@
using System.IO;
using System.Text;
using System.Text.Json.Nodes;
+using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
@@ -234,12 +235,12 @@ public void ParseBasicOperationShouldSucceed()
}
[Fact]
- public void ParseBasicOperationTwiceShouldYieldSameObject()
+ public async Task ParseBasicOperationTwiceShouldYieldSameObject()
{
// Arrange
MapNode node;
using (var stream = new MemoryStream(
- Encoding.Default.GetBytes(_basicOperation.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0))))
+ Encoding.Default.GetBytes(await _basicOperation.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0))))
{
node = TestHelper.CreateYamlMapNode(stream);
}
@@ -269,12 +270,12 @@ public void ParseOperationWithBodyShouldSucceed()
}
[Fact]
- public void ParseOperationWithBodyTwiceShouldYieldSameObject()
+ public async Task ParseOperationWithBodyTwiceShouldYieldSameObject()
{
// Arrange
MapNode node;
using (var stream = new MemoryStream(
- Encoding.Default.GetBytes(_operationWithBody.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0))))
+ Encoding.Default.GetBytes(await _operationWithBody.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0))))
{
node = TestHelper.CreateYamlMapNode(stream);
}
@@ -404,7 +405,7 @@ public void ParseOperationWithBodyAndEmptyConsumesSetsRequestBodySchemaIfExists(
}
[Fact]
- public void ParseV2ResponseWithExamplesExtensionWorks()
+ public async Task ParseV2ResponseWithExamplesExtensionWorks()
{
// Arrange
MapNode node;
@@ -415,7 +416,7 @@ public void ParseV2ResponseWithExamplesExtensionWorks()
// Act
var operation = OpenApiV2Deserializer.LoadOperation(node);
- var actual = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await operation.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
var expected = @"summary: Get all pets
@@ -454,7 +455,7 @@ public void ParseV2ResponseWithExamplesExtensionWorks()
}
[Fact]
- public void LoadV3ExamplesInResponseAsExtensionsWorks()
+ public async Task LoadV3ExamplesInResponseAsExtensionsWorks()
{
// Arrange
MapNode node;
@@ -465,7 +466,7 @@ public void LoadV3ExamplesInResponseAsExtensionsWorks()
// Act
var operation = OpenApiV3Deserializer.LoadOperation(node);
- var actual = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0);
+ var actual = await operation.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0);
// Assert
var expected = @"summary: Get all pets
@@ -504,7 +505,7 @@ public void LoadV3ExamplesInResponseAsExtensionsWorks()
}
[Fact]
- public void LoadV2OperationWithBodyParameterExamplesWorks()
+ public async Task LoadV2OperationWithBodyParameterExamplesWorks()
{
// Arrange
MapNode node;
@@ -515,7 +516,7 @@ public void LoadV2OperationWithBodyParameterExamplesWorks()
// Act
var operation = OpenApiV2Deserializer.LoadOperation(node);
- var actual = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await operation.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
var expected = @"summary: Get all pets
@@ -555,7 +556,7 @@ public void LoadV2OperationWithBodyParameterExamplesWorks()
}
[Fact]
- public void LoadV3ExamplesInRequestBodyParameterAsExtensionsWorks()
+ public async Task LoadV3ExamplesInRequestBodyParameterAsExtensionsWorks()
{
// Arrange
MapNode node;
@@ -566,7 +567,7 @@ public void LoadV3ExamplesInRequestBodyParameterAsExtensionsWorks()
// Act
var operation = OpenApiV3Deserializer.LoadOperation(node);
- var actual = operation.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0);
+ var actual = await operation.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0);
// Assert
var expected = @"summary: Get all pets
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs
index 22747f0cf..a83da5e39 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiDocumentTests.cs
@@ -460,7 +460,7 @@ public async Task ParseDocumentWithPatternPropertiesInSchemaWorks()
prop3:
type: string";
- var actualMediaType = mediaType.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1);
+ var actualMediaType = await mediaType.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1);
// Assert
actualSchema.Should().BeEquivalentTo(expectedSchema);
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs
index c281206e3..864bb5aaa 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs
@@ -32,7 +32,7 @@ public OpenApiDocumentTests()
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
}
- private static T Clone(T element) where T : IOpenApiSerializable
+ private static async Task CloneAsync(T element) where T : IOpenApiSerializable
{
using var stream = new MemoryStream();
var streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture);
@@ -41,15 +41,15 @@ private static T Clone(T element) where T : IOpenApiSerializable
InlineLocalReferences = true
});
element.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
stream.Position = 0;
using var streamReader = new StreamReader(stream);
- var result = streamReader.ReadToEnd();
+ var result = await streamReader.ReadToEndAsync();
return OpenApiModelFactory.Parse(result, OpenApiSpecVersion.OpenApi3_0, out var _);
}
- private static OpenApiSecurityScheme CloneSecurityScheme(OpenApiSecurityScheme element)
+ private static async Task CloneSecuritySchemeAsync(OpenApiSecurityScheme element)
{
using var stream = new MemoryStream();
var streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture);
@@ -58,11 +58,11 @@ private static OpenApiSecurityScheme CloneSecurityScheme(OpenApiSecurityScheme e
InlineLocalReferences = true
});
element.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
stream.Position = 0;
using var streamReader = new StreamReader(stream);
- var result = streamReader.ReadToEnd();
+ var result = await streamReader.ReadToEndAsync();
return OpenApiModelFactory.Parse(result, OpenApiSpecVersion.OpenApi3_0, out var _);
}
@@ -681,7 +681,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
};
// Create a clone of the schema to avoid modifying things in components.
- var petSchema = Clone(components.Schemas["pet1"]);
+ var petSchema = await CloneAsync(components.Schemas["pet1"]);
petSchema.Reference = new()
{
Id = "pet1",
@@ -689,7 +689,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
HostDocument = actual.Document
};
- var newPetSchema = Clone(components.Schemas["newPet"]);
+ var newPetSchema = await CloneAsync(components.Schemas["newPet"]);
newPetSchema.Reference = new()
{
@@ -698,7 +698,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
HostDocument = actual.Document
};
- var errorModelSchema = Clone(components.Schemas["errorModel"]);
+ var errorModelSchema = await CloneAsync(components.Schemas["errorModel"]);
errorModelSchema.Reference = new()
{
@@ -729,7 +729,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
}
};
- var securityScheme1 = CloneSecurityScheme(components.SecuritySchemes["securitySchemeName1"]);
+ var securityScheme1 = await CloneSecuritySchemeAsync(components.SecuritySchemes["securitySchemeName1"]);
securityScheme1.Reference = new OpenApiReference
{
@@ -737,7 +737,7 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
Type = ReferenceType.SecurityScheme
};
- var securityScheme2 = CloneSecurityScheme(components.SecuritySchemes["securitySchemeName2"]);
+ var securityScheme2 = await CloneSecuritySchemeAsync(components.SecuritySchemes["securitySchemeName2"]);
securityScheme2.Reference = new OpenApiReference
{
@@ -1081,7 +1081,6 @@ public async Task ParseModifiedPetStoreDocumentWithTagAndSecurityShouldSucceed()
};
actual.Document.Should().BeEquivalentTo(expected, options => options
- .Excluding(x => x.HashCode)
.Excluding(m => m.Tags[0].Reference)
.Excluding(x => x.Paths["/pets"].Operations[OperationType.Get].Tags[0].Reference)
.Excluding(x => x.Paths["/pets"].Operations[OperationType.Get].Tags[0].Reference.HostDocument)
@@ -1325,7 +1324,7 @@ public async Task ParseDocWithRefsUsingProxyReferencesSucceeds()
// Act
var doc = (await OpenApiDocument.LoadAsync(stream)).Document;
var actualParam = doc.Paths["/pets"].Operations[OperationType.Get].Parameters[0];
- var outputDoc = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0).MakeLineBreaksEnvironmentNeutral();
+ var outputDoc = (await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0)).MakeLineBreaksEnvironmentNeutral();
var expectedParam = expected.Paths["/pets"].Operations[OperationType.Get].Parameters[0];
// Assert
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs
index 6197cca71..8ade58ca5 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiMediaTypeTests.cs
@@ -77,7 +77,7 @@ public async Task ParseMediaTypeWithExamplesShouldSucceed()
}
[Fact]
- public void ParseMediaTypeWithEmptyArrayInExamplesWorks()
+ public async Task ParseMediaTypeWithEmptyArrayInExamplesWorks()
{
// Arrange
var expected = @"{
@@ -107,7 +107,7 @@ public void ParseMediaTypeWithEmptyArrayInExamplesWorks()
// Act
var mediaType = OpenApiV3Deserializer.LoadMediaType(node);
- var serialized = mediaType.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
+ var serialized = await mediaType.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
serialized.MakeLineBreaksEnvironmentNeutral()
diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs
index 8e52ad6aa..a1554352f 100644
--- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs
+++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs
@@ -383,8 +383,8 @@ public async Task ParseAdvancedSchemaWithReferenceShouldSucceed()
};
// We serialize so that we can get rid of the schema BaseUri properties which show up as diffs
- var actual = result.Document.Components.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
- var expected = expectedComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await result.Document.Components.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
+ var expected = await expectedComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual.Should().Be(expected);
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs
index ad2c9ffdb..8c729b7c4 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiCallbackTests.cs
@@ -105,7 +105,7 @@ public async Task SerializeAdvancedCallbackAsV3JsonWorksAsync(bool produceTerseO
// Act
AdvancedCallback.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -122,7 +122,7 @@ public async Task SerializeReferencedCallbackAsV3JsonWorksAsync(bool produceTers
// Act
CallbackProxy.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -139,7 +139,7 @@ public async Task SerializeReferencedCallbackAsV3JsonWithoutReferenceWorksAsync(
// Act
ReferencedCallback.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs
index a959edbf6..3a69b708e 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiComponentsTests.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT license.
using System.Collections.Generic;
+using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
@@ -274,13 +275,13 @@ public class OpenApiComponentsTests
};
[Fact]
- public void SerializeBasicComponentsAsJsonWorks()
+ public async Task SerializeBasicComponentsAsJsonWorks()
{
// Arrange
var expected = @"{ }";
// Act
- var actual = BasicComponents.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await BasicComponents.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -289,13 +290,13 @@ public void SerializeBasicComponentsAsJsonWorks()
}
[Fact]
- public void SerializeBasicComponentsAsYamlWorks()
+ public async Task SerializeBasicComponentsAsYamlWorks()
{
// Arrange
var expected = @"{ }";
// Act
- var actual = BasicComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await BasicComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -304,7 +305,7 @@ public void SerializeBasicComponentsAsYamlWorks()
}
[Fact]
- public void SerializeAdvancedComponentsAsJsonV3Works()
+ public async Task SerializeAdvancedComponentsAsJsonV3Works()
{
// Arrange
var expected =
@@ -347,7 +348,7 @@ public void SerializeAdvancedComponentsAsJsonV3Works()
""";
// Act
- var actual = AdvancedComponents.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await AdvancedComponents.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -356,7 +357,7 @@ public void SerializeAdvancedComponentsAsJsonV3Works()
}
[Fact]
- public void SerializeAdvancedComponentsWithReferenceAsJsonV3Works()
+ public async Task SerializeAdvancedComponentsWithReferenceAsJsonV3Works()
{
// Arrange
var expected =
@@ -405,7 +406,7 @@ public void SerializeAdvancedComponentsWithReferenceAsJsonV3Works()
""";
// Act
- var actual = AdvancedComponentsWithReference.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await AdvancedComponentsWithReference.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -414,7 +415,7 @@ public void SerializeAdvancedComponentsWithReferenceAsJsonV3Works()
}
[Fact]
- public void SerializeAdvancedComponentsAsYamlV3Works()
+ public async Task SerializeAdvancedComponentsAsYamlV3Works()
{
// Arrange
var expected =
@@ -444,7 +445,7 @@ public void SerializeAdvancedComponentsAsYamlV3Works()
""";
// Act
- var actual = AdvancedComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await AdvancedComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -453,7 +454,7 @@ public void SerializeAdvancedComponentsAsYamlV3Works()
}
[Fact]
- public void SerializeAdvancedComponentsWithReferenceAsYamlV3Works()
+ public async Task SerializeAdvancedComponentsWithReferenceAsYamlV3Works()
{
// Arrange
var expected =
@@ -486,7 +487,7 @@ public void SerializeAdvancedComponentsWithReferenceAsYamlV3Works()
""";
// Act
- var actual = AdvancedComponentsWithReference.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await AdvancedComponentsWithReference.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -495,7 +496,7 @@ public void SerializeAdvancedComponentsWithReferenceAsYamlV3Works()
}
[Fact]
- public void SerializeBrokenComponentsAsJsonV3Works()
+ public async Task SerializeBrokenComponentsAsJsonV3Works()
{
// Arrange
var expected = """
@@ -523,7 +524,7 @@ public void SerializeBrokenComponentsAsJsonV3Works()
""";
// Act
- var actual = BrokenComponents.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await BrokenComponents.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -532,7 +533,7 @@ public void SerializeBrokenComponentsAsJsonV3Works()
}
[Fact]
- public void SerializeBrokenComponentsAsYamlV3Works()
+ public async Task SerializeBrokenComponentsAsYamlV3Works()
{
// Arrange
var expected =
@@ -553,7 +554,7 @@ public void SerializeBrokenComponentsAsYamlV3Works()
""";
// Act
- var actual = BrokenComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await BrokenComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -562,7 +563,7 @@ public void SerializeBrokenComponentsAsYamlV3Works()
}
[Fact]
- public void SerializeTopLevelReferencingComponentsAsYamlV3Works()
+ public async Task SerializeTopLevelReferencingComponentsAsYamlV3Works()
{
// Arrange
// Arrange
@@ -579,7 +580,7 @@ public void SerializeTopLevelReferencingComponentsAsYamlV3Works()
""";
// Act
- var actual = TopLevelReferencingComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await TopLevelReferencingComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -588,7 +589,7 @@ public void SerializeTopLevelReferencingComponentsAsYamlV3Works()
}
[Fact]
- public void SerializeTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV3Works()
+ public async Task SerializeTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV3Works()
{
// Arrange
var expected = @"schemas:
@@ -604,7 +605,7 @@ public void SerializeTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV
type: string";
// Act
- var actual = TopLevelSelfReferencingComponentsWithOtherProperties.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await TopLevelSelfReferencingComponentsWithOtherProperties.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -613,7 +614,7 @@ public void SerializeTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV
}
[Fact]
- public void SerializeComponentsWithPathItemsAsJsonWorks()
+ public async Task SerializeComponentsWithPathItemsAsJsonWorks()
{
// Arrange
var expected = @"{
@@ -659,7 +660,7 @@ public void SerializeComponentsWithPathItemsAsJsonWorks()
}
}";
// Act
- var actual = ComponentsWithPathItem.SerializeAsJson(OpenApiSpecVersion.OpenApi3_1);
+ var actual = await ComponentsWithPathItem.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_1);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -668,7 +669,7 @@ public void SerializeComponentsWithPathItemsAsJsonWorks()
}
[Fact]
- public void SerializeComponentsWithPathItemsAsYamlWorks()
+ public async Task SerializeComponentsWithPathItemsAsYamlWorks()
{
// Arrange
var expected = @"pathItems:
@@ -696,7 +697,7 @@ public void SerializeComponentsWithPathItemsAsYamlWorks()
type: integer";
// Act
- var actual = ComponentsWithPathItem.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1);
+ var actual = await ComponentsWithPathItem.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs
index 06c00fec4..337548ccb 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT license.
using System.Collections.Generic;
+using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
@@ -32,13 +33,13 @@ public class OpenApiContactTests
[InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json, "{ }")]
[InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml, "{ }")]
[InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Yaml, "{ }")]
- public void SerializeBasicContactWorks(
+ public async Task SerializeBasicContactWorks(
OpenApiSpecVersion version,
OpenApiFormat format,
string expected)
{
// Arrange & Act
- var actual = BasicContact.Serialize(version, format);
+ var actual = await BasicContact.SerializeAsync(version, format);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -49,7 +50,7 @@ public void SerializeBasicContactWorks(
[Theory]
[InlineData(OpenApiSpecVersion.OpenApi3_0)]
[InlineData(OpenApiSpecVersion.OpenApi2_0)]
- public void SerializeAdvanceContactAsJsonWorks(OpenApiSpecVersion version)
+ public async Task SerializeAdvanceContactAsJsonWorks(OpenApiSpecVersion version)
{
// Arrange
var expected =
@@ -63,7 +64,7 @@ public void SerializeAdvanceContactAsJsonWorks(OpenApiSpecVersion version)
""";
// Act
- var actual = AdvanceContact.SerializeAsJson(version);
+ var actual = await AdvanceContact.SerializeAsJsonAsync(version);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -74,7 +75,7 @@ public void SerializeAdvanceContactAsJsonWorks(OpenApiSpecVersion version)
[Theory]
[InlineData(OpenApiSpecVersion.OpenApi3_0)]
[InlineData(OpenApiSpecVersion.OpenApi2_0)]
- public void SerializeAdvanceContactAsYamlWorks(OpenApiSpecVersion version)
+ public async Task SerializeAdvanceContactAsYamlWorks(OpenApiSpecVersion version)
{
// Arrange
var expected =
@@ -86,7 +87,7 @@ public void SerializeAdvanceContactAsYamlWorks(OpenApiSpecVersion version)
""";
// Act
- var actual = AdvanceContact.SerializeAsYaml(version);
+ var actual = await AdvanceContact.SerializeAsYamlAsync(version);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs
index 5d493fc55..5d9c9175b 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs
@@ -1355,7 +1355,7 @@ public async Task SerializeAdvancedDocumentAsV3JsonWorksAsync(bool produceTerseO
// Act
AdvancedDocument.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -1372,7 +1372,7 @@ public async Task SerializeAdvancedDocumentWithReferenceAsV3JsonWorksAsync(bool
// Act
AdvancedDocumentWithReference.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -1389,7 +1389,7 @@ public async Task SerializeAdvancedDocumentWithServerVariableAsV2JsonWorksAsync(
// Act
AdvancedDocumentWithServerVariable.SerializeAsV2(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -1406,7 +1406,7 @@ public async Task SerializeAdvancedDocumentAsV2JsonWorksAsync(bool produceTerseO
// Act
AdvancedDocument.SerializeAsV2(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -1423,7 +1423,7 @@ public async Task SerializeDuplicateExtensionsAsV3JsonWorksAsync(bool produceTer
// Act
DuplicateExtensions.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -1440,7 +1440,7 @@ public async Task SerializeDuplicateExtensionsAsV2JsonWorksAsync(bool produceTer
// Act
DuplicateExtensions.SerializeAsV2(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -1457,14 +1457,14 @@ public async Task SerializeAdvancedDocumentWithReferenceAsV2JsonWorksAsync(bool
// Act
AdvancedDocumentWithReference.SerializeAsV2(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
}
[Fact]
- public void SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Works()
+ public async Task SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Works()
{
// Arrange
var expected = @"swagger: '2.0'
@@ -1481,7 +1481,7 @@ public void SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Work
type: string";
// Act
- var actual = SimpleDocumentWithTopLevelReferencingComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0);
+ var actual = await SimpleDocumentWithTopLevelReferencingComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -1490,7 +1490,7 @@ public void SerializeSimpleDocumentWithTopLevelReferencingComponentsAsYamlV2Work
}
[Fact]
- public void SerializeSimpleDocumentWithTopLevelSelfReferencingComponentsAsYamlV3Works()
+ public async Task SerializeSimpleDocumentWithTopLevelSelfReferencingComponentsAsYamlV3Works()
{
// Arrange
var expected = @"swagger: '2.0'
@@ -1501,7 +1501,7 @@ public void SerializeSimpleDocumentWithTopLevelSelfReferencingComponentsAsYamlV3
schema1: { }";
// Act
- var actual = SimpleDocumentWithTopLevelSelfReferencingComponents.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0);
+ var actual = await SimpleDocumentWithTopLevelSelfReferencingComponents.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -1510,7 +1510,7 @@ public void SerializeSimpleDocumentWithTopLevelSelfReferencingComponentsAsYamlV3
}
[Fact]
- public void SerializeSimpleDocumentWithTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV3Works()
+ public async Task SerializeSimpleDocumentWithTopLevelSelfReferencingWithOtherPropertiesComponentsAsYamlV3Works()
{
// Arrange
var expected = @"swagger: '2.0'
@@ -1530,7 +1530,7 @@ public void SerializeSimpleDocumentWithTopLevelSelfReferencingWithOtherPropertie
type: string";
// Act
- var actual = SimpleDocumentWithTopLevelSelfReferencingComponentsWithOtherProperties.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0);
+ var actual = await SimpleDocumentWithTopLevelSelfReferencingComponentsWithOtherProperties.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -1539,7 +1539,7 @@ public void SerializeSimpleDocumentWithTopLevelSelfReferencingWithOtherPropertie
}
[Fact]
- public void SerializeDocumentWithReferenceButNoComponents()
+ public async Task SerializeDocumentWithReferenceButNoComponents()
{
// Arrange
var document = new OpenApiDocument()
@@ -1584,14 +1584,14 @@ public void SerializeDocumentWithReferenceButNoComponents()
};
// Act
- var actual = document.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json);
+ var actual = await document.SerializeAsync(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json);
// Assert
Assert.NotEmpty(actual);
}
[Fact]
- public void SerializeRelativePathAsV2JsonWorks()
+ public async Task SerializeRelativePathAsV2JsonWorks()
{
// Arrange
var expected =
@@ -1612,7 +1612,7 @@ public void SerializeRelativePathAsV2JsonWorks()
};
// Act
- var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0);
+ var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -1621,7 +1621,7 @@ public void SerializeRelativePathAsV2JsonWorks()
}
[Fact]
- public void SerializeRelativePathWithHostAsV2JsonWorks()
+ public async Task SerializeRelativePathWithHostAsV2JsonWorks()
{
// Arrange
var expected =
@@ -1643,7 +1643,7 @@ public void SerializeRelativePathWithHostAsV2JsonWorks()
};
// Act
- var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0);
+ var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -1652,7 +1652,7 @@ public void SerializeRelativePathWithHostAsV2JsonWorks()
}
[Fact]
- public void SerializeRelativeRootPathWithHostAsV2JsonWorks()
+ public async Task SerializeRelativeRootPathWithHostAsV2JsonWorks()
{
// Arrange
var expected =
@@ -1673,7 +1673,7 @@ public void SerializeRelativeRootPathWithHostAsV2JsonWorks()
};
// Act
- var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0);
+ var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -1696,8 +1696,17 @@ public async Task TestHashCodesForSimilarOpenApiDocuments()
Test whether reading in two similar documents yield the same hash code,
And reading in similar documents(one has a whitespace) yields the same hash code as the result is terse
*/
- Assert.True(doc1.HashCode != null && doc2.HashCode != null && doc1.HashCode.Equals(doc2.HashCode));
- Assert.Equal(doc1.HashCode, doc3.HashCode);
+ var doc1HashCode = await doc1.GetHashCodeAsync();
+ var doc2HashCode = await doc2.GetHashCodeAsync();
+ var doc3HashCode = await doc3.GetHashCodeAsync();
+ Assert.NotNull(doc1HashCode);
+ Assert.NotNull(doc2HashCode);
+ Assert.NotNull(doc3HashCode);
+ Assert.NotEmpty(doc1HashCode);
+ Assert.NotEmpty(doc2HashCode);
+ Assert.NotEmpty(doc3HashCode);
+ Assert.Equal(doc1HashCode, doc2HashCode);
+ Assert.Equal(doc1HashCode, doc3HashCode);
}
private static async Task ParseInputFileAsync(string filePath)
@@ -1707,7 +1716,7 @@ private static async Task ParseInputFileAsync(string filePath)
}
[Fact]
- public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFormat()
+ public async Task SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFormat()
{
// Arrange
var expected = @"swagger: '2.0'
@@ -1750,7 +1759,7 @@ public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFo
};
// Act
- var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi2_0);
+ var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi2_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -1759,7 +1768,7 @@ public void SerializeV2DocumentWithNonArraySchemaTypeDoesNotWriteOutCollectionFo
}
[Fact]
- public void SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue()
+ public async Task SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue()
{
// Arrange
var expected = @"openapi: 3.0.4
@@ -1839,7 +1848,7 @@ public void SerializeV2DocumentWithStyleAsNullDoesNotWriteOutStyleValue()
};
// Act
- var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -1912,7 +1921,7 @@ public async Task SerializeDocumentWithWebhooksAsV3JsonWorks(bool produceTerseOu
// Act
DocumentWithWebhooks.SerializeAsV31(writer);
- writer.Flush();
+ await writer.FlushAsync();
var actual = outputStringWriter.GetStringBuilder().ToString();
// Assert
@@ -1920,7 +1929,7 @@ public async Task SerializeDocumentWithWebhooksAsV3JsonWorks(bool produceTerseOu
}
[Fact]
- public void SerializeDocumentWithWebhooksAsV3YamlWorks()
+ public async Task SerializeDocumentWithWebhooksAsV3YamlWorks()
{
// Arrange
var expected = @"openapi: '3.1.1'
@@ -1956,7 +1965,7 @@ public void SerializeDocumentWithWebhooksAsV3YamlWorks()
description: Return a 200 status to indicate that the data was received successfully";
// Act
- var actual = DocumentWithWebhooks.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1);
+ var actual = await DocumentWithWebhooks.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -1965,7 +1974,7 @@ public void SerializeDocumentWithWebhooksAsV3YamlWorks()
}
[Fact]
- public void SerializeDocumentWithRootJsonSchemaDialectPropertyWorks()
+ public async Task SerializeDocumentWithRootJsonSchemaDialectPropertyWorks()
{
// Arrange
var doc = new OpenApiDocument
@@ -1986,7 +1995,7 @@ public void SerializeDocumentWithRootJsonSchemaDialectPropertyWorks()
paths: { }";
// Act
- var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1);
+ var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1);
// Assert
actual.MakeLineBreaksEnvironmentNeutral().Should().BeEquivalentTo(expected.MakeLineBreaksEnvironmentNeutral());
@@ -2062,12 +2071,12 @@ public async Task SerializeDocWithDollarIdInDollarRefSucceeds()
type: number
";
var doc = (await OpenApiDocument.LoadAsync("Models/Samples/docWithDollarId.yaml")).Document;
- var actual = doc.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_1);
+ var actual = await doc.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_1);
actual.MakeLineBreaksEnvironmentNeutral().Should().BeEquivalentTo(expected.MakeLineBreaksEnvironmentNeutral());
}
[Fact]
- public void SerializeDocumentTagsWithMultipleExtensionsWorks()
+ public async Task SerializeDocumentTagsWithMultipleExtensionsWorks()
{
var expected = @"{
""openapi"": ""3.0.4"",
@@ -2116,7 +2125,7 @@ public void SerializeDocumentTagsWithMultipleExtensionsWorks()
}
};
- var actual = doc.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await doc.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
actual.MakeLineBreaksEnvironmentNeutral().Should().BeEquivalentTo(expected.MakeLineBreaksEnvironmentNeutral());
}
}
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs
index fe699f7aa..c9ce9d217 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
+using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
@@ -24,10 +25,10 @@ public class OpenApiEncodingTests
[Theory]
[InlineData(OpenApiFormat.Json, "{ }")]
[InlineData(OpenApiFormat.Yaml, "{ }")]
- public void SerializeBasicEncodingAsV3Works(OpenApiFormat format, string expected)
+ public async Task SerializeBasicEncodingAsV3Works(OpenApiFormat format, string expected)
{
// Arrange & Act
- var actual = BasicEncoding.Serialize(OpenApiSpecVersion.OpenApi3_0, format);
+ var actual = await BasicEncoding.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, format);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -36,7 +37,7 @@ public void SerializeBasicEncodingAsV3Works(OpenApiFormat format, string expecte
}
[Fact]
- public void SerializeAdvanceEncodingAsV3JsonWorks()
+ public async Task SerializeAdvanceEncodingAsV3JsonWorks()
{
// Arrange
var expected =
@@ -50,7 +51,7 @@ public void SerializeAdvanceEncodingAsV3JsonWorks()
""";
// Act
- var actual = AdvanceEncoding.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await AdvanceEncoding.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -59,7 +60,7 @@ public void SerializeAdvanceEncodingAsV3JsonWorks()
}
[Fact]
- public void SerializeAdvanceEncodingAsV3YamlWorks()
+ public async Task SerializeAdvanceEncodingAsV3YamlWorks()
{
// Arrange
var expected =
@@ -71,7 +72,7 @@ public void SerializeAdvanceEncodingAsV3YamlWorks()
""";
// Act
- var actual = AdvanceEncoding.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await AdvanceEncoding.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs
index 023f4d78f..c920c986b 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiExampleTests.cs
@@ -108,7 +108,7 @@ public async Task SerializeAdvancedExampleAsV3JsonWorksAsync(bool produceTerseOu
// Act
AdvancedExample.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -125,7 +125,7 @@ public async Task SerializeReferencedExampleAsV3JsonWorksAsync(bool produceTerse
// Act
OpenApiExampleReference.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -142,7 +142,7 @@ public async Task SerializeReferencedExampleAsV3JsonWithoutReferenceWorksAsync(b
// Act
ReferencedExample.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs
index 25bf6315d..59c81865f 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
+using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
@@ -24,10 +25,10 @@ public class OpenApiExternalDocsTests
[Theory]
[InlineData(OpenApiFormat.Json, "{ }")]
[InlineData(OpenApiFormat.Yaml, "{ }")]
- public void SerializeBasicExternalDocsAsV3Works(OpenApiFormat format, string expected)
+ public async Task SerializeBasicExternalDocsAsV3Works(OpenApiFormat format, string expected)
{
// Arrange & Act
- var actual = BasicExDocs.Serialize(OpenApiSpecVersion.OpenApi3_0, format);
+ var actual = await BasicExDocs.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, format);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -36,7 +37,7 @@ public void SerializeBasicExternalDocsAsV3Works(OpenApiFormat format, string exp
}
[Fact]
- public void SerializeAdvanceExDocsAsV3JsonWorks()
+ public async Task SerializeAdvanceExDocsAsV3JsonWorks()
{
// Arrange
var expected =
@@ -48,7 +49,7 @@ public void SerializeAdvanceExDocsAsV3JsonWorks()
""";
// Act
- var actual = AdvanceExDocs.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await AdvanceExDocs.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
@@ -57,7 +58,7 @@ public void SerializeAdvanceExDocsAsV3JsonWorks()
}
[Fact]
- public void SerializeAdvanceExDocsAsV3YamlWorks()
+ public async Task SerializeAdvanceExDocsAsV3YamlWorks()
{
// Arrange
var expected =
@@ -67,7 +68,7 @@ public void SerializeAdvanceExDocsAsV3YamlWorks()
""";
// Act
- var actual = AdvanceExDocs.SerializeAsYaml(OpenApiSpecVersion.OpenApi3_0);
+ var actual = await AdvanceExDocs.SerializeAsYamlAsync(OpenApiSpecVersion.OpenApi3_0);
// Assert
actual = actual.MakeLineBreaksEnvironmentNeutral();
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs
index 72c4fdfaa..e368c587b 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiHeaderTests.cs
@@ -48,7 +48,7 @@ public async Task SerializeAdvancedHeaderAsV3JsonWorksAsync(bool produceTerseOut
// Act
AdvancedHeader.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -65,7 +65,7 @@ public async Task SerializeReferencedHeaderAsV3JsonWorksAsync(bool produceTerseO
// Act
OpenApiHeaderReference.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -82,7 +82,7 @@ public async Task SerializeReferencedHeaderAsV3JsonWithoutReferenceWorksAsync(bo
// Act
ReferencedHeader.SerializeAsV3(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -99,7 +99,7 @@ public async Task SerializeAdvancedHeaderAsV2JsonWorksAsync(bool produceTerseOut
// Act
AdvancedHeader.SerializeAsV2(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -116,7 +116,7 @@ public async Task SerializeReferencedHeaderAsV2JsonWorksAsync(bool produceTerseO
// Act
OpenApiHeaderReference.SerializeAsV2(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
@@ -133,7 +133,7 @@ public async Task SerializeReferencedHeaderAsV2JsonWithoutReferenceWorksAsync(bo
// Act
ReferencedHeader.SerializeAsV2(writer);
- writer.Flush();
+ await writer.FlushAsync();
// Assert
await Verifier.Verify(outputStringWriter).UseParameters(produceTerseOutput);
diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs
index 980ce0565..a3c4633e1 100644
--- a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs
+++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs
@@ -2,6 +2,7 @@
// Licensed under the MIT license.
using System.Collections.Generic;
+using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Extensions;
@@ -62,10 +63,10 @@ public static IEnumerable