diff --git a/README.md b/README.md index f903038cd..ef93e1450 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ var stream = await httpClient.GetStreamAsync("main/examples/v3.0/petstore.yaml") var openApiDocument = new OpenApiStreamReader().Read(stream, out var diagnostic); // Write V2 as JSON -var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json); +var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json); ``` diff --git a/docs/upgrade-guide-2.md b/docs/upgrade-guide-2.md index c1416b8fe..f1fd6c23f 100644 --- a/docs/upgrade-guide-2.md +++ b/docs/upgrade-guide-2.md @@ -487,10 +487,24 @@ The `SerializeAs()` method simplifies serialization scenarios, making it easier ```csharp OpenApiDocument document = new OpenApiDocument(); -string json = document.SerializeAs(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Json); +string json = document.SerializeAs(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Json); ``` +### Use OpenApiConstants string Instead of OpenApiFormat Enum + +OpenApiConstants are now used instead of OpenApiFormat enums. + +**Example:** + +```csharp +// Before (1.6) +var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json); + +// After (2.0) +var outputString = openApiDocument.Serialize(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json); +``` + ### Bug Fixes ## Serialization of References diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs index 8b412d14f..52d25ef27 100644 --- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs +++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs @@ -55,7 +55,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog if (options.Output == null) { #pragma warning disable CA1308 // Normalize strings to uppercase - var extension = options.OpenApiFormat?.GetDisplayName().ToLowerInvariant(); + var extension = options.OpenApiFormat?.ToLowerInvariant(); var inputExtension = !string.IsNullOrEmpty(extension) ? string.Concat(".", extension) : GetInputPathExtension(options.OpenApi, options.Csdl); @@ -73,7 +73,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog } // Default to yaml and OpenApiVersion 3_1 during csdl to OpenApi conversion - var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml); + var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiConstants.Yaml); var openApiVersion = options.Version != null ? TryParseOpenApiSpecVersion(options.Version) : OpenApiSpecVersion.OpenApi3_1; // If ApiManifest is provided, set the referenced OpenAPI document @@ -92,7 +92,7 @@ public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILog } // Load OpenAPI document - var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false); + var document = await GetOpenApiAsync(options, openApiFormat, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false); if (options.FilterOptions != null && document is not null) { @@ -189,7 +189,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger, return document; } - private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken) + private static async Task WriteOpenApiAsync(HidiOptions options, string openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken) { using (logger.BeginScope("Output")) { @@ -202,11 +202,12 @@ private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat o InlineLocalReferences = options.InlineLocal, InlineExternalReferences = options.InlineExternal }; - - IOpenApiWriter writer = openApiFormat switch +#pragma warning disable CA1308 + IOpenApiWriter writer = openApiFormat.ToLowerInvariant() switch +#pragma warning restore CA1308 { - OpenApiFormat.Json => options.TerseOutput ? new(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false), - OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings), + OpenApiConstants.Json => options.TerseOutput ? new(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false), + OpenApiConstants.Yaml => new OpenApiYamlWriter(textWriter, settings), _ => throw new ArgumentException("Unknown format"), }; @@ -560,10 +561,10 @@ SecurityException or /// /// /// - private static OpenApiFormat GetOpenApiFormat(string input, ILogger logger) + private static string GetOpenApiFormat(string input, ILogger logger) { logger.LogTrace("Getting the OpenApi format"); - return !input.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Path.GetExtension(input) == ".json" ? OpenApiFormat.Json : OpenApiFormat.Yaml; + return !input.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Path.GetExtension(input) == ".json" ? OpenApiConstants.Json : OpenApiConstants.Yaml; } private static string GetInputPathExtension(string? openapi = null, string? csdl = null) @@ -590,8 +591,8 @@ private static string GetInputPathExtension(string? openapi = null, string? csdl throw new ArgumentException("Please input a file path or URL"); } - var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml); - var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, null, cancellationToken).ConfigureAwait(false); + var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiConstants.Yaml); + var document = await GetOpenApiAsync(options, openApiFormat, logger, null, cancellationToken).ConfigureAwait(false); if (document is not null) { using (logger.BeginScope("Creating diagram")) @@ -754,10 +755,10 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg } var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) - ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml); + ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiConstants.Yaml); // Load OpenAPI document - var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false); + var document = await GetOpenApiAsync(options, openApiFormat, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); @@ -777,7 +778,7 @@ internal static async Task PluginManifestAsync(HidiOptions options, ILogger logg options.TerseOutput = true; if (document is not null) { - await WriteOpenApiAsync(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false); + await WriteOpenApiAsync(options, OpenApiConstants.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false); // Create OpenAIPluginManifest from ApiDependency and OpenAPI document var manifest = new OpenAIPluginManifest(document.Info.Title ?? "Title", diff --git a/src/Microsoft.OpenApi.Hidi/Options/CommandOptions.cs b/src/Microsoft.OpenApi.Hidi/Options/CommandOptions.cs index 6fee866cb..908435c33 100644 --- a/src/Microsoft.OpenApi.Hidi/Options/CommandOptions.cs +++ b/src/Microsoft.OpenApi.Hidi/Options/CommandOptions.cs @@ -16,7 +16,7 @@ internal class CommandOptions public readonly Option CleanOutputOption = new("--clean-output", "Overwrite an existing file"); public readonly Option VersionOption = new("--version", "OpenAPI specification version"); public readonly Option MetadataVersionOption = new("--metadata-version", "Graph metadata version to use."); - public readonly Option FormatOption = new("--format", "File format"); + public readonly Option FormatOption = new("--format", "File format"); public readonly Option TerseOutputOption = new("--terse-output", "Produce terse json output"); public readonly Option SettingsFileOption = new("--settings-path", "The configuration file with CSDL conversion settings."); public readonly Option LogLevelOption = new("--log-level", () => LogLevel.Information, "The log level to use when logging messages to the main output."); diff --git a/src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs b/src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs index fca97c87f..127a0a14a 100644 --- a/src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs +++ b/src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs @@ -20,7 +20,7 @@ internal class HidiOptions public bool CleanOutput { get; set; } public string? Version { get; set; } public string? MetadataVersion { get; set; } - public OpenApiFormat? OpenApiFormat { get; set; } + public string? OpenApiFormat { get; set; } public bool TerseOutput { get; set; } public IConfiguration? SettingsConfig { get; set; } public LogLevel LogLevel { get; set; } diff --git a/src/Microsoft.OpenApi.Workbench/MainModel.cs b/src/Microsoft.OpenApi.Workbench/MainModel.cs index d4e469e8f..d065b36e7 100644 --- a/src/Microsoft.OpenApi.Workbench/MainModel.cs +++ b/src/Microsoft.OpenApi.Workbench/MainModel.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. using System; @@ -43,7 +43,7 @@ public class MainModel : INotifyPropertyChanged /// /// Default format. /// - private OpenApiFormat _format = OpenApiFormat.Yaml; + private string _format = OpenApiConstants.Yaml; /// /// Default version. @@ -121,7 +121,7 @@ public string RenderTime } } - public OpenApiFormat Format + public string Format { get => _format; set @@ -166,14 +166,14 @@ public OpenApiSpecVersion Version public bool IsYaml { - get => Format == OpenApiFormat.Yaml; - set => Format = value ? OpenApiFormat.Yaml : Format; + get => Format == OpenApiConstants.Yaml; + set => Format = value ? OpenApiConstants.Yaml : Format; } public bool IsJson { - get => Format == OpenApiFormat.Json; - set => Format = value ? OpenApiFormat.Json : Format; + get => Format == OpenApiConstants.Json; + set => Format = value ? OpenApiConstants.Json : Format; } public bool IsV2_0 @@ -243,7 +243,7 @@ internal async Task ParseDocumentAsync() : new("file://" + Path.GetDirectoryName(_inputFile) + "/"); } - var readResult = await OpenApiDocument.LoadAsync(stream, Format.GetDisplayName().ToLowerInvariant(), settings); + var readResult = await OpenApiDocument.LoadAsync(stream, Format.ToLowerInvariant(), settings); var document = readResult.Document; var context = readResult.Diagnostic; diff --git a/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs b/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs index d028cd5e4..dcee59faf 100755 --- a/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs +++ b/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.OpenApi.Exceptions; using Microsoft.OpenApi.Interfaces; +using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Properties; using Microsoft.OpenApi.Writers; @@ -28,7 +29,7 @@ public static class OpenApiSerializableExtensions public static Task SerializeAsJsonAsync(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default) where T : IOpenApiSerializable { - return element.SerializeAsync(stream, specVersion, OpenApiFormat.Json, cancellationToken); + return element.SerializeAsync(stream, specVersion, OpenApiConstants.Json, cancellationToken); } /// @@ -42,7 +43,7 @@ public static Task SerializeAsJsonAsync(this T element, Stream stream, OpenAp public static Task SerializeAsYamlAsync(this T element, Stream stream, OpenApiSpecVersion specVersion, CancellationToken cancellationToken = default) where T : IOpenApiSerializable { - return element.SerializeAsync(stream, specVersion, OpenApiFormat.Yaml, cancellationToken); + return element.SerializeAsync(stream, specVersion, OpenApiConstants.Yaml, cancellationToken); } /// @@ -59,7 +60,7 @@ public static Task SerializeAsync( this T element, Stream stream, OpenApiSpecVersion specVersion, - OpenApiFormat format, + string format, CancellationToken cancellationToken = default) where T : IOpenApiSerializable { @@ -81,7 +82,7 @@ public static Task SerializeAsync( this T element, Stream stream, OpenApiSpecVersion specVersion, - OpenApiFormat format, + string format, OpenApiWriterSettings? settings = null, CancellationToken cancellationToken = default) where T : IOpenApiSerializable @@ -90,10 +91,10 @@ public static Task SerializeAsync( var streamWriter = new FormattingStreamWriter(stream, CultureInfo.InvariantCulture); - IOpenApiWriter writer = format switch + IOpenApiWriter writer = format.ToLowerInvariant() switch { - OpenApiFormat.Json => new OpenApiJsonWriter(streamWriter, settings, false), - OpenApiFormat.Yaml => new OpenApiYamlWriter(streamWriter, settings), + OpenApiConstants.Json => new OpenApiJsonWriter(streamWriter, settings, false), + OpenApiConstants.Yaml => new OpenApiYamlWriter(streamWriter, settings), _ => throw new OpenApiException(string.Format(SRResource.OpenApiFormatNotSupported, format)), }; return element.SerializeAsync(writer, specVersion, cancellationToken); @@ -147,7 +148,7 @@ public static Task SerializeAsJsonAsync( CancellationToken cancellationToken = default) where T : IOpenApiSerializable { - return element.SerializeAsync(specVersion, OpenApiFormat.Json, cancellationToken); + return element.SerializeAsync(specVersion, OpenApiConstants.Json, cancellationToken); } /// @@ -163,7 +164,7 @@ public static Task SerializeAsYamlAsync( CancellationToken cancellationToken = default) where T : IOpenApiSerializable { - return element.SerializeAsync(specVersion, OpenApiFormat.Yaml, cancellationToken); + return element.SerializeAsync(specVersion, OpenApiConstants.Yaml, cancellationToken); } /// @@ -177,7 +178,7 @@ public static Task SerializeAsYamlAsync( public static async Task SerializeAsync( this T element, OpenApiSpecVersion specVersion, - OpenApiFormat format, + string format, CancellationToken cancellationToken = default) where T : IOpenApiSerializable { diff --git a/src/Microsoft.OpenApi/OpenApiFormat.cs b/src/Microsoft.OpenApi/OpenApiFormat.cs deleted file mode 100644 index 8005d7d62..000000000 --- a/src/Microsoft.OpenApi/OpenApiFormat.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -namespace Microsoft.OpenApi -{ - /// - /// Represents the Open Api document format. - /// - public enum OpenApiFormat - { - /// - /// JSON format. - /// - Json, - - /// - /// Yaml format. - /// - Yaml - } -} diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index 7e5b4de3c..97c27fe37 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -261,7 +261,7 @@ public async Task TransformCommandConvertsOpenApiWithDefaultOutputNameAndSwitchF OpenApi = Path.Combine("UtilityFiles", "SampleOpenApi.yml"), CleanOutput = true, Version = "3.0", - OpenApiFormat = OpenApiFormat.Yaml, + OpenApiFormat = OpenApiConstants.Yaml, TerseOutput = false, InlineLocal = false, InlineExternal = false, @@ -296,7 +296,7 @@ public async Task TransformToPowerShellCompliantOpenApiAsync() OpenApi = Path.Combine("UtilityFiles", "SampleOpenApi.yml"), CleanOutput = true, Version = "3.0", - OpenApiFormat = OpenApiFormat.Yaml, + OpenApiFormat = OpenApiConstants.Yaml, TerseOutput = false, InlineLocal = false, InlineExternal = false, diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs index 65f34c65b..114956a11 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiContactTests.cs @@ -28,13 +28,13 @@ public class OpenApiContactTests }; [Theory] - [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Json, "{ }")] - [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json, "{ }")] - [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml, "{ }")] - [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Yaml, "{ }")] + [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Json, "{ }")] + [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json, "{ }")] + [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Yaml, "{ }")] + [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Yaml, "{ }")] public async Task SerializeBasicContactWorks( OpenApiSpecVersion version, - OpenApiFormat format, + string format, string expected) { // Arrange & Act diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs index 2774680a7..48310df15 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs @@ -1557,7 +1557,7 @@ public async Task SerializeDocumentWithReferenceButNoComponents() document.Paths["/"].Operations[HttpMethod.Get].Responses["200"].Content["application/json"].Schema = new OpenApiSchemaReference("test", document); // Act - var actual = await document.SerializeAsync(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json); + var actual = await document.SerializeAsync(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json); // Assert Assert.NotEmpty(actual); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs index fd0b21c9d..ee5b8bfd0 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiEncodingTests.cs @@ -22,9 +22,9 @@ public class OpenApiEncodingTests }; [Theory] - [InlineData(OpenApiFormat.Json, "{ }")] - [InlineData(OpenApiFormat.Yaml, "{ }")] - public async Task SerializeBasicEncodingAsV3Works(OpenApiFormat format, string expected) + [InlineData(OpenApiConstants.Json, "{ }")] + [InlineData(OpenApiConstants.Yaml, "{ }")] + public async Task SerializeBasicEncodingAsV3Works(string format, string expected) { // Arrange & Act var actual = await BasicEncoding.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, format); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs index a2bee2e58..8dc551396 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiExternalDocsTests.cs @@ -22,9 +22,9 @@ public class OpenApiExternalDocsTests #region OpenAPI V3 [Theory] - [InlineData(OpenApiFormat.Json, "{ }")] - [InlineData(OpenApiFormat.Yaml, "{ }")] - public async Task SerializeBasicExternalDocsAsV3Works(OpenApiFormat format, string expected) + [InlineData(OpenApiConstants.Json, "{ }")] + [InlineData(OpenApiConstants.Yaml, "{ }")] + public async Task SerializeBasicExternalDocsAsV3Works(string format, string expected) { // Arrange & Act var actual = await BasicExDocs.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, format); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs index 08300a4ff..c78c1d74f 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiInfoTests.cs @@ -205,7 +205,7 @@ public async Task InfoVersionShouldAcceptDateStyledAsVersions() """; // Act - var actual = await info.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml); + var actual = await info.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Yaml); // Assert actual = actual.MakeLineBreaksEnvironmentNeutral(); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs index 3f3c93889..6eff288ad 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiMediaTypeTests.cs @@ -132,9 +132,9 @@ public OpenApiMediaTypeTests(ITestOutputHelper output) } [Theory] - [InlineData(OpenApiFormat.Json, "{ }")] - [InlineData(OpenApiFormat.Yaml, "{ }")] - public async Task SerializeBasicMediaTypeAsV3Works(OpenApiFormat format, string expected) + [InlineData(OpenApiConstants.Json, "{ }")] + [InlineData(OpenApiConstants.Yaml, "{ }")] + public async Task SerializeBasicMediaTypeAsV3Works(string format, string expected) { // Arrange & Act var actual = await BasicMediaType.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, format); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs index 51decab10..4c579fb9e 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiResponseTests.cs @@ -175,16 +175,16 @@ public class OpenApiResponseTests }; [Theory] - [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Json)] - [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json)] - [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml)] - [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Yaml)] + [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Json)] + [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json)] + [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Yaml)] + [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Yaml)] public async Task SerializeBasicResponseWorks( OpenApiSpecVersion version, - OpenApiFormat format) + string format) { // Arrange - var expected = format == OpenApiFormat.Json ? @"{ + var expected = format == OpenApiConstants.Json ? @"{ ""description"": null }" : @"description: "; diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs index 255bfe908..2eb688edd 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiServerVariableTests.cs @@ -25,9 +25,9 @@ public class OpenApiServerVariableTests }; [Theory] - [InlineData(OpenApiFormat.Json, "{ }")] - [InlineData(OpenApiFormat.Yaml, "{ }")] - public async Task SerializeBasicServerVariableAsV3Works(OpenApiFormat format, string expected) + [InlineData(OpenApiConstants.Json, "{ }")] + [InlineData(OpenApiConstants.Yaml, "{ }")] + public async Task SerializeBasicServerVariableAsV3Works(string format, string expected) { // Arrange & Act var actual = await BasicServerVariable.SerializeAsync(OpenApiSpecVersion.OpenApi3_0, format); diff --git a/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs b/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs index 98ec758c8..173bf6620 100644 --- a/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs +++ b/test/Microsoft.OpenApi.Tests/Models/OpenApiXmlTests.cs @@ -30,13 +30,13 @@ public class OpenApiXmlTests public static OpenApiXml BasicXml = new(); [Theory] - [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Json)] - [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Json)] - [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiFormat.Yaml)] - [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiFormat.Yaml)] + [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Json)] + [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Json)] + [InlineData(OpenApiSpecVersion.OpenApi3_0, OpenApiConstants.Yaml)] + [InlineData(OpenApiSpecVersion.OpenApi2_0, OpenApiConstants.Yaml)] public async Task SerializeBasicXmlWorks( OpenApiSpecVersion version, - OpenApiFormat format) + string format) { // Act var actual = await BasicXml.SerializeAsync(version, format); diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 2ec1fb15b..53262c892 100644 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -172,13 +172,13 @@ namespace Microsoft.OpenApi.Extensions where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } public static System.Threading.Tasks.Task SerializeAsYamlAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static System.Threading.Tasks.Task SerializeAsync(this T element, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, System.Threading.CancellationToken cancellationToken = default) + public static System.Threading.Tasks.Task SerializeAsync(this T element, Microsoft.OpenApi.OpenApiSpecVersion specVersion, string format, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } public static System.Threading.Tasks.Task SerializeAsync(this T element, Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static System.Threading.Tasks.Task SerializeAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, System.Threading.CancellationToken cancellationToken = default) + public static System.Threading.Tasks.Task SerializeAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, string format, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } - public static System.Threading.Tasks.Task SerializeAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, Microsoft.OpenApi.OpenApiFormat format, Microsoft.OpenApi.Writers.OpenApiWriterSettings? settings = null, System.Threading.CancellationToken cancellationToken = default) + public static System.Threading.Tasks.Task SerializeAsync(this T element, System.IO.Stream stream, Microsoft.OpenApi.OpenApiSpecVersion specVersion, string format, Microsoft.OpenApi.Writers.OpenApiWriterSettings? settings = null, System.Threading.CancellationToken cancellationToken = default) where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable { } } public static class OpenApiServerExtensions @@ -259,11 +259,6 @@ namespace Microsoft.OpenApi public string[] Tokens { get; } public override string ToString() { } } - public enum OpenApiFormat - { - Json = 0, - Yaml = 1, - } public enum OpenApiSpecVersion { OpenApi2_0 = 0,