From 37ec4f699ca0ee74e1f03fecc24337218e5c7992 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 26 May 2022 14:55:30 +0300 Subject: [PATCH 1/4] Retrieve list of derived types for structured types --- .../Generator/OpenApiSchemaGenerator.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs index a60818c3..96fde287 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs @@ -436,23 +436,26 @@ private static OpenApiSchema CreateStructuredTypeSchema(this ODataContext contex // The discriminator object is added to structured types which have derived types. OpenApiDiscriminator discriminator = null; if (context.Settings.EnableDiscriminatorValue && derivedTypes.Any() && structuredType.BaseType != null) - { - string v3RefIdentifier = new OpenApiSchema + { + Dictionary mapping = new(); + foreach (var item in derivedTypes) { - Reference = new OpenApiReference + string v3RefIdentifier = new OpenApiSchema { - Type = ReferenceType.Schema, - Id = structuredType.FullTypeName() - } - }.Reference.ReferenceV3; + Reference = new OpenApiReference + { + Type = ReferenceType.Schema, + Id = item.FullTypeName() + } + }.Reference.ReferenceV3; + + mapping.Add("#" + item.FullTypeName(), v3RefIdentifier); + } discriminator = new OpenApiDiscriminator { PropertyName = "@odata.type", - Mapping = new Dictionary - { - {"#" + structuredType.FullTypeName(), v3RefIdentifier } - } + Mapping = mapping }; } From 9fc34bd7e4b1733b59b1afe7fc3461dab052bf9e Mon Sep 17 00:00:00 2001 From: Millicent Achieng Date: Thu, 26 May 2022 16:25:23 +0300 Subject: [PATCH 2/4] Update tests for creating structured type schema with discriminator --- .../Generator/OpenApiSchemaGeneratorTests.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs index 98f86e49..241299ec 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs @@ -118,7 +118,23 @@ public void CreateStructuredTypeSchemaWithDiscriminatorValueEnabledReturnsCorrec ""discriminator"": { ""propertyName"": ""@odata.type"", ""mapping"": { - ""#microsoft.graph.directoryObject"": ""#/components/schemas/microsoft.graph.directoryObject"" + ""#microsoft.graph.user"": ""#/components/schemas/microsoft.graph.user"", + ""#microsoft.graph.group"": ""#/components/schemas/microsoft.graph.group"", + ""#microsoft.graph.device"": ""#/components/schemas/microsoft.graph.device"", + ""#microsoft.graph.application"": ""#/components/schemas/microsoft.graph.application"", + ""#microsoft.graph.servicePrincipal"": ""#/components/schemas/microsoft.graph.servicePrincipal"", + ""#microsoft.graph.policyBase"": ""#/components/schemas/microsoft.graph.policyBase"", + ""#microsoft.graph.extensionProperty"": ""#/components/schemas/microsoft.graph.extensionProperty"", + ""#microsoft.graph.endpoint"": ""#/components/schemas/microsoft.graph.endpoint"", + ""#microsoft.graph.resourceSpecificPermissionGrant"": ""#/components/schemas/microsoft.graph.resourceSpecificPermissionGrant"", + ""#microsoft.graph.administrativeUnit"": ""#/components/schemas/microsoft.graph.administrativeUnit"", + ""#microsoft.graph.contract"": ""#/components/schemas/microsoft.graph.contract"", + ""#microsoft.graph.directoryObjectPartnerReference"": ""#/components/schemas/microsoft.graph.directoryObjectPartnerReference"", + ""#microsoft.graph.directoryRole"": ""#/components/schemas/microsoft.graph.directoryRole"", + ""#microsoft.graph.directoryRoleTemplate"": ""#/components/schemas/microsoft.graph.directoryRoleTemplate"", + ""#microsoft.graph.directorySettingTemplate"": ""#/components/schemas/microsoft.graph.directorySettingTemplate"", + ""#microsoft.graph.organization"": ""#/components/schemas/microsoft.graph.organization"", + ""#microsoft.graph.orgContact"": ""#/components/schemas/microsoft.graph.orgContact"" } } } From 1a0b593d64e008e99756a95aabb94eee42952e4c Mon Sep 17 00:00:00 2001 From: Millicent Achieng Date: Fri, 27 May 2022 10:17:49 +0300 Subject: [PATCH 3/4] Simplify how mapping property of dicriminator object is computed --- .../Generator/OpenApiSchemaGenerator.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs index 96fde287..b4a72ed0 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiSchemaGenerator.cs @@ -436,21 +436,16 @@ private static OpenApiSchema CreateStructuredTypeSchema(this ODataContext contex // The discriminator object is added to structured types which have derived types. OpenApiDiscriminator discriminator = null; if (context.Settings.EnableDiscriminatorValue && derivedTypes.Any() && structuredType.BaseType != null) - { - Dictionary mapping = new(); - foreach (var item in derivedTypes) - { - string v3RefIdentifier = new OpenApiSchema + { + Dictionary mapping = derivedTypes + .ToDictionary(x => $"#{x.FullTypeName()}", x => new OpenApiSchema { Reference = new OpenApiReference { Type = ReferenceType.Schema, - Id = item.FullTypeName() + Id = x.FullTypeName() } - }.Reference.ReferenceV3; - - mapping.Add("#" + item.FullTypeName(), v3RefIdentifier); - } + }.Reference.ReferenceV3); discriminator = new OpenApiDiscriminator { From a0d8dd793dfe5d59a43d07c7e9489ba415b115de Mon Sep 17 00:00:00 2001 From: Millicent Achieng Date: Fri, 27 May 2022 16:41:01 +0300 Subject: [PATCH 4/4] Update release notes --- .../Microsoft.OpenAPI.OData.Reader.csproj | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) 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 28b24c6f..36f76183 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj +++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj @@ -15,27 +15,13 @@ netstandard2.0 Microsoft.OpenApi.OData true - 1.0.10-preview3 + 1.0.11-preview1 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 https://github.com/Microsoft/OpenAPI.NET.OData -- Adds path items for properties of complex type. #176, #15 -- Describes errors on error response codes instead of default. #172, #165, #193 -- Fixes a bug where reference objects are not created correctly. #171 -- Adds support for enum values descriptions. #164 -- Declares path parameters on path item instead of operation. #159 -- Multiple fixes on navigation properties path items expansion. #151, #123 -- Multiple fixes for descriptions. #154 -- Fixes a bug where URL templates would be missing quotes for string parameters. #140 -- Fixes description of operations of primitive types. #126 -- Adds support for OData cast segments in path items generation. #123 -- Fixes the response descriptions for functions that return a collection. #122 -- Fixes structured and collection-valued parameters of functions. #203 -- Adds support for discriminator property in inheritance. #118 -- Sets deprecated for operations that are generated from deprecated types/singletons/entitysets/properties in the model. #113 -- Aligns target version to netframework2.0. #139 +- Adds list of all derived types for discriminator mapping #219 Microsoft.OpenApi.OData.Reader ..\..\tool\Microsoft.OpenApi.OData.snk