diff --git a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs index 5939cde4..8ed5853c 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs @@ -317,6 +317,18 @@ public static OpenApiSchema CreateEnumTypeSchema(this ODataContext context, IEdm // whose value is the value of the unqualified annotation Core.Description of the enumeration type. Description = context.Model.GetDescriptionAnnotation(enumType) }; + + // If the enum is flagged, add the extension info to the description + if (context.Settings.AddEnumFlagsExtension && enumType.IsFlags) + { + var enumFlagsExtension = new OpenApiEnumFlagsExtension + { + IsFlags = true, + Style = "simple" + }; + schema.Extensions.Add(enumFlagsExtension.Name, enumFlagsExtension); + } + var extension = (context.Settings.OpenApiSpecVersion == OpenApiSpecVersion.OpenApi2_0 || context.Settings.OpenApiSpecVersion == OpenApiSpecVersion.OpenApi3_0 ) && context.Settings.AddEnumDescriptionExtension ? diff --git a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj index cde6b9c6..f3eb19de 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj +++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj @@ -15,7 +15,7 @@ netstandard2.0 Microsoft.OpenApi.OData true - 1.5.0-preview2 + 1.5.0-preview3 This package contains the codes you need to convert OData CSDL to Open API Document of Model. © Microsoft Corporation. All rights reserved. Microsoft OpenApi OData EDM @@ -24,6 +24,7 @@ - Resolves operation ids for $count and overloaded functions paths #382, #383 - Updates README #13, #253, #40 - Fixes casing in default propertyName for `innerError` in the `ErrorMainSchema` +- Adds support for `x-ms-enum-flags` extension for flagged enums Microsoft.OpenApi.OData.Reader ..\..\tool\Microsoft.OpenApi.OData.snk diff --git a/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs b/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs index 59d44012..7f711452 100644 --- a/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs +++ b/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs @@ -261,6 +261,11 @@ public string PathPrefix /// public bool AddEnumDescriptionExtension { get; set; } = false; + /// + /// Gets/sets a value indicating whether or not to add a "x-ms-enum-flags" extension to the enum type schema. + /// + public bool AddEnumFlagsExtension { get; set; } = true; + /// /// Gets/sets a value indicating whether the error responses should be described as a default response or as 4XX and 5XX error responses. /// @@ -377,6 +382,7 @@ internal OpenApiConvertSettings Clone() RequireDerivedTypesConstraintForODataTypeCastSegments = this.RequireDerivedTypesConstraintForODataTypeCastSegments, EnableDeprecationInformation = this.EnableDeprecationInformation, AddEnumDescriptionExtension = this.AddEnumDescriptionExtension, + AddEnumFlagsExtension = this.AddEnumFlagsExtension, ErrorResponsesAsDefault = this.ErrorResponsesAsDefault, InnerErrorComplexTypeName = this.InnerErrorComplexTypeName, RequireRestrictionAnnotationsToGenerateComplexPropertyPaths = this.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths, diff --git a/src/Microsoft.OpenApi.OData.Reader/OpenApiExtensions/OpenApiEnumFlagsExtension.cs b/src/Microsoft.OpenApi.OData.Reader/OpenApiExtensions/OpenApiEnumFlagsExtension.cs new file mode 100644 index 00000000..cc8dd86e --- /dev/null +++ b/src/Microsoft.OpenApi.OData.Reader/OpenApiExtensions/OpenApiEnumFlagsExtension.cs @@ -0,0 +1,41 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------ + +using System; +using Microsoft.OpenApi.Interfaces; +using Microsoft.OpenApi.OData.Common; +using Microsoft.OpenApi.Writers; + +namespace Microsoft.OpenApi.OData.OpenApiExtensions; + +/// +/// Extension element for OpenAPI to add deprecation information. x-ms-enum-flags +/// +public class OpenApiEnumFlagsExtension : IOpenApiExtension +{ + /// + /// Name of the extension as used in the description. + /// + public string Name => "x-ms-enum-flags"; + /// + /// Whether the enum is a flagged enum. + /// + public bool IsFlags { get; set; } + /// + /// The serialization style of the flagged enum. + /// + public string Style { get; set; } + /// + public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) + { + if(writer == null) + throw new ArgumentNullException(nameof(writer)); + + writer.WriteStartObject(); + writer.WriteProperty(nameof(IsFlags).ToFirstCharacterLowerCase(), IsFlags); + writer.WriteProperty(nameof(Style).ToFirstCharacterLowerCase(),Style); + writer.WriteEndObject(); + } +} \ No newline at end of file diff --git a/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt b/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt index a40f45f6..b4684880 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt +++ b/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt @@ -17,6 +17,8 @@ Microsoft.OpenApi.OData.Edm.ODataSegment.GetPathItemName(Microsoft.OpenApi.OData Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.ODataTypeCastSegment(Microsoft.OData.Edm.IEdmStructuredType structuredType, Microsoft.OData.Edm.IEdmModel model) -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.AddAlternateKeyPaths.get -> bool Microsoft.OpenApi.OData.OpenApiConvertSettings.AddAlternateKeyPaths.set -> void +Microsoft.OpenApi.OData.OpenApiConvertSettings.AddEnumFlagsExtension.get -> bool +Microsoft.OpenApi.OData.OpenApiConvertSettings.AddEnumFlagsExtension.set -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.AppendBoundOperationsOnDerivedTypeCastSegments.get -> bool Microsoft.OpenApi.OData.OpenApiConvertSettings.AppendBoundOperationsOnDerivedTypeCastSegments.set -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomHttpMethodLinkRelMapping.get -> System.Collections.Generic.Dictionary @@ -48,6 +50,14 @@ Microsoft.OpenApi.OData.OpenApiConvertSettings.ShowExternalDocs.get -> bool Microsoft.OpenApi.OData.OpenApiConvertSettings.ShowExternalDocs.set -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.UseSuccessStatusCodeRange.get -> bool Microsoft.OpenApi.OData.OpenApiConvertSettings.UseSuccessStatusCodeRange.set -> void +Microsoft.OpenApi.OData.OpenApiExtensions.OpenApiEnumFlagsExtension +Microsoft.OpenApi.OData.OpenApiExtensions.OpenApiEnumFlagsExtension.IsFlags.get -> bool +Microsoft.OpenApi.OData.OpenApiExtensions.OpenApiEnumFlagsExtension.IsFlags.set -> void +Microsoft.OpenApi.OData.OpenApiExtensions.OpenApiEnumFlagsExtension.Name.get -> string +Microsoft.OpenApi.OData.OpenApiExtensions.OpenApiEnumFlagsExtension.OpenApiEnumFlagsExtension() -> void +Microsoft.OpenApi.OData.OpenApiExtensions.OpenApiEnumFlagsExtension.Style.get -> string +Microsoft.OpenApi.OData.OpenApiExtensions.OpenApiEnumFlagsExtension.Style.set -> void +Microsoft.OpenApi.OData.OpenApiExtensions.OpenApiEnumFlagsExtension.Write(Microsoft.OpenApi.Writers.IOpenApiWriter writer, Microsoft.OpenApi.OpenApiSpecVersion specVersion) -> void Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Action = 6 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Create = 2 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/EdmModelOpenApiExtensionsTest.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/EdmModelOpenApiExtensionsTest.cs index 2aa15468..b5a11fef 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/EdmModelOpenApiExtensionsTest.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/EdmModelOpenApiExtensionsTest.cs @@ -243,6 +243,7 @@ public void TripServiceMetadataToOpenApiYamlWorks(OpenApiSpecVersion specVersion // Arrange IEdmModel model = EdmModelHelper.TripServiceModel; +#pragma warning disable CS0618 // Type or member is obsolete OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableKeyAsSegment = true, @@ -255,6 +256,7 @@ public void TripServiceMetadataToOpenApiYamlWorks(OpenApiSpecVersion specVersion AppendBoundOperationsOnDerivedTypeCastSegments = true, IncludeAssemblyInfo = false }; +#pragma warning restore CS0618 // Type or member is obsolete // Act string yaml = WriteEdmModelAsOpenApi(model, OpenApiFormat.Yaml, settings); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiParameterGeneratorTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiParameterGeneratorTests.cs index 6c923550..1f588b07 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiParameterGeneratorTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiParameterGeneratorTests.cs @@ -299,7 +299,7 @@ public void CreateKeyParametersForAlternateKeyWithSinglePropertyWorks() // Assert Assert.NotNull(parameters); - Assert.Equal(1, parameters.Count); + Assert.Single(parameters); string json = altParameter.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); Assert.Equal(@"{ ""name"": ""AltId"", diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs index df8a7096..ee5b2241 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs @@ -523,7 +523,7 @@ public void CreateComplexTypeWithBaseSchemaReturnCorrectSchema() Assert.Null(declaredSchema.OneOf); Assert.NotNull(declaredSchema.Properties); - Assert.Equal(1, declaredSchema.Properties.Count); + Assert.Single(declaredSchema.Properties); var property = Assert.Single(declaredSchema.Properties); Assert.Equal("Price", property.Key); Assert.Equal("decimal", property.Value.OneOf.FirstOrDefault(x => !string.IsNullOrEmpty(x.Format))?.Format); @@ -674,7 +674,7 @@ public void CreateEntityTypeWithBaseSchemaReturnCorrectSchema() Assert.Null(declaredSchema.OneOf); Assert.NotNull(declaredSchema.Properties); - Assert.Equal(1, declaredSchema.Properties.Count); + Assert.Single(declaredSchema.Properties); var property = Assert.Single(declaredSchema.Properties); Assert.Equal("Name", property.Key); Assert.Equal("string", property.Value.Type); @@ -750,7 +750,7 @@ public void CreateEntityTypeWithCrossReferenceBaseSchemaReturnCorrectSchema() Assert.Null(declaredSchema.OneOf); Assert.NotNull(declaredSchema.Properties); - Assert.Equal(1, declaredSchema.Properties.Count); + Assert.Single(declaredSchema.Properties); var property = Assert.Single(declaredSchema.Properties); Assert.Equal("Extra", property.Key); Assert.Equal("integer", property.Value.Type); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/OpenApiExtensions/OpenApiEnumFlagsExtensionTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/OpenApiExtensions/OpenApiEnumFlagsExtensionTests.cs new file mode 100644 index 00000000..e6266dfb --- /dev/null +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/OpenApiExtensions/OpenApiEnumFlagsExtensionTests.cs @@ -0,0 +1,89 @@ +// ------------------------------------------------------------ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. +// ------------------------------------------------------------ + +using System.IO; +using Microsoft.OpenApi.Writers; +using Xunit; + +namespace Microsoft.OpenApi.OData.OpenApiExtensions.Tests; + +public class OpenApiEnumFlagsExtensionTests +{ + [Fact] + public void ExtensionNameMatchesExpected() + { + // Arrange + OpenApiEnumFlagsExtension extension = new(); + + // Act + string name = extension.Name; + string expectedName = "x-ms-enum-flags"; + + // Assert + Assert.Equal(expectedName, name); + } + + [Fact] + public void WritesDefaultValues() + { + // Arrange + OpenApiEnumFlagsExtension extension = new(); + using TextWriter sWriter = new StringWriter(); + OpenApiJsonWriter writer = new(sWriter); + + // Act + extension.Write(writer, OpenApiSpecVersion.OpenApi3_0); + string result = sWriter.ToString(); + + // Assert + Assert.False(extension.IsFlags); + Assert.Null(extension.Style); + Assert.Contains("\"isFlags\": false", result); + Assert.DoesNotContain("\"style\"", result); + } + + [Fact] + public void WritesAllDefaultValues() + { + // Arrange + OpenApiEnumFlagsExtension extension = new() { + IsFlags = true + }; + using TextWriter sWriter = new StringWriter(); + OpenApiJsonWriter writer = new(sWriter); + + // Act + extension.Write(writer, OpenApiSpecVersion.OpenApi3_0); + string result = sWriter.ToString(); + + // Assert + Assert.True(extension.IsFlags); + Assert.Null(extension.Style); + Assert.Contains("\"isFlags\": true", result); + Assert.DoesNotContain("\"style\":", result); + } + + [Fact] + public void WritesAllValues() + { + // Arrange + OpenApiEnumFlagsExtension extension = new() { + IsFlags = true, + Style = "simple" + }; + using TextWriter sWriter = new StringWriter(); + OpenApiJsonWriter writer = new(sWriter); + + // Act + extension.Write(writer, OpenApiSpecVersion.OpenApi3_0); + string result = sWriter.ToString(); + + // Assert + Assert.True(extension.IsFlags); + Assert.NotNull(extension.Style); + Assert.Contains("\"isFlags\": true", result); + Assert.Contains("\"style\": \"simple\"", result); + } +} \ No newline at end of file diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/ComplexPropertyPatchOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/ComplexPropertyPatchOperationHandlerTests.cs index 5e367046..4d29528a 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/ComplexPropertyPatchOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/ComplexPropertyPatchOperationHandlerTests.cs @@ -41,7 +41,7 @@ public void CreateComplexPropertyDeleteOperationReturnsCorrectOperationForSingle Assert.Equal("Update the BillingAddress value.", patch.Description); Assert.NotNull(patch.Parameters); - Assert.Equal(1, patch.Parameters.Count); //id + Assert.Single(patch.Parameters); //id Assert.NotNull(patch.Responses); Assert.Equal(2, patch.Responses.Count); @@ -85,7 +85,7 @@ public void CreateComplexPropertyPatchOperationReturnsCorrectOperationForCollect Assert.Equal("Update the BillingAddress value.", patch.Description); Assert.NotNull(patch.Parameters); - Assert.Equal(1, patch.Parameters.Count); //id + Assert.Single(patch.Parameters); //id Assert.NotNull(patch.Responses); Assert.Equal(2, patch.Responses.Count); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/ComplexPropertyPutOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/ComplexPropertyPutOperationHandlerTests.cs index 8d46f3d9..bf02b4f9 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/ComplexPropertyPutOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/ComplexPropertyPutOperationHandlerTests.cs @@ -44,7 +44,7 @@ public void CreateComplexPropertyPutOperationReturnsCorrectOperationForSingle(bo Assert.Equal("Update the BillingAddress value.", put.Description); Assert.NotNull(put.Parameters); - Assert.Equal(1, put.Parameters.Count); //id + Assert.Single(put.Parameters); //id Assert.NotNull(put.Responses); Assert.Equal(2, put.Responses.Count); @@ -95,7 +95,7 @@ public void CreateComplexPropertyPutOperationReturnsCorrectOperationForCollectio Assert.Equal("Update the BillingAddress value.", put.Description); Assert.NotNull(put.Parameters); - Assert.Equal(1, put.Parameters.Count); //id + Assert.Single(put.Parameters); //id Assert.NotNull(put.Responses); Assert.Equal(2, put.Responses.Count); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmActionOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmActionOperationHandlerTests.cs index 5f12ae05..03d87da1 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmActionOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmActionOperationHandlerTests.cs @@ -43,7 +43,7 @@ public void CreateOperationForEdmActionReturnsCorrectOperation() Assert.Equal("People.Actions", tag.Name); Assert.NotNull(operation.Parameters); - Assert.Equal(1, operation.Parameters.Count); + Assert.Single(operation.Parameters); Assert.Equal(new string[] { "UserName" }, operation.Parameters.Select(p => p.Name)); Assert.NotNull(operation.RequestBody); @@ -82,7 +82,7 @@ public void CreateOperationForEdmActionReturnsCorrectOperationHierarchicalClass( Assert.Equal($"{entitySetName}.Actions", tag.Name); Assert.NotNull(operation.Parameters); - Assert.Equal(1, operation.Parameters.Count); + Assert.Single(operation.Parameters); Assert.Equal(new string[] { "id" }, operation.Parameters.Select(p => p.Name)); Assert.NotNull(operation.RequestBody); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionOperationHandlerTests.cs index 29b9a878..a3d8baf7 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionOperationHandlerTests.cs @@ -102,7 +102,7 @@ public void CreateOperationForEdmFunctionReturnsCorrectOperation(bool useHTTPSta Assert.Equal("People.Functions", tag.Name); Assert.NotNull(operation.Parameters); - Assert.Equal(1, operation.Parameters.Count); + Assert.Single(operation.Parameters); Assert.Equal(new string[] { "UserName" }, operation.Parameters.Select(p => p.Name)); Assert.Null(operation.RequestBody); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityPatchOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityPatchOperationHandlerTests.cs index cdfd9ab6..fad725a5 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityPatchOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityPatchOperationHandlerTests.cs @@ -46,7 +46,7 @@ public void CreateEntityPatchOperationReturnsCorrectOperation(bool enableOperati Assert.Equal("Customers.Customer", tag.Name); Assert.NotNull(patch.Parameters); - Assert.Equal(1, patch.Parameters.Count); + Assert.Single(patch.Parameters); Assert.NotNull(patch.RequestBody); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityPutOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityPutOperationHandlerTests.cs index 5208e579..511d1681 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityPutOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntityPutOperationHandlerTests.cs @@ -46,7 +46,7 @@ public void CreateEntityPutOperationReturnsCorrectOperation(bool enableOperation Assert.Equal("Customers.Customer", tag.Name); Assert.NotNull(putOperation.Parameters); - Assert.Equal(1, putOperation.Parameters.Count); + Assert.Single(putOperation.Parameters); Assert.NotNull(putOperation.RequestBody); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntitySetPostOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntitySetPostOperationHandlerTests.cs index c3377ec7..82f24d26 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntitySetPostOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EntitySetPostOperationHandlerTests.cs @@ -105,11 +105,11 @@ private void VerifyEntitySetPostOperation(string annotation, bool enableOperatio { // RequestBody Assert.NotNull(post.RequestBody); - Assert.Equal(1, post.RequestBody.Content.Keys.Count); + Assert.Single(post.RequestBody.Content.Keys); Assert.True(post.RequestBody.Content.ContainsKey(Constants.ApplicationJsonMediaType)); // Response - Assert.Equal(1, post.Responses[Constants.StatusCode201].Content.Keys.Count); + Assert.Single(post.Responses[Constants.StatusCode201].Content.Keys); Assert.True(post.Responses[Constants.StatusCode201].Content.ContainsKey(Constants.ApplicationJsonMediaType)); } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/MediaEntityGetOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/MediaEntityGetOperationHandlerTests.cs index 85f7fc52..a3bc9479 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/MediaEntityGetOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/MediaEntityGetOperationHandlerTests.cs @@ -101,13 +101,13 @@ private void VerifyMediaEntityGetOperation(string annotation, bool enableOperati Assert.True(getOperation.Responses[statusCode].Content.ContainsKey("image/jpeg")); Assert.Equal("The logo image.", getOperation.Description); - Assert.Equal(1, getOperation2.Responses[statusCode].Content.Keys.Count); + Assert.Single(getOperation2.Responses[statusCode].Content.Keys); Assert.True(getOperation2.Responses[statusCode].Content.ContainsKey(Constants.ApplicationOctetStreamMediaType)); } else { - Assert.Equal(1, getOperation.Responses[statusCode].Content.Keys.Count); - Assert.Equal(1, getOperation2.Responses[statusCode].Content.Keys.Count); + Assert.Single(getOperation.Responses[statusCode].Content.Keys); + Assert.Single(getOperation2.Responses[statusCode].Content.Keys); Assert.True(getOperation.Responses[statusCode].Content.ContainsKey(Constants.ApplicationOctetStreamMediaType)); Assert.True(getOperation2.Responses[statusCode].Content.ContainsKey(Constants.ApplicationOctetStreamMediaType)); } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/MediaEntityPutOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/MediaEntityPutOperationHandlerTests.cs index 7564e4b0..cfd73b5c 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/MediaEntityPutOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/MediaEntityPutOperationHandlerTests.cs @@ -122,13 +122,13 @@ private void VerifyMediaEntityPutOperation(string annotation, bool enableOperati Assert.True(putOperation.RequestBody.Content.ContainsKey("image/jpeg")); Assert.Equal("The logo image.", putOperation.Description); - Assert.Equal(1, putOperation2.RequestBody.Content.Keys.Count); + Assert.Single(putOperation2.RequestBody.Content.Keys); Assert.True(putOperation2.RequestBody.Content.ContainsKey(Constants.ApplicationOctetStreamMediaType)); } else { - Assert.Equal(1, putOperation.RequestBody.Content.Keys.Count); - Assert.Equal(1, putOperation2.RequestBody.Content.Keys.Count); + Assert.Single(putOperation.RequestBody.Content.Keys); + Assert.Single(putOperation2.RequestBody.Content.Keys); Assert.True(putOperation.RequestBody.Content.ContainsKey(Constants.ApplicationOctetStreamMediaType)); Assert.True(putOperation2.RequestBody.Content.ContainsKey(Constants.ApplicationOctetStreamMediaType)); } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/NavigationPropertyPatchOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/NavigationPropertyPatchOperationHandlerTests.cs index ed705ede..3adb2e6f 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/NavigationPropertyPatchOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/NavigationPropertyPatchOperationHandlerTests.cs @@ -51,7 +51,7 @@ public void CreateNavigationPatchOperationReturnsCorrectOperation(bool enableOpe Assert.Equal("People.Person", tag.Name); Assert.NotNull(operation.Parameters); - Assert.Equal(1, operation.Parameters.Count); + Assert.Single(operation.Parameters); Assert.NotNull(operation.RequestBody); Assert.Equal("New navigation property values", operation.RequestBody.Description); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/NavigationPropertyPutOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/NavigationPropertyPutOperationHandlerTests.cs index ddd328f5..499863bc 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/NavigationPropertyPutOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/NavigationPropertyPutOperationHandlerTests.cs @@ -51,7 +51,7 @@ public void CreateNavigationPutOperationReturnsCorrectOperation(bool enableOpera Assert.Equal("People.Person", tag.Name); Assert.NotNull(operation.Parameters); - Assert.Equal(1, operation.Parameters.Count); + Assert.Single(operation.Parameters); Assert.NotNull(operation.RequestBody); Assert.Equal("New navigation property values", operation.RequestBody.Description); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/RefPutOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/RefPutOperationHandlerTests.cs index a64a3d1f..9a431561 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/RefPutOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/RefPutOperationHandlerTests.cs @@ -52,7 +52,7 @@ public void CreateNavigationRefPutOperationReturnsCorrectOperation(bool enableOp Assert.Equal("People.Person", tag.Name); Assert.NotNull(operation.Parameters); - Assert.Equal(1, operation.Parameters.Count); + Assert.Single(operation.Parameters); Assert.Equal(Models.ReferenceType.RequestBody, operation.RequestBody.Reference.Type); Assert.Equal(Common.Constants.ReferencePutRequestBodyName, operation.RequestBody.Reference.Id); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/SingletonGetOperationHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/SingletonGetOperationHandlerTests.cs index acff34e1..b5c691bf 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/SingletonGetOperationHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/SingletonGetOperationHandlerTests.cs @@ -304,7 +304,7 @@ private void VerifyParameter(string annotation, bool hasRestriction, bool suppor } else { - Assert.Equal(1, get.Parameters.Count); + Assert.Single(get.Parameters); Assert.DoesNotContain(queryOption, get.Parameters.Select(p => p.Name)); } } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntityPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntityPathItemHandlerTests.cs index fc1adf7d..f5a060a8 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntityPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntityPathItemHandlerTests.cs @@ -109,7 +109,7 @@ public void CreateEntityPathItemReturnsCorrectPathItemWithPathParameters(bool de if (declarePathParametersOnPathItem) { Assert.NotEmpty(pathItem.Parameters); - Assert.Equal(1, pathItem.Parameters.Count); + Assert.Single(pathItem.Parameters); } else { diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/NavigationPropertyPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/NavigationPropertyPathItemHandlerTests.cs index ba85d971..d7380dd6 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/NavigationPropertyPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/NavigationPropertyPathItemHandlerTests.cs @@ -147,7 +147,7 @@ public void CreateNavigationPropertyPathItemReturnsCorrectPathItemWithPathParame } else { - Assert.Equal(1, pathItem.Parameters.Count); // Customer ID + Assert.Single(pathItem.Parameters); // Customer ID } } else diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OData.xml b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OData.xml index 4154c778..6ec22e9c 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OData.xml +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OData.xml @@ -249,11 +249,11 @@ - + - + diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.json b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.json index 395d643b..63189d75 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.json +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.json @@ -27922,7 +27922,11 @@ "Feature3", "Feature4" ], - "type": "string" + "type": "string", + "x-ms-enum-flags": { + "isFlags": true, + "style": "simple" + } }, "Edm.Geography": { "$ref": "#/definitions/Edm.Geometry" diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.yaml b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.yaml index 44e4b4b8..86df0ff5 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.yaml +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.yaml @@ -19625,6 +19625,9 @@ definitions: - Feature3 - Feature4 type: string + x-ms-enum-flags: + isFlags: true + style: simple Edm.Geography: $ref: '#/definitions/Edm.Geometry' Edm.GeographyPoint: diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json index 9524cf59..8f9b290f 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json @@ -31294,7 +31294,11 @@ "Feature3", "Feature4" ], - "type": "string" + "type": "string", + "x-ms-enum-flags": { + "isFlags": true, + "style": "simple" + } }, "Edm.Geography": { "$ref": "#/components/schemas/Edm.Geometry" diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml index 19dd0d0d..5f613dc2 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml @@ -21805,6 +21805,9 @@ components: - Feature3 - Feature4 type: string + x-ms-enum-flags: + isFlags: true + style: simple Edm.Geography: $ref: '#/components/schemas/Edm.Geometry' Edm.GeographyPoint: