From 6641868c970e3fd63f157a9ea27415595237e401 Mon Sep 17 00:00:00 2001 From: Millicent Achieng Date: Mon, 24 Oct 2022 12:12:06 +0300 Subject: [PATCH] Temporarily remove support for alternate keys to allow for further discussions --- .../Generator/OpenApiParameterGenerator.cs | 40 --------- .../Microsoft.OpenAPI.OData.Reader.csproj | 3 +- .../OpenApiParameterGeneratorTests.cs | 89 ------------------- 3 files changed, 1 insertion(+), 131 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs index 337b24c9..81914584 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiParameterGenerator.cs @@ -212,46 +212,6 @@ public static IList CreateKeyParameters(this ODataContext cont } } - IList alternateKeyParameters = CreateAlternateKeyParameters(entityType, context); - parameters.AddRange(alternateKeyParameters); - - return parameters; - } - - private static IList CreateAlternateKeyParameters(IEdmEntityType entityType, ODataContext context) - { - IList parameters = new List(); - IEnumerable> alternateKeys = context.Model.GetAlternateKeysAnnotation(entityType); - foreach (var alternateKey in alternateKeys) - { - if (alternateKey.Count() == 1) - { - parameters.Add( - new OpenApiParameter - { - Name = alternateKey.First().Key, - In = ParameterLocation.Path, - Description = $"Alternate key: {alternateKey.First().Value.Name} of {entityType.Name}", - Schema = context.CreateEdmTypeSchema(alternateKey.First().Value.Type) - } - ); - } - else - { - foreach (var compositekey in alternateKey) - { - parameters.Add( - new OpenApiParameter - { - Name = compositekey.Key, - In = ParameterLocation.Path, - Description = $"Composite alternate key: {compositekey.Value.Name} of {entityType.Name}", - Schema = context.CreateEdmTypeSchema(compositekey.Value.Type) - } - ); - } - } - } return parameters; } 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 91b9d5cf..8c988fc5 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.2.0-preview4 + 1.2.0-preview5 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,7 +24,6 @@ - Use convert setting to toggle between referencing @odata.count and @odata.nextLink #282 - Fixes URL Path parameters of type datetime generated as strings with quotes #262 - Set assembly version used for conversion in OpenApiInfo object #208 -- Add support for alternate keys parameters #120 - Adds create and update operations to non-containment navigation properties when restrictions annotations are explicitly set to true #265 - Generate odata.nextLink and odata.deltaLink properties on delta functions response schemas #285 - Omits paths with PathItems without any operation #148 diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiParameterGeneratorTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiParameterGeneratorTests.cs index 5c6a39dd..08b483e7 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiParameterGeneratorTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiParameterGeneratorTests.cs @@ -279,95 +279,6 @@ public void CreateKeyParametersForCompositeKeyWorks(bool prefix) Assert.Equal(expected.ChangeLineBreaks(), json); } - [Fact] - public void CreateKeyParametersForAlternateKeyWithSinglePropertyWorks() - { - // Arrange - EdmModel model = new EdmModel(); - EdmEntityType customer = new EdmEntityType("NS", "Customer"); - customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.String)); - - IEdmProperty alternateId = customer.AddStructuralProperty("AlternateId", EdmPrimitiveTypeKind.String); - model.AddAlternateKeyAnnotation(customer, new Dictionary { { "AltId", alternateId } }); - - model.AddElement(customer); - ODataContext context = new(model); - ODataKeySegment keySegment = new(customer); - - // Act - var parameters = context.CreateKeyParameters(keySegment); - var altParameter = parameters.Last(); - - // Assert - Assert.NotNull(parameters); - Assert.Equal(2, parameters.Count); - string json = altParameter.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); - Assert.Equal(@"{ - ""name"": ""AltId"", - ""in"": ""path"", - ""description"": ""Alternate key: AlternateId of Customer"", - ""style"": ""simple"", - ""schema"": { - ""type"": ""string"", - ""nullable"": true - } -}".ChangeLineBreaks(), json); - } - - [Fact] - public void CreateKeyParametersForAlternateKeyWithMultiplePropertiesWorks() - { - // Arrange - EdmModel model = new EdmModel(); - EdmEntityType customer = new EdmEntityType("NS", "Customer"); - customer.AddKeys(customer.AddStructuralProperty("Id", EdmPrimitiveTypeKind.String)); - - IEdmProperty alternateId1 = customer.AddStructuralProperty("AlternateId1", EdmPrimitiveTypeKind.String); - IEdmProperty alternateId2 = customer.AddStructuralProperty("AlternateId2", EdmPrimitiveTypeKind.String); - model.AddAlternateKeyAnnotation(customer, - new Dictionary - { - { "AltId1", alternateId1 }, - { "AltId2", alternateId2 } - }); - - model.AddElement(customer); - ODataContext context = new(model); - ODataKeySegment keySegment = new(customer); - - // Act - var parameters = context.CreateKeyParameters(keySegment); - var altParameter1 = parameters.Skip(1).First(); - var altParameter2 = parameters.Last(); - - // Assert - Assert.NotNull(parameters); - Assert.Equal(3, parameters.Count); - string json1 = altParameter1.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); - Assert.Equal(@"{ - ""name"": ""AltId1"", - ""in"": ""path"", - ""description"": ""Composite alternate key: AlternateId1 of Customer"", - ""style"": ""simple"", - ""schema"": { - ""type"": ""string"", - ""nullable"": true - } -}".ChangeLineBreaks(), json1); - - string json2 = altParameter2.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0); - Assert.Equal(@"{ - ""name"": ""AltId2"", - ""in"": ""path"", - ""description"": ""Composite alternate key: AlternateId2 of Customer"", - ""style"": ""simple"", - ""schema"": { - ""type"": ""string"", - ""nullable"": true - } -}".ChangeLineBreaks(), json2); - } - [Fact] public void CreateOrderByAndSelectAndExpandParametersWorks() {