From 46936985bd6450eb894a7f77782f2a601f85526d Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Tue, 4 Apr 2023 21:24:39 +0300 Subject: [PATCH 01/16] Refactor striping and aliasing of namespace prefixes --- .../Common/EdmModelHelper.cs | 43 +++++++++++++++++++ .../Edm/ODataOperationSegment.cs | 13 +++--- .../Edm/ODataTypeCastSegment.cs | 18 ++------ 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs b/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs index caad2af4..f9cdacf6 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs @@ -6,7 +6,9 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime; using Microsoft.OData.Edm; +using Microsoft.OData.Edm.Csdl; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; @@ -341,5 +343,46 @@ internal static string GenerateODataTypeCastPathOperationIdPrefix(ODataPath path return operationId; } + + internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, IEdmModel model, OpenApiConvertSettings settings) + { + Utils.CheckArgumentNull(element, nameof(element)); + Utils.CheckArgumentNull(model, nameof(model)); + Utils.CheckArgumentNull(settings, nameof(settings)); + + string namespaceAlias = string.Empty; + string namespaceName = element.Namespace; + string segmentName = element.FullName(); + + if (!string.IsNullOrEmpty(namespaceName)) + { + namespaceAlias = model.GetNamespaceAlias(namespaceName); + } + + if (element is IEdmStructuredType) + { + if (settings.EnableAliasForTypeCastSegments && !string.IsNullOrEmpty(namespaceAlias)) + { + // Alias type cast segment name + segmentName = namespaceAlias.TrimEnd('.') + "." + element.Name; + } + } + + if (element is IEdmOperation) + { + if (settings.EnableAliasForOperationSegments && !string.IsNullOrEmpty(namespaceAlias)) + { + // Strip namespace from operation segment name + segmentName = namespaceAlias.TrimEnd('.') + "." + element.Name; + } + else if (element.Namespace.Equals(settings.NamespacePrefixToStripForInMethodPaths, StringComparison.OrdinalIgnoreCase)) + { + // Alias operation segment name + segmentName = element.Name; + } + } + + return segmentName; + } } } \ No newline at end of file diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs index 44e7f0f0..cfc23041 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs @@ -1,12 +1,15 @@ -// ------------------------------------------------------------ +// ----- +// private readonly IEdmModel _model;------------------------------------------------------- // 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 System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.OData.Edm; +using Microsoft.OData.Edm.Csdl; using Microsoft.OData.Edm.Vocabularies; using Microsoft.OpenApi.OData.Common; @@ -47,7 +50,7 @@ public ODataOperationSegment(IEdmOperation operation, IDictionary /// Gets the parameter mappings. /// @@ -118,11 +121,9 @@ private string OperationName(IEdmOperation operation, OpenApiConvertSettings set } else { - string selectedName = operation.FullName(); - return !string.IsNullOrEmpty(settings.NamespacePrefixToStripForInMethodPaths) - ? selectedName.StripNamespacePrefix(settings.NamespacePrefixToStripForInMethodPaths) - : selectedName; + // return EdmModelHelper.StripOrAliasNamespacePrefix(operation, _model, settings); } + return null; } private string FunctionName(IEdmFunction function, OpenApiConvertSettings settings, HashSet parameters) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs index 718fc1c9..4c3f3cb4 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs @@ -53,20 +53,10 @@ public override IEnumerable GetAnnotables() public override string GetPathItemName(OpenApiConvertSettings settings, HashSet parameters) { Utils.CheckArgumentNull(settings, nameof(settings)); - string namespaceName = string.Empty; - string namespaceAlias = string.Empty; + + IEdmSchemaElement element = StructuredType as IEdmSchemaElement; - if (StructuredType is IEdmSchemaElement element) - namespaceName = element.Namespace; - - if (!string.IsNullOrEmpty(namespaceName)) - namespaceAlias = _model.GetNamespaceAlias(namespaceName); - - if(settings.EnableAliasForTypeCastSegments && !string.IsNullOrEmpty(namespaceAlias)) - { - return namespaceAlias.TrimEnd('.') + "." + StructuredType.FullTypeName().Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Last(); - } - - return StructuredType.FullTypeName(); + string name = EdmModelHelper.StripOrAliasNamespacePrefix(element, _model, settings); + return name; } } \ No newline at end of file From d5c0c85c2e8cd5c4c9909936fbad351fbc54c491 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Tue, 4 Apr 2023 21:26:23 +0300 Subject: [PATCH 02/16] Adds new convert setting --- .../OpenApiConvertSettings.cs | 8 +++++++- .../PublicAPI.Unshipped.txt | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs b/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs index aa26aba4..59d44012 100644 --- a/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs +++ b/src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs @@ -336,6 +336,11 @@ public string PathPrefix /// public bool EnableAliasForTypeCastSegments { get; set; } = false; + /// + /// Enables the use of aliases for operation segments to shorten the url path. + /// + public bool EnableAliasForOperationSegments { get; set; } = false; + internal OpenApiConvertSettings Clone() { var newSettings = new OpenApiConvertSettings @@ -387,7 +392,8 @@ internal OpenApiConvertSettings Clone() AddAlternateKeyPaths = this.AddAlternateKeyPaths, NamespacePrefixToStripForInMethodPaths = this.NamespacePrefixToStripForInMethodPaths, EnableAliasForTypeCastSegments = this.EnableAliasForTypeCastSegments, - SemVerVersion = this.SemVerVersion + SemVerVersion = this.SemVerVersion, + EnableAliasForOperationSegments = this.EnableAliasForOperationSegments }; return newSettings; diff --git a/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt b/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt index 581b498a..e11ce0cb 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt +++ b/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt @@ -14,6 +14,8 @@ Microsoft.OpenApi.OData.OpenApiConvertSettings.AppendBoundOperationsOnDerivedTyp Microsoft.OpenApi.OData.OpenApiConvertSettings.AppendBoundOperationsOnDerivedTypeCastSegments.set -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomHttpMethodLinkRelMapping.get -> System.Collections.Generic.Dictionary Microsoft.OpenApi.OData.OpenApiConvertSettings.CustomHttpMethodLinkRelMapping.set -> void +Microsoft.OpenApi.OData.OpenApiConvertSettings.EnableAliasForOperationSegments.get -> bool +Microsoft.OpenApi.OData.OpenApiConvertSettings.EnableAliasForOperationSegments.set -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.EnableAliasForTypeCastSegments.get -> bool Microsoft.OpenApi.OData.OpenApiConvertSettings.EnableAliasForTypeCastSegments.set -> void Microsoft.OpenApi.OData.OpenApiConvertSettings.EnableCount.get -> bool From 8263e08f0df52c4b315da85105c1bcfa0f7972c4 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 6 Apr 2023 16:16:16 +0300 Subject: [PATCH 03/16] Add function that strips or aliases namespace prefix --- .../Common/EdmModelHelper.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs b/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs index f9cdacf6..b0aa922d 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs @@ -344,17 +344,23 @@ internal static string GenerateODataTypeCastPathOperationIdPrefix(ODataPath path return operationId; } - internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, IEdmModel model, OpenApiConvertSettings settings) + /// + /// Strips or aliases namespace prefixes from an element name. + /// + /// The target element. + /// Optional: The Edm model. Used for searching for the namespace alias. + /// The OpenAPI convert settings. + /// The element name, alias-prefixed or namespace-stripped if applicable. + internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, OpenApiConvertSettings settings, IEdmModel model = null) { Utils.CheckArgumentNull(element, nameof(element)); - Utils.CheckArgumentNull(model, nameof(model)); Utils.CheckArgumentNull(settings, nameof(settings)); string namespaceAlias = string.Empty; string namespaceName = element.Namespace; string segmentName = element.FullName(); - if (!string.IsNullOrEmpty(namespaceName)) + if (!string.IsNullOrEmpty(namespaceName) && model != null) { namespaceAlias = model.GetNamespaceAlias(namespaceName); } @@ -372,12 +378,12 @@ internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, IE { if (settings.EnableAliasForOperationSegments && !string.IsNullOrEmpty(namespaceAlias)) { - // Strip namespace from operation segment name + // Alias operation segment name segmentName = namespaceAlias.TrimEnd('.') + "." + element.Name; } else if (element.Namespace.Equals(settings.NamespacePrefixToStripForInMethodPaths, StringComparison.OrdinalIgnoreCase)) { - // Alias operation segment name + // Strip specified namespace from operation segment name segmentName = element.Name; } } From 763688b97a31d6b52eb02305f7b942214194eda0 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 6 Apr 2023 16:41:23 +0300 Subject: [PATCH 04/16] Alias or strip namespace prefixes from operation segments --- .../Edm/ODataOperationSegment.cs | 36 ++++++++++++++++--- .../Edm/ODataPathProvider.cs | 12 +++---- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs index cfc23041..6ad4a2b5 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataOperationSegment.cs @@ -4,12 +4,10 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ -using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.OData.Edm; -using Microsoft.OData.Edm.Csdl; using Microsoft.OData.Edm.Vocabularies; using Microsoft.OpenApi.OData.Common; @@ -50,6 +48,31 @@ public ODataOperationSegment(IEdmOperation operation, IDictionary + /// Initializes a new instance of class. + /// + /// The operation. + /// The Edm model. + public ODataOperationSegment(IEdmOperation operation, IEdmModel model) + : this(operation, false, model) + { + } + + /// + /// Initializes a new instance of class. + /// + /// The operation. + /// A value indicating this operation is an escaped function. + /// The Edm model. + public ODataOperationSegment(IEdmOperation operation, bool isEscapedFunction, IEdmModel model) + { + Operation = operation ?? throw Error.ArgumentNull(nameof(operation)); + IsEscapedFunction = isEscapedFunction; + _model = model ?? throw Error.ArgumentNull(nameof(model)); + } + + private readonly IEdmModel _model; /// /// Gets the parameter mappings. @@ -119,11 +142,14 @@ private string OperationName(IEdmOperation operation, OpenApiConvertSettings set { return operation.Name; } + else if (_model != null) + { + return EdmModelHelper.StripOrAliasNamespacePrefix(operation, settings, _model); + } else { - // return EdmModelHelper.StripOrAliasNamespacePrefix(operation, _model, settings); + return operation.FullName(); } - return null; } private string FunctionName(IEdmFunction function, OpenApiConvertSettings settings, HashSet parameters) @@ -168,5 +194,5 @@ public override IEnumerable GetAnnotables() { return new IEdmVocabularyAnnotatable[] { Operation }; } - } + } } \ No newline at end of file diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs index 868fd881..aaf66cfa 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs @@ -781,7 +781,7 @@ secondLastPathSegment is not ODataKeySegment && if (lastPathSegment is ODataTypeCastSegment && !convertSettings.AppendBoundOperationsOnDerivedTypeCastSegments) continue; if (lastPathSegment is ODataKeySegment segment && segment.IsAlternateKey) continue; ODataPath newPath = subPath.Clone(); - newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction)); + newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction, _model)); AppendPath(newPath); } } @@ -828,7 +828,7 @@ private void AppendBoundOperationOnNavigationPropertyPath(IEdmOperation edmOpera } ODataPath newPath = path.Clone(); - newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction)); + newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction, _model)); AppendPath(newPath); } } @@ -861,7 +861,7 @@ private void AppendBoundOperationOnDerived( if (ns is IEdmEntitySet) { ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataTypeCastSegment(bindingEntityType, _model), - new ODataOperationSegment(edmOperation, isEscapedFunction)); + new ODataOperationSegment(edmOperation, isEscapedFunction, _model)); AppendPath(newPath); } } @@ -870,14 +870,14 @@ private void AppendBoundOperationOnDerived( if (ns is IEdmSingleton) { ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataTypeCastSegment(bindingEntityType, _model), - new ODataOperationSegment(edmOperation, isEscapedFunction)); + new ODataOperationSegment(edmOperation, isEscapedFunction, _model)); AppendPath(newPath); } else { ODataPath newPath = new ODataPath(new ODataNavigationSourceSegment(ns), new ODataKeySegment(ns.EntityType()), new ODataTypeCastSegment(bindingEntityType , _model), - new ODataOperationSegment(edmOperation, isEscapedFunction)); + new ODataOperationSegment(edmOperation, isEscapedFunction, _model)); AppendPath(newPath); } } @@ -957,7 +957,7 @@ private void AppendBoundOperationOnDerivedNavigationPropertyPath( ODataPath newPath = path.Clone(); newPath.Push(new ODataTypeCastSegment(bindingEntityType, _model)); - newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction)); + newPath.Push(new ODataOperationSegment(edmOperation, isEscapedFunction, _model)); AppendPath(newPath); } } From 6f9dd026e898014a924a844f29f56fe1eda05321 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 6 Apr 2023 17:01:19 +0300 Subject: [PATCH 05/16] Strip or alias namespace prefix for type cast paths --- .../Edm/ODataTypeCastSegment.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs index 4c3f3cb4..4614f307 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs @@ -3,11 +3,8 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ -using System; using System.Collections.Generic; -using System.Linq; using Microsoft.OData.Edm; -using Microsoft.OData.Edm.Csdl; using Microsoft.OData.Edm.Vocabularies; using Microsoft.OpenApi.OData.Common; @@ -54,9 +51,10 @@ public override string GetPathItemName(OpenApiConvertSettings settings, HashSet< { Utils.CheckArgumentNull(settings, nameof(settings)); - IEdmSchemaElement element = StructuredType as IEdmSchemaElement; + IEdmSchemaElement element = StructuredType as IEdmSchemaElement; - string name = EdmModelHelper.StripOrAliasNamespacePrefix(element, _model, settings); - return name; + return element != null && _model != null + ? EdmModelHelper.StripOrAliasNamespacePrefix(element, settings, _model) + : (element?.FullName()); } } \ No newline at end of file From 8277fe011544db35bde314d3ce6a2a6182f9810d Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 6 Apr 2023 17:02:49 +0300 Subject: [PATCH 06/16] Update public API doc. --- .../PublicAPI.Unshipped.txt | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt b/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt index e11ce0cb..a40f45f6 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt +++ b/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt @@ -7,6 +7,13 @@ Microsoft.OpenApi.OData.Edm.EdmModelExtensions Microsoft.OpenApi.OData.Edm.EdmTypeExtensions Microsoft.OpenApi.OData.Edm.ODataKeySegment.IsAlternateKey.get -> bool Microsoft.OpenApi.OData.Edm.ODataKeySegment.IsAlternateKey.set -> void +Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation) -> void +Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, bool isEscapedFunction) -> void +Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, bool isEscapedFunction, Microsoft.OData.Edm.IEdmModel model) -> void +Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, Microsoft.OData.Edm.IEdmModel model) -> void +Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, System.Collections.Generic.IDictionary parameterMappings) -> void +Microsoft.OpenApi.OData.Edm.ODataPath.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> string +Microsoft.OpenApi.OData.Edm.ODataSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> string 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 @@ -49,6 +56,15 @@ Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Function = 5 -> Microsoft.Ope Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.List = 1 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.ReadByKey = 0 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Update = 3 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey +override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataRefSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string static Microsoft.OpenApi.OData.Common.OpenApiOperationExtensions.AddErrorResponses(this Microsoft.OpenApi.Models.OpenApiOperation operation, Microsoft.OpenApi.OData.OpenApiConvertSettings settings, bool addNoContent = false, Microsoft.OpenApi.Models.OpenApiSchema schema = null) -> void static Microsoft.OpenApi.OData.Edm.EdmModelExtensions.OperationTargetsMultiplePaths(this Microsoft.OData.Edm.IEdmModel model, Microsoft.OData.Edm.IEdmOperation operation) -> bool static Microsoft.OpenApi.OData.Edm.EdmTypeExtensions.ShouldPathParameterBeQuoted(this Microsoft.OData.Edm.IEdmType edmType, Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> bool @@ -76,9 +92,6 @@ Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.OperationImport.get -> M Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.ParameterMappings.get -> System.Collections.Generic.IDictionary Microsoft.OpenApi.OData.Edm.ODataOperationSegment Microsoft.OpenApi.OData.Edm.ODataOperationSegment.IsEscapedFunction.get -> bool -Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation) -> void -Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, bool isEscapedFunction) -> void -Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, System.Collections.Generic.IDictionary parameterMappings) -> void Microsoft.OpenApi.OData.Edm.ODataOperationSegment.Operation.get -> Microsoft.OData.Edm.IEdmOperation Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ParameterMappings.get -> System.Collections.Generic.IDictionary Microsoft.OpenApi.OData.Edm.ODataPath @@ -90,7 +103,6 @@ Microsoft.OpenApi.OData.Edm.ODataPath.FirstSegment.get -> Microsoft.OpenApi.ODat Microsoft.OpenApi.OData.Edm.ODataPath.GetCount(bool keySegmentAsDepth) -> int Microsoft.OpenApi.OData.Edm.ODataPath.GetEnumerator() -> System.Collections.Generic.IEnumerator Microsoft.OpenApi.OData.Edm.ODataPath.GetPathItemName() -> string -Microsoft.OpenApi.OData.Edm.ODataPath.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> string Microsoft.OpenApi.OData.Edm.ODataPath.HttpMethods.get -> System.Collections.Generic.ISet Microsoft.OpenApi.OData.Edm.ODataPath.LastSegment.get -> Microsoft.OpenApi.OData.Edm.ODataSegment Microsoft.OpenApi.OData.Edm.ODataPath.ODataPath(params Microsoft.OpenApi.OData.Edm.ODataSegment[] segments) -> void @@ -116,7 +128,6 @@ Microsoft.OpenApi.OData.Edm.ODataPathProvider Microsoft.OpenApi.OData.Edm.ODataPathProvider.ODataPathProvider() -> void Microsoft.OpenApi.OData.Edm.ODataRefSegment Microsoft.OpenApi.OData.Edm.ODataSegment -Microsoft.OpenApi.OData.Edm.ODataSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> string Microsoft.OpenApi.OData.Edm.ODataSegment.GetPathHash(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, Microsoft.OpenApi.OData.Edm.ODataPath path = null) -> string Microsoft.OpenApi.OData.Edm.ODataSegment.ODataSegment() -> void Microsoft.OpenApi.OData.Edm.ODataSegmentKind @@ -145,7 +156,6 @@ override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.Kind.get -> Mic override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.Identifier.get -> string Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.ComplexType.get -> Microsoft.OData.Edm.IEdmComplexType override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string Microsoft.OpenApi.OData.EdmModelOpenApiExtensions Microsoft.OpenApi.OData.Extensions.IODataRoutePathPrefixProvider Microsoft.OpenApi.OData.Extensions.IODataRoutePathPrefixProvider.Parameters.get -> System.Collections.Generic.IEnumerable @@ -242,13 +252,11 @@ override Microsoft.OpenApi.OData.Edm.ODataKeySegment.GetPathItemName(Microsoft.O override Microsoft.OpenApi.OData.Edm.ODataKeySegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataKeySegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataKeySegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType -override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.GetAnnotables() -> System.Collections.Generic.IEnumerable @@ -257,34 +265,28 @@ override Microsoft.OpenApi.OData.Edm.ODataNavigationSourceSegment.GetPathItemNam override Microsoft.OpenApi.OData.Edm.ODataNavigationSourceSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataNavigationSourceSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataNavigationSourceSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable override Microsoft.OpenApi.OData.Edm.ODataPath.ToString() -> string -override Microsoft.OpenApi.OData.Edm.ODataRefSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataRefSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataRefSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataRefSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataRefSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.GetAnnotables() -> System.Collections.Generic.IEnumerable Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.StructuredType.get -> Microsoft.OData.Edm.IEdmStructuredType -override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind From 4bbbeb6ca4928f2008fe7b15c9c88b4e20990d7e Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 6 Apr 2023 17:05:58 +0300 Subject: [PATCH 07/16] Update unit test --- .../Edm/ODataOperationSegmentTests.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs index f65a5dd0..71c9586f 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs @@ -73,20 +73,22 @@ public void GetPathItemNameReturnsCorrectActionLiteral(bool unqualifiedCall, boo } [Theory] - [InlineData(true, true, "MyFunction(param={param},param2=@param2)", null)] - [InlineData(true, false, "MyFunction(entity={entity},param={param},param2=@param2)", null)] - [InlineData(false, true, "XY.MyFunction(param={param},param2=@param2)", "NS")] - [InlineData(false, false, "XY.MyFunction(entity={entity},param={param},param2=@param2)", "NS")] - public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, bool isBound, string expected, string namespacePrefixToStrip) + [InlineData(true, true, "MyFunction(param={param},param2=@param2)", null, "NS.XY")] + [InlineData(true, false, "MyFunction(entity={entity},param={param},param2=@param2)", null, "NS.XY")] + [InlineData(false, true, "NS.XY.MyFunction(param={param},param2=@param2)", "NS", "NS.XY")] + [InlineData(false, true, "MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY")] + [InlineData(false, false, "NS.XY.MyFunction(entity={entity},param={param},param2=@param2)", "NS", "NS.XY")] + [InlineData(false, false, "MyFunction(entity={entity},param={param},param2=@param2)", "NS.XY", "NS.XY")] + public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, bool isBound, string expected, string namespacePrefixToStrip, string namespaceName) { // Arrange & Act IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType("NS.XY", "Entity"), false); IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false); - EdmFunction boundFunction = BoundFunction("MyFunction", isBound, entityTypeReference, namespaceIdentifier: "NS.XY"); + EdmFunction boundFunction = BoundFunction("MyFunction", isBound, entityTypeReference, namespaceIdentifier: namespaceName); boundFunction.AddParameter("param", parameterType); boundFunction.AddOptionalParameter("param2", parameterType); - var segment = new ODataOperationSegment(boundFunction); + var segment = new ODataOperationSegment(boundFunction, EdmCoreModel.Instance); OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableUnqualifiedCall = unqualifiedCall, @@ -111,7 +113,7 @@ public void GetPathItemNameReturnsCorrectFunctionLiteralForEscapedFunction(bool boundFunction.AddParameter("param", parameterType); boundFunction.AddOptionalParameter("param2", parameterType); - var segment = new ODataOperationSegment(boundFunction, isEscapedFunction); + var segment = new ODataOperationSegment(boundFunction, isEscapedFunction, EdmCoreModel.Instance); OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableUriEscapeFunctionCall = enableEscapeFunctionCall, @@ -136,7 +138,7 @@ public void GetPathItemNameReturnsCorrectFunctionLiteralForEscapedComposableFunc boundFunction.AddParameter("param", parameterType); boundFunction.AddOptionalParameter("param2", parameterType); - var segment = new ODataOperationSegment(boundFunction, isEscapedFunction); + var segment = new ODataOperationSegment(boundFunction, isEscapedFunction, EdmCoreModel.Instance); OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableUriEscapeFunctionCall = enableEscapeFunctionCall, From b2f949f2fca5074fcfe5d752095713dd5a67dc8f Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 6 Apr 2023 17:01:19 +0300 Subject: [PATCH 08/16] Strip or aliases namespace prefix from type cast segments --- .../Edm/ODataTypeCastSegment.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs index 4c3f3cb4..4614f307 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs @@ -3,11 +3,8 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ -using System; using System.Collections.Generic; -using System.Linq; using Microsoft.OData.Edm; -using Microsoft.OData.Edm.Csdl; using Microsoft.OData.Edm.Vocabularies; using Microsoft.OpenApi.OData.Common; @@ -54,9 +51,10 @@ public override string GetPathItemName(OpenApiConvertSettings settings, HashSet< { Utils.CheckArgumentNull(settings, nameof(settings)); - IEdmSchemaElement element = StructuredType as IEdmSchemaElement; + IEdmSchemaElement element = StructuredType as IEdmSchemaElement; - string name = EdmModelHelper.StripOrAliasNamespacePrefix(element, _model, settings); - return name; + return element != null && _model != null + ? EdmModelHelper.StripOrAliasNamespacePrefix(element, settings, _model) + : (element?.FullName()); } } \ No newline at end of file From d4c0653650ed0fdd8dd09f6a640593f444659585 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 6 Apr 2023 17:02:49 +0300 Subject: [PATCH 09/16] Update public API doc. --- .../PublicAPI.Unshipped.txt | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt b/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt index e11ce0cb..a40f45f6 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt +++ b/src/Microsoft.OpenApi.OData.Reader/PublicAPI.Unshipped.txt @@ -7,6 +7,13 @@ Microsoft.OpenApi.OData.Edm.EdmModelExtensions Microsoft.OpenApi.OData.Edm.EdmTypeExtensions Microsoft.OpenApi.OData.Edm.ODataKeySegment.IsAlternateKey.get -> bool Microsoft.OpenApi.OData.Edm.ODataKeySegment.IsAlternateKey.set -> void +Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation) -> void +Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, bool isEscapedFunction) -> void +Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, bool isEscapedFunction, Microsoft.OData.Edm.IEdmModel model) -> void +Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, Microsoft.OData.Edm.IEdmModel model) -> void +Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, System.Collections.Generic.IDictionary parameterMappings) -> void +Microsoft.OpenApi.OData.Edm.ODataPath.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> string +Microsoft.OpenApi.OData.Edm.ODataSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> string 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 @@ -49,6 +56,15 @@ Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Function = 5 -> Microsoft.Ope Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.List = 1 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.ReadByKey = 0 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey.Update = 3 -> Microsoft.OpenApi.OData.Vocabulary.Core.LinkRelKey +override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataRefSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string +override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string static Microsoft.OpenApi.OData.Common.OpenApiOperationExtensions.AddErrorResponses(this Microsoft.OpenApi.Models.OpenApiOperation operation, Microsoft.OpenApi.OData.OpenApiConvertSettings settings, bool addNoContent = false, Microsoft.OpenApi.Models.OpenApiSchema schema = null) -> void static Microsoft.OpenApi.OData.Edm.EdmModelExtensions.OperationTargetsMultiplePaths(this Microsoft.OData.Edm.IEdmModel model, Microsoft.OData.Edm.IEdmOperation operation) -> bool static Microsoft.OpenApi.OData.Edm.EdmTypeExtensions.ShouldPathParameterBeQuoted(this Microsoft.OData.Edm.IEdmType edmType, Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> bool @@ -76,9 +92,6 @@ Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.OperationImport.get -> M Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.ParameterMappings.get -> System.Collections.Generic.IDictionary Microsoft.OpenApi.OData.Edm.ODataOperationSegment Microsoft.OpenApi.OData.Edm.ODataOperationSegment.IsEscapedFunction.get -> bool -Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation) -> void -Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, bool isEscapedFunction) -> void -Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ODataOperationSegment(Microsoft.OData.Edm.IEdmOperation operation, System.Collections.Generic.IDictionary parameterMappings) -> void Microsoft.OpenApi.OData.Edm.ODataOperationSegment.Operation.get -> Microsoft.OData.Edm.IEdmOperation Microsoft.OpenApi.OData.Edm.ODataOperationSegment.ParameterMappings.get -> System.Collections.Generic.IDictionary Microsoft.OpenApi.OData.Edm.ODataPath @@ -90,7 +103,6 @@ Microsoft.OpenApi.OData.Edm.ODataPath.FirstSegment.get -> Microsoft.OpenApi.ODat Microsoft.OpenApi.OData.Edm.ODataPath.GetCount(bool keySegmentAsDepth) -> int Microsoft.OpenApi.OData.Edm.ODataPath.GetEnumerator() -> System.Collections.Generic.IEnumerator Microsoft.OpenApi.OData.Edm.ODataPath.GetPathItemName() -> string -Microsoft.OpenApi.OData.Edm.ODataPath.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> string Microsoft.OpenApi.OData.Edm.ODataPath.HttpMethods.get -> System.Collections.Generic.ISet Microsoft.OpenApi.OData.Edm.ODataPath.LastSegment.get -> Microsoft.OpenApi.OData.Edm.ODataSegment Microsoft.OpenApi.OData.Edm.ODataPath.ODataPath(params Microsoft.OpenApi.OData.Edm.ODataSegment[] segments) -> void @@ -116,7 +128,6 @@ Microsoft.OpenApi.OData.Edm.ODataPathProvider Microsoft.OpenApi.OData.Edm.ODataPathProvider.ODataPathProvider() -> void Microsoft.OpenApi.OData.Edm.ODataRefSegment Microsoft.OpenApi.OData.Edm.ODataSegment -Microsoft.OpenApi.OData.Edm.ODataSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings) -> string Microsoft.OpenApi.OData.Edm.ODataSegment.GetPathHash(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, Microsoft.OpenApi.OData.Edm.ODataPath path = null) -> string Microsoft.OpenApi.OData.Edm.ODataSegment.ODataSegment() -> void Microsoft.OpenApi.OData.Edm.ODataSegmentKind @@ -145,7 +156,6 @@ override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.Kind.get -> Mic override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.Identifier.get -> string Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.ComplexType.get -> Microsoft.OData.Edm.IEdmComplexType override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataComplexPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string Microsoft.OpenApi.OData.EdmModelOpenApiExtensions Microsoft.OpenApi.OData.Extensions.IODataRoutePathPrefixProvider Microsoft.OpenApi.OData.Extensions.IODataRoutePathPrefixProvider.Parameters.get -> System.Collections.Generic.IEnumerable @@ -242,13 +252,11 @@ override Microsoft.OpenApi.OData.Edm.ODataKeySegment.GetPathItemName(Microsoft.O override Microsoft.OpenApi.OData.Edm.ODataKeySegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataKeySegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataKeySegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataMetadataSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType -override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataNavigationPropertySegment.GetAnnotables() -> System.Collections.Generic.IEnumerable @@ -257,34 +265,28 @@ override Microsoft.OpenApi.OData.Edm.ODataNavigationSourceSegment.GetPathItemNam override Microsoft.OpenApi.OData.Edm.ODataNavigationSourceSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataNavigationSourceSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataNavigationSourceSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataOperationImportSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataOperationSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable override Microsoft.OpenApi.OData.Edm.ODataPath.ToString() -> string -override Microsoft.OpenApi.OData.Edm.ODataRefSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataRefSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataRefSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataRefSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataRefSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataStreamContentSegment.GetAnnotables() -> System.Collections.Generic.IEnumerable -override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind override Microsoft.OpenApi.OData.Edm.ODataStreamPropertySegment.GetAnnotables() -> System.Collections.Generic.IEnumerable Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.StructuredType.get -> Microsoft.OData.Edm.IEdmStructuredType -override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.GetPathItemName(Microsoft.OpenApi.OData.OpenApiConvertSettings settings, System.Collections.Generic.HashSet parameters) -> string override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.Identifier.get -> string override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.EntityType.get -> Microsoft.OData.Edm.IEdmEntityType override Microsoft.OpenApi.OData.Edm.ODataTypeCastSegment.Kind.get -> Microsoft.OpenApi.OData.Edm.ODataSegmentKind From faabbfa8fdc443db169dd4c01b5533dfeaaec42f Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 6 Apr 2023 17:05:58 +0300 Subject: [PATCH 10/16] Update unit test --- .../Edm/ODataOperationSegmentTests.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs index f65a5dd0..71c9586f 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs @@ -73,20 +73,22 @@ public void GetPathItemNameReturnsCorrectActionLiteral(bool unqualifiedCall, boo } [Theory] - [InlineData(true, true, "MyFunction(param={param},param2=@param2)", null)] - [InlineData(true, false, "MyFunction(entity={entity},param={param},param2=@param2)", null)] - [InlineData(false, true, "XY.MyFunction(param={param},param2=@param2)", "NS")] - [InlineData(false, false, "XY.MyFunction(entity={entity},param={param},param2=@param2)", "NS")] - public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, bool isBound, string expected, string namespacePrefixToStrip) + [InlineData(true, true, "MyFunction(param={param},param2=@param2)", null, "NS.XY")] + [InlineData(true, false, "MyFunction(entity={entity},param={param},param2=@param2)", null, "NS.XY")] + [InlineData(false, true, "NS.XY.MyFunction(param={param},param2=@param2)", "NS", "NS.XY")] + [InlineData(false, true, "MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY")] + [InlineData(false, false, "NS.XY.MyFunction(entity={entity},param={param},param2=@param2)", "NS", "NS.XY")] + [InlineData(false, false, "MyFunction(entity={entity},param={param},param2=@param2)", "NS.XY", "NS.XY")] + public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, bool isBound, string expected, string namespacePrefixToStrip, string namespaceName) { // Arrange & Act IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType("NS.XY", "Entity"), false); IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false); - EdmFunction boundFunction = BoundFunction("MyFunction", isBound, entityTypeReference, namespaceIdentifier: "NS.XY"); + EdmFunction boundFunction = BoundFunction("MyFunction", isBound, entityTypeReference, namespaceIdentifier: namespaceName); boundFunction.AddParameter("param", parameterType); boundFunction.AddOptionalParameter("param2", parameterType); - var segment = new ODataOperationSegment(boundFunction); + var segment = new ODataOperationSegment(boundFunction, EdmCoreModel.Instance); OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableUnqualifiedCall = unqualifiedCall, @@ -111,7 +113,7 @@ public void GetPathItemNameReturnsCorrectFunctionLiteralForEscapedFunction(bool boundFunction.AddParameter("param", parameterType); boundFunction.AddOptionalParameter("param2", parameterType); - var segment = new ODataOperationSegment(boundFunction, isEscapedFunction); + var segment = new ODataOperationSegment(boundFunction, isEscapedFunction, EdmCoreModel.Instance); OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableUriEscapeFunctionCall = enableEscapeFunctionCall, @@ -136,7 +138,7 @@ public void GetPathItemNameReturnsCorrectFunctionLiteralForEscapedComposableFunc boundFunction.AddParameter("param", parameterType); boundFunction.AddOptionalParameter("param2", parameterType); - var segment = new ODataOperationSegment(boundFunction, isEscapedFunction); + var segment = new ODataOperationSegment(boundFunction, isEscapedFunction, EdmCoreModel.Instance); OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableUriEscapeFunctionCall = enableEscapeFunctionCall, From e61196b28f226ba51096ade9ef198a9d8b0c18af Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 6 Apr 2023 17:21:47 +0300 Subject: [PATCH 11/16] Update release notes --- .../Microsoft.OpenAPI.OData.Reader.csproj | 5 +++-- 1 file changed, 3 insertions(+), 2 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 0a2524b2..2fbe8f44 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj +++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj @@ -15,13 +15,14 @@ netstandard2.0 Microsoft.OpenApi.OData true - 1.4.0-preview1 + 1.4.0-preview2 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 -- DELETE methods should always return response status code 204 +- DELETE methods should always return response status code #204 +- Aliases or strips namespace prefixes from segment names when and where applicable #365 Microsoft.OpenApi.OData.Reader ..\..\tool\Microsoft.OpenApi.OData.snk From f222ad66a8842231cfaa2a31dbccd71e7e801289 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 6 Apr 2023 18:17:46 +0300 Subject: [PATCH 12/16] Update operation segment tests --- .../Edm/ODataOperationSegmentTests.cs | 49 ++++++++++++++----- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs index 71c9586f..ab0ba8f2 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs @@ -4,7 +4,9 @@ // ------------------------------------------------------------ using System; +using System.Runtime.CompilerServices; using Microsoft.OData.Edm; +using Microsoft.OData.Edm.Csdl; using Xunit; namespace Microsoft.OpenApi.OData.Edm.Tests @@ -73,26 +75,51 @@ public void GetPathItemNameReturnsCorrectActionLiteral(bool unqualifiedCall, boo } [Theory] - [InlineData(true, true, "MyFunction(param={param},param2=@param2)", null, "NS.XY")] - [InlineData(true, false, "MyFunction(entity={entity},param={param},param2=@param2)", null, "NS.XY")] - [InlineData(false, true, "NS.XY.MyFunction(param={param},param2=@param2)", "NS", "NS.XY")] - [InlineData(false, true, "MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY")] - [InlineData(false, false, "NS.XY.MyFunction(entity={entity},param={param},param2=@param2)", "NS", "NS.XY")] - [InlineData(false, false, "MyFunction(entity={entity},param={param},param2=@param2)", "NS.XY", "NS.XY")] - public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, bool isBound, string expected, string namespacePrefixToStrip, string namespaceName) + [InlineData(true, true, "MyFunction(param={param},param2=@param2)")] + [InlineData(true, false, "MyFunction(entity={entity},param={param},param2=@param2)")] + [InlineData(false, true, "NS.MyFunction(param={param},param2=@param2)")] + [InlineData(false, false, "NS.MyFunction(entity={entity},param={param},param2=@param2)")] + public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, bool isBound, string expected) { // Arrange & Act - IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType("NS.XY", "Entity"), false); + IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType("NS", "Entity"), false); IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false); - EdmFunction boundFunction = BoundFunction("MyFunction", isBound, entityTypeReference, namespaceIdentifier: namespaceName); + EdmFunction boundFunction = BoundFunction("MyFunction", isBound, entityTypeReference, namespaceIdentifier: "NS"); boundFunction.AddParameter("param", parameterType); boundFunction.AddOptionalParameter("param2", parameterType); - var segment = new ODataOperationSegment(boundFunction, EdmCoreModel.Instance); + var segment = new ODataOperationSegment(boundFunction); OpenApiConvertSettings settings = new OpenApiConvertSettings { - EnableUnqualifiedCall = unqualifiedCall, + EnableUnqualifiedCall = unqualifiedCall + }; + + // Assert + Assert.Equal(expected, segment.GetPathItemName(settings)); + } + + [Theory] + [InlineData("NS.XY.MyFunction(param={param},param2=@param2)", "NS", "NS.XY", false)] + [InlineData("MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY", false)] + [InlineData("N.MyFunction(param={param},param2=@param2)", "NS", "NS.XY", true)] + [InlineData("N.MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY", true)] + public void GetPathItemNameReturnsCorrectFunctionLiteralWhenSegmentAliasedOrNamespacePrefixStripped(string expected, string namespacePrefixToStrip, string namespaceName, bool enableAlias) + { + // Arrange & Act + IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType(namespaceName, "Entity"), false); + IEdmTypeReference parameterType = EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Boolean, isNullable: false); + EdmFunction boundFunction = BoundFunction("MyFunction", true, entityTypeReference, namespaceIdentifier: namespaceName); + boundFunction.AddParameter("param", parameterType); + boundFunction.AddOptionalParameter("param2", parameterType); + EdmModel model = new(); + model.AddElement(boundFunction); + model.SetNamespaceAlias(namespaceName, "N"); + + var segment = new ODataOperationSegment(boundFunction, model); + OpenApiConvertSettings settings = new() + { NamespacePrefixToStripForInMethodPaths = namespacePrefixToStrip, + EnableAliasForOperationSegments = enableAlias }; // Assert From 2af6dd058fba3e71000a5d5ca905f669dc19c784 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 10 Apr 2023 09:20:03 -0400 Subject: [PATCH 13/16] Apply suggestions from code review --- .../Common/EdmModelHelper.cs | 11 ++++------- .../Edm/ODataTypeCastSegment.cs | 5 ++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs b/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs index b0aa922d..1c7a5a38 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs @@ -365,13 +365,10 @@ internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, Op namespaceAlias = model.GetNamespaceAlias(namespaceName); } - if (element is IEdmStructuredType) - { - if (settings.EnableAliasForTypeCastSegments && !string.IsNullOrEmpty(namespaceAlias)) - { - // Alias type cast segment name - segmentName = namespaceAlias.TrimEnd('.') + "." + element.Name; - } + if (element is IEdmStructuredType && settings.EnableAliasForTypeCastSegments && !string.IsNullOrEmpty(namespaceAlias)) + { + // Alias type cast segment name + segmentName = namespaceAlias.TrimEnd('.') + "." + element.Name; } if (element is IEdmOperation) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs index 4614f307..1b385efb 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs @@ -51,10 +51,9 @@ public override string GetPathItemName(OpenApiConvertSettings settings, HashSet< { Utils.CheckArgumentNull(settings, nameof(settings)); - IEdmSchemaElement element = StructuredType as IEdmSchemaElement; - return element != null && _model != null + return StructuredType is IEdmSchemaElement element && _model != null ? EdmModelHelper.StripOrAliasNamespacePrefix(element, settings, _model) - : (element?.FullName()); + : (StructuredType.FullName()); } } \ No newline at end of file From c5c2545c06deb45ce4bc6958eb80bbfac09f15c8 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 10 Apr 2023 09:24:03 -0400 Subject: [PATCH 14/16] - fixes review correction --- .../Edm/ODataTypeCastSegment.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs index 1b385efb..6a7e660e 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataTypeCastSegment.cs @@ -54,6 +54,6 @@ public override string GetPathItemName(OpenApiConvertSettings settings, HashSet< return StructuredType is IEdmSchemaElement element && _model != null ? EdmModelHelper.StripOrAliasNamespacePrefix(element, settings, _model) - : (StructuredType.FullName()); + : StructuredType.FullTypeName(); } -} \ No newline at end of file +} From 6fbe5a20390d22f496451a50ab66c77755241dff Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Wed, 12 Apr 2023 22:17:53 +0300 Subject: [PATCH 15/16] Strip namespace prefix independently of aliasing --- src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs | 4 +++- .../Edm/ODataOperationSegmentTests.cs | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs b/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs index 1c7a5a38..d32f653a 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs @@ -378,7 +378,9 @@ internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, Op // Alias operation segment name segmentName = namespaceAlias.TrimEnd('.') + "." + element.Name; } - else if (element.Namespace.Equals(settings.NamespacePrefixToStripForInMethodPaths, StringComparison.OrdinalIgnoreCase)) + + if (settings.NamespacePrefixToStripForInMethodPaths != null && + element.Namespace.Equals(settings.NamespacePrefixToStripForInMethodPaths, StringComparison.OrdinalIgnoreCase)) { // Strip specified namespace from operation segment name segmentName = element.Name; diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs index ab0ba8f2..70d8a152 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Edm/ODataOperationSegmentTests.cs @@ -102,8 +102,9 @@ public void GetPathItemNameReturnsCorrectFunctionLiteral(bool unqualifiedCall, b [InlineData("NS.XY.MyFunction(param={param},param2=@param2)", "NS", "NS.XY", false)] [InlineData("MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY", false)] [InlineData("N.MyFunction(param={param},param2=@param2)", "NS", "NS.XY", true)] - [InlineData("N.MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY", true)] - public void GetPathItemNameReturnsCorrectFunctionLiteralWhenSegmentAliasedOrNamespacePrefixStripped(string expected, string namespacePrefixToStrip, string namespaceName, bool enableAlias) + [InlineData("MyFunction(param={param},param2=@param2)", "NS.XY", "NS.XY", true)] + public void GetPathItemNameReturnsCorrectFunctionLiteralWhenSegmentAliasedOrNamespacePrefixStripped( + string expected, string namespacePrefixToStrip, string namespaceName, bool enableAlias) { // Arrange & Act IEdmEntityTypeReference entityTypeReference = new EdmEntityTypeReference(new EdmEntityType(namespaceName, "Entity"), false); From 621c3b17596a863e016b59d96c52f14b6eca6cb0 Mon Sep 17 00:00:00 2001 From: Irvine Sunday Date: Thu, 13 Apr 2023 19:17:48 +0300 Subject: [PATCH 16/16] PR review suggestions --- src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs b/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs index d32f653a..1a3eefdb 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs @@ -379,10 +379,12 @@ internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, Op segmentName = namespaceAlias.TrimEnd('.') + "." + element.Name; } - if (settings.NamespacePrefixToStripForInMethodPaths != null && + if (!string.IsNullOrEmpty(settings.NamespacePrefixToStripForInMethodPaths) && element.Namespace.Equals(settings.NamespacePrefixToStripForInMethodPaths, StringComparison.OrdinalIgnoreCase)) { - // Strip specified namespace from operation segment name + // Strip specified namespace from operation segment name. + // If the namespace prefix to strip matches the namespace name, + // and the alias has been appended, the alias will be stripped. segmentName = element.Name; } }