diff --git a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs index 8f60d187..300accc9 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Edm/ODataContext.cs @@ -135,7 +135,7 @@ public IEnumerable AllPaths /// /// Gets all tags. /// - public IList Tags { get; private set; } + public ISet Tags { get; private set; } /// /// Append tag. @@ -143,7 +143,7 @@ public IEnumerable AllPaths /// The tag item. internal void AppendTag(OpenApiTag tagItem) { - Tags ??= []; + Tags ??= new HashSet(); if (FindTagByName(tagItem.Name) is not null) { diff --git a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiDocumentGenerator.cs b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiDocumentGenerator.cs index 273ae47f..b2b606e5 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiDocumentGenerator.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiDocumentGenerator.cs @@ -38,7 +38,7 @@ public static OpenApiDocument CreateDocument(this ODataContext context) Servers = context.CreateServers(), - SecurityRequirements = null, + Security = null, ExternalDocs = null, }; diff --git a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiPathItemGenerator.cs b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiPathItemGenerator.cs index 604b5676..5aa19ad1 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiPathItemGenerator.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiPathItemGenerator.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -58,9 +59,9 @@ public static void AddPathItemsToDocument(this ODataContext context, OpenApiDocu { OpenApiPathItem rootPath = new() { - Operations = new Dictionary { + Operations = new Dictionary { { - OperationType.Get, new OpenApiOperation { + HttpMethod.Get, new OpenApiOperation { OperationId = "graphService.GetGraphService", Responses = new OpenApiResponses() { diff --git a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiTagGenerator.cs b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiTagGenerator.cs index 83ffe828..c96d7695 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiTagGenerator.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiTagGenerator.cs @@ -22,7 +22,7 @@ internal static class OpenApiTagGenerator /// /// The OData context. /// The created collection of object. - public static IList CreateTags(this ODataContext context) + public static ISet CreateTags(this ODataContext context) { Utils.CheckArgumentNull(context, nameof(context)); @@ -38,7 +38,7 @@ public static IList CreateTags(this ODataContext context) return context.Tags; } - IList tags = new List(); + var tags = new HashSet(); if (context.EntityContainer != null) { foreach (IEdmEntityContainerElement element in context.Model.EntityContainer.Elements) 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 f0cb63c3..8d3997c6 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj +++ b/src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj @@ -29,7 +29,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyBaseOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyBaseOperationHandler.cs index c23ab894..79843b93 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyBaseOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyBaseOperationHandler.cs @@ -9,6 +9,7 @@ using Microsoft.OpenApi.OData.Common; using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Vocabulary.Core; +using System.Collections.Generic; namespace Microsoft.OpenApi.OData.Operation; @@ -35,7 +36,7 @@ protected override void Initialize(ODataContext context, ODataPath path) protected override void SetTags(OpenApiOperation operation) { string tagName = EdmModelHelper.GenerateComplexPropertyPathTagName(Path, Context); - + operation.Tags ??= new HashSet(); if (!string.IsNullOrEmpty(tagName)) { Context.AddExtensionToTag(tagName, Constants.xMsTocType, new OpenApiAny("page"), () => new OpenApiTag() diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyGetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyGetOperationHandler.cs index b8e01ccc..6e873c83 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyGetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyGetOperationHandler.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System.Linq; +using System.Net.Http; using System.Text.Json.Nodes; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; @@ -28,7 +29,7 @@ public ComplexPropertyGetOperationHandler(OpenApiDocument document):base(documen } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; private ReadRestrictionsType _readRestrictions; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPatchOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPatchOperationHandler.cs index 43aeafa4..a79a42ee 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPatchOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPatchOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OpenApi.Models; namespace Microsoft.OpenApi.OData.Operation; @@ -18,5 +19,5 @@ public ComplexPropertyPatchOperationHandler(OpenApiDocument document):base(docum } /// - public override OperationType OperationType => OperationType.Patch; + public override HttpMethod OperationType => HttpMethod.Patch; } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPostOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPostOperationHandler.cs index 1d6c4e93..a6734b03 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPostOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPostOperationHandler.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.References; @@ -41,7 +42,7 @@ protected override void Initialize(ODataContext context, ODataPath path) _insertRestrictions ??= complexPropertyInsertRestrictions; } /// - public override OperationType OperationType => OperationType.Post; + public override HttpMethod OperationType => HttpMethod.Post; private InsertRestrictionsType _insertRestrictions; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPutOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPutOperationHandler.cs index 3ea9d299..e8793d0e 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPutOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyPutOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OpenApi.Models; namespace Microsoft.OpenApi.OData.Operation; @@ -18,5 +19,5 @@ public ComplexPropertyPutOperationHandler(OpenApiDocument document) : base(docum } /// - public override OperationType OperationType => OperationType.Put; + public override HttpMethod OperationType => HttpMethod.Put; } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyUpdateOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyUpdateOperationHandler.cs index c05aa00d..1ac6ce8d 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyUpdateOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/ComplexPropertyUpdateOperationHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -50,7 +51,7 @@ protected override void SetBasicInfo(OpenApiOperation operation) // OperationId if (Context.Settings.EnableOperationId) { - string prefix = OperationType == OperationType.Patch ? "Update" : "Set"; + string prefix = OperationType == HttpMethod.Patch ? "Update" : "Set"; operation.OperationId = EdmModelHelper.GenerateComplexPropertyPathOperationId(Path, Context, prefix); } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/DollarCountGetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/DollarCountGetOperationHandler.cs index 226f4501..0f7620d6 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/DollarCountGetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/DollarCountGetOperationHandler.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Vocabularies; using Microsoft.OpenApi.Any; @@ -33,7 +34,7 @@ public DollarCountGetOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; /// /// Gets/sets the segment before $count. @@ -84,6 +85,8 @@ private void AddODataSegmentToAnnotables(ODataSegment oDataSegment, ODataSegment protected override void SetTags(OpenApiOperation operation) { string tagName = null; + operation.Tags ??= new HashSet(); + if (SecondLastSegment is ODataNavigationSourceSegment sourceSegment) { tagName = TagNameFromNavigationSourceSegment(sourceSegment); diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionImportOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionImportOperationHandler.cs index 7d932f7e..4111f9dd 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionImportOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionImportOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; @@ -25,7 +26,7 @@ public EdmActionImportOperationHandler(OpenApiDocument document):base(document) } /// - public override OperationType OperationType => OperationType.Post; + public override HttpMethod OperationType => HttpMethod.Post; protected override void SetRequestBody(OpenApiOperation operation) { diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionOperationHandler.cs index 39549df1..057147b3 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmActionOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; @@ -28,7 +29,7 @@ public EdmActionOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Post; + public override HttpMethod OperationType => HttpMethod.Post; /// protected override void SetBasicInfo(OpenApiOperation operation) diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionImportOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionImportOperationHandler.cs index 94522cb9..50ec9a9f 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionImportOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionImportOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; @@ -25,7 +26,7 @@ public EdmFunctionImportOperationHandler(OpenApiDocument document) : base(docume } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; /// protected override void SetParameters(OpenApiOperation operation) diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionOperationHandler.cs index 559663eb..802ccbbf 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmFunctionOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Models; @@ -26,7 +27,7 @@ public EdmFunctionOperationHandler(OpenApiDocument document):base(document) } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; /// /// Gets the Edm Function. diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationImportOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationImportOperationHandler.cs index 532c38e2..d158e065 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationImportOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationImportOperationHandler.cs @@ -141,6 +141,8 @@ protected override void SetTags(OpenApiOperation operation) var tag = CreateTag(EdmOperationImport); tag.Extensions.Add(Constants.xMsTocType, new OpenApiAny("container")); Context.AppendTag(tag); + + operation.Tags ??= new HashSet(); operation.Tags.Add(new OpenApiTagReference(tag.Name, _document)); base.SetTags(operation); diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs index cc214850..cfc18619 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EdmOperationOperationHandler.cs @@ -154,6 +154,7 @@ protected override void SetTags(OpenApiOperation operation) Name = tagName, }; tag.Extensions.Add(Constants.xMsTocType, new OpenApiAny("container")); + operation.Tags ??= new HashSet(); operation.Tags.Add(new OpenApiTagReference(tag.Name, _document)); Context.AppendTag(tag); diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EntityDeleteOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EntityDeleteOperationHandler.cs index 343e8f99..8b2091f0 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EntityDeleteOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EntityDeleteOperationHandler.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; @@ -29,7 +30,7 @@ public EntityDeleteOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Delete; + public override HttpMethod OperationType => HttpMethod.Delete; private DeleteRestrictionsType _deleteRestrictions; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EntityGetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EntityGetOperationHandler.cs index eca54745..224c3833 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EntityGetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EntityGetOperationHandler.cs @@ -13,6 +13,7 @@ using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.Models.Interfaces; +using System.Net.Http; namespace Microsoft.OpenApi.OData.Operation { @@ -32,7 +33,7 @@ public EntityGetOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; private ReadRestrictionsType _readRestrictions; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EntityPatchOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EntityPatchOperationHandler.cs index b99f6d55..aa003143 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EntityPatchOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EntityPatchOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OpenApi.Models; namespace Microsoft.OpenApi.OData.Operation @@ -23,6 +24,6 @@ public EntityPatchOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Patch; + public override HttpMethod OperationType => HttpMethod.Patch; } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EntityPutOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EntityPutOperationHandler.cs index 7cb79f95..be418dbd 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EntityPutOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EntityPutOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OpenApi.Models; namespace Microsoft.OpenApi.OData.Operation @@ -23,6 +24,6 @@ public EntityPutOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Put; + public override HttpMethod OperationType => HttpMethod.Put; } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetGetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetGetOperationHandler.cs index e4d4067c..9dba9d97 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetGetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetGetOperationHandler.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System.Linq; +using System.Net.Http; using System.Text.Json.Nodes; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; @@ -33,7 +34,7 @@ public EntitySetGetOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; private ReadRestrictionsType _readRestrictions; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetOperationHandler.cs index fb8bb6d2..4719ddee 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetOperationHandler.cs @@ -10,6 +10,7 @@ using Microsoft.OpenApi.OData.Common; using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Vocabulary.Core; +using System.Collections.Generic; namespace Microsoft.OpenApi.OData.Operation { @@ -46,7 +47,7 @@ protected override void Initialize(ODataContext context, ODataPath path) protected override void SetTags(OpenApiOperation operation) { var tagName = EntitySet.Name + "." + EntitySet.EntityType.Name; - + operation.Tags ??= new HashSet(); operation.Tags.Add(new OpenApiTagReference(tagName, _document)); Context.AddExtensionToTag(tagName, Constants.xMsTocType, new OpenApiAny("page"), () => new OpenApiTag() diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetPostOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetPostOperationHandler.cs index 4167d7d3..046ba838 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetPostOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EntitySetPostOperationHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -33,7 +34,7 @@ public EntitySetPostOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Post; + public override HttpMethod OperationType => HttpMethod.Post; private InsertRestrictionsType _insertRestrictions; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/EntityUpdateOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/EntityUpdateOperationHandler.cs index 01568a1b..a34d6d9f 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/EntityUpdateOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/EntityUpdateOperationHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -60,7 +61,7 @@ protected override void SetBasicInfo(OpenApiOperation operation) if (Context.Settings.EnableOperationId) { string typeName = entityType.Name; - string prefix = OperationType == OperationType.Patch ? "Update" : "Set"; + string prefix = OperationType == HttpMethod.Patch ? "Update" : "Set"; string operationName = $"{prefix}{ Utils.UpperFirstChar(typeName)}"; if (keySegment.IsAlternateKey) { diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/IOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/IOperationHandler.cs index cd9d807d..1faef29a 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/IOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/IOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Edm; @@ -16,7 +17,7 @@ internal interface IOperationHandler /// /// The operation type. /// - OperationType OperationType { get; } + HttpMethod OperationType { get; } /// /// Create the . diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/IOperationHandlerProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/IOperationHandlerProvider.cs index 0c311836..be07c065 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/IOperationHandlerProvider.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/IOperationHandlerProvider.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Edm; @@ -20,6 +21,6 @@ internal interface IOperationHandlerProvider /// The operation type. /// The Open API document to use to lookup references. /// The corresponding . - IOperationHandler GetHandler(ODataPathKind pathKind, OperationType operationType, OpenApiDocument document); + IOperationHandler GetHandler(ODataPathKind pathKind, HttpMethod operationType, OpenApiDocument document); } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityDeleteOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityDeleteOperationHandler.cs index fc71789a..af94ff02 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityDeleteOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityDeleteOperationHandler.cs @@ -5,6 +5,7 @@ using Microsoft.OpenApi.OData.Generator; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; using System.Linq; +using System.Net.Http; namespace Microsoft.OpenApi.OData.Operation { @@ -19,7 +20,7 @@ public MediaEntityDeleteOperationHandler(OpenApiDocument document) : base(docume } /// - public override OperationType OperationType => OperationType.Delete; + public override HttpMethod OperationType => HttpMethod.Delete; private DeleteRestrictionsType _deleteRestrictions; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityGetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityGetOperationHandler.cs index 60a95ccd..1f6a695b 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityGetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityGetOperationHandler.cs @@ -11,6 +11,7 @@ using Microsoft.OpenApi.OData.Generator; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; using System.Linq; +using System.Net.Http; namespace Microsoft.OpenApi.OData.Operation { @@ -28,7 +29,7 @@ public MediaEntityGetOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; private ReadRestrictionsType _readRestrictions = null; protected override void Initialize(ODataContext context, ODataPath path) diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityOperationalHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityOperationalHandler.cs index 422c2256..488046d6 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityOperationalHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityOperationalHandler.cs @@ -96,6 +96,8 @@ protected override void SetTags(OpenApiOperation operation) { Name = tagIdentifier }); + + operation.Tags ??= new HashSet(); operation.Tags.Add(new OpenApiTagReference(tagIdentifier, _document)); } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityPutOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityPutOperationHandler.cs index a1b9649a..0fde994a 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityPutOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/MediaEntityPutOperationHandler.cs @@ -5,6 +5,7 @@ using System; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Vocabularies; using Microsoft.OpenApi.Models; @@ -30,7 +31,7 @@ public MediaEntityPutOperationHandler(OpenApiDocument document):base(document) } /// - public override OperationType OperationType => OperationType.Put; + public override HttpMethod OperationType => HttpMethod.Put; private UpdateRestrictionsType _updateRestrictions = null; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/MetadataGetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/MetadataGetOperationHandler.cs index 9cba74f5..4ec24a1e 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/MetadataGetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/MetadataGetOperationHandler.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System.Collections.Generic; +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; @@ -23,7 +24,7 @@ public MetadataGetOperationHandler(OpenApiDocument document):base(document) } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; /// protected override void SetBasicInfo(OpenApiOperation operation) diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyDeleteOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyDeleteOperationHandler.cs index 864c02ca..2bedd562 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyDeleteOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyDeleteOperationHandler.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System.Linq; +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; using Microsoft.OpenApi.OData.Edm; @@ -28,7 +29,7 @@ public NavigationPropertyDeleteOperationHandler(OpenApiDocument document):base(d } /// - public override OperationType OperationType => OperationType.Delete; + public override HttpMethod OperationType => HttpMethod.Delete; private DeleteRestrictionsType _deleteRestriction; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyGetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyGetOperationHandler.cs index 6ca66c76..0d01c013 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyGetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyGetOperationHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text.Json.Nodes; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; @@ -34,7 +35,7 @@ public NavigationPropertyGetOperationHandler(OpenApiDocument document) : base(do } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; private ReadRestrictionsType _readRestriction; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyOperationHandler.cs index 240a6e2b..445dd407 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyOperationHandler.cs @@ -99,6 +99,7 @@ protected override void SetTags(OpenApiOperation operation) { Name = name }); + operation.Tags ??= new HashSet(); operation.Tags.Add(new OpenApiTagReference(name, _document)); base.SetTags(operation); diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPatchOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPatchOperationHandler.cs index 46eda3a6..98218ea4 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPatchOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPatchOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OpenApi.Models; namespace Microsoft.OpenApi.OData.Operation @@ -23,6 +24,6 @@ public NavigationPropertyPatchOperationHandler(OpenApiDocument document):base(do } /// - public override OperationType OperationType => OperationType.Patch; + public override HttpMethod OperationType => HttpMethod.Patch; } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPostOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPostOperationHandler.cs index 2c4d1274..065fcfe4 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPostOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPostOperationHandler.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; @@ -29,7 +30,7 @@ public NavigationPropertyPostOperationHandler(OpenApiDocument document):base(doc } /// - public override OperationType OperationType => OperationType.Post; + public override HttpMethod OperationType => HttpMethod.Post; private InsertRestrictionsType _insertRestriction; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPutOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPutOperationHandler.cs index 09699293..62ed631a 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPutOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyPutOperationHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OpenApi.Models; namespace Microsoft.OpenApi.OData.Operation @@ -23,6 +24,6 @@ public NavigationPropertyPutOperationHandler(OpenApiDocument document) : base(do } /// - public override OperationType OperationType => OperationType.Put; + public override HttpMethod OperationType => HttpMethod.Put; } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyUpdateOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyUpdateOperationHandler.cs index 9daf7e5f..3549480a 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyUpdateOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/NavigationPropertyUpdateOperationHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; @@ -49,7 +50,7 @@ protected override void SetBasicInfo(OpenApiOperation operation) // OperationId if (Context.Settings.EnableOperationId) { - string prefix = OperationType == OperationType.Patch ? "Update" : "Set"; + string prefix = OperationType == HttpMethod.Patch ? "Update" : "Set"; operation.OperationId = GetOperationId(prefix); } diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/ODataTypeCastGetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/ODataTypeCastGetOperationHandler.cs index c51adf32..4b655508 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/ODataTypeCastGetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/ODataTypeCastGetOperationHandler.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text.Json.Nodes; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Vocabularies; @@ -35,7 +36,7 @@ public ODataTypeCastGetOperationHandler(OpenApiDocument document):base(document) } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; /// /// Gets/sets the segment before cast. @@ -237,6 +238,7 @@ protected override void SetResponses(OpenApiOperation operation) protected override void SetTags(OpenApiOperation operation) { string tagName = null; + operation.Tags ??= new HashSet(); if (SecondLastSegment is ODataNavigationPropertySegment || isIndexedCollValuedNavProp) { diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs index 5d934cb4..4f27692c 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OpenApi.MicrosoftExtensions; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -34,7 +35,7 @@ protected OperationHandler(OpenApiDocument document) _document = document; } /// - public abstract OperationType OperationType { get; } + public abstract HttpMethod OperationType { get; } protected IDictionary> ParameterMappings; @@ -289,13 +290,13 @@ protected virtual void SetCustomLinkRelType() { if (Context.Settings.CustomHttpMethodLinkRelMapping != null) { - LinkRelKey? key = OperationType switch + LinkRelKey? key = OperationType.ToString().ToLowerInvariant() switch { - OperationType.Get => Path.LastSegment?.Kind == ODataSegmentKind.Key ? LinkRelKey.ReadByKey : LinkRelKey.List, - OperationType.Post => LinkRelKey.Create, - OperationType.Patch => LinkRelKey.Update, - OperationType.Put => LinkRelKey.Update, - OperationType.Delete => LinkRelKey.Delete, + "get" => Path.LastSegment?.Kind == ODataSegmentKind.Key ? LinkRelKey.ReadByKey : LinkRelKey.List, + "post" => LinkRelKey.Create, + "patch" => LinkRelKey.Update, + "put" => LinkRelKey.Update, + "delete" => LinkRelKey.Delete, _ => null, }; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandlerProvider.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandlerProvider.cs index 92c4f131..9f65fedf 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandlerProvider.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandlerProvider.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System.Collections.Generic; +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Edm; @@ -15,65 +16,65 @@ namespace Microsoft.OpenApi.OData.Operation internal class OperationHandlerProvider : IOperationHandlerProvider { /// - public IOperationHandler GetHandler(ODataPathKind pathKind, OperationType operationType, OpenApiDocument document) + public IOperationHandler GetHandler(ODataPathKind pathKind, HttpMethod operationType, OpenApiDocument document) { - return (pathKind, operationType) switch + return (pathKind, operationType.ToString().ToLowerInvariant()) switch { // entity set (Get/Post) - (ODataPathKind.EntitySet, OperationType.Get) => new EntitySetGetOperationHandler(document), - (ODataPathKind.EntitySet, OperationType.Post) => new EntitySetPostOperationHandler(document), + (ODataPathKind.EntitySet, "get") => new EntitySetGetOperationHandler(document), + (ODataPathKind.EntitySet, "post") => new EntitySetPostOperationHandler(document), // entity (Get/Patch/Put/Delete) - (ODataPathKind.Entity, OperationType.Get) => new EntityGetOperationHandler(document), - (ODataPathKind.Entity, OperationType.Patch) => new EntityPatchOperationHandler(document), - (ODataPathKind.Entity, OperationType.Put) => new EntityPutOperationHandler(document), - (ODataPathKind.Entity, OperationType.Delete) => new EntityDeleteOperationHandler(document), + (ODataPathKind.Entity, "get") => new EntityGetOperationHandler(document), + (ODataPathKind.Entity, "patch") => new EntityPatchOperationHandler(document), + (ODataPathKind.Entity, "put") => new EntityPutOperationHandler(document), + (ODataPathKind.Entity, "delete") => new EntityDeleteOperationHandler(document), // singleton (Get/Patch) - (ODataPathKind.Singleton, OperationType.Get) => new SingletonGetOperationHandler(document), - (ODataPathKind.Singleton, OperationType.Patch) => new SingletonPatchOperationHandler(document), + (ODataPathKind.Singleton, "get") => new SingletonGetOperationHandler(document), + (ODataPathKind.Singleton, "patch") => new SingletonPatchOperationHandler(document), // edm operation (Get|Post) - (ODataPathKind.Operation, OperationType.Get) => new EdmFunctionOperationHandler(document), - (ODataPathKind.Operation, OperationType.Post) => new EdmActionOperationHandler(document), + (ODataPathKind.Operation, "get") => new EdmFunctionOperationHandler(document), + (ODataPathKind.Operation, "post") => new EdmActionOperationHandler(document), // edm operation import (Get|Post) - (ODataPathKind.OperationImport, OperationType.Get) => new EdmFunctionImportOperationHandler(document), - (ODataPathKind.OperationImport, OperationType.Post) => new EdmActionImportOperationHandler(document), + (ODataPathKind.OperationImport, "get") => new EdmFunctionImportOperationHandler(document), + (ODataPathKind.OperationImport, "post") => new EdmActionImportOperationHandler(document), // navigation property (Get/Patch/Put/Post/Delete) - (ODataPathKind.NavigationProperty, OperationType.Get) => new NavigationPropertyGetOperationHandler(document), - (ODataPathKind.NavigationProperty, OperationType.Patch) => new NavigationPropertyPatchOperationHandler(document), - (ODataPathKind.NavigationProperty, OperationType.Put) => new NavigationPropertyPutOperationHandler(document), - (ODataPathKind.NavigationProperty, OperationType.Post) => new NavigationPropertyPostOperationHandler(document), - (ODataPathKind.NavigationProperty, OperationType.Delete) => new NavigationPropertyDeleteOperationHandler(document), + (ODataPathKind.NavigationProperty, "get") => new NavigationPropertyGetOperationHandler(document), + (ODataPathKind.NavigationProperty, "patch") => new NavigationPropertyPatchOperationHandler(document), + (ODataPathKind.NavigationProperty, "put") => new NavigationPropertyPutOperationHandler(document), + (ODataPathKind.NavigationProperty, "post") => new NavigationPropertyPostOperationHandler(document), + (ODataPathKind.NavigationProperty, "delete") => new NavigationPropertyDeleteOperationHandler(document), // navigation property ref (Get/Post/Put/Delete) - (ODataPathKind.Ref, OperationType.Get) => new RefGetOperationHandler(document), - (ODataPathKind.Ref, OperationType.Put) => new RefPutOperationHandler(document), - (ODataPathKind.Ref, OperationType.Post) => new RefPostOperationHandler(document), - (ODataPathKind.Ref, OperationType.Delete) => new RefDeleteOperationHandler(document), + (ODataPathKind.Ref, "get") => new RefGetOperationHandler(document), + (ODataPathKind.Ref, "put") => new RefPutOperationHandler(document), + (ODataPathKind.Ref, "post") => new RefPostOperationHandler(document), + (ODataPathKind.Ref, "delete") => new RefDeleteOperationHandler(document), // media entity operation (Get|Put|Delete) - (ODataPathKind.MediaEntity, OperationType.Get) => new MediaEntityGetOperationHandler(document), - (ODataPathKind.MediaEntity, OperationType.Put) => new MediaEntityPutOperationHandler(document), - (ODataPathKind.MediaEntity, OperationType.Delete) => new MediaEntityDeleteOperationHandler(document), + (ODataPathKind.MediaEntity, "get") => new MediaEntityGetOperationHandler(document), + (ODataPathKind.MediaEntity, "put") => new MediaEntityPutOperationHandler(document), + (ODataPathKind.MediaEntity, "delete") => new MediaEntityDeleteOperationHandler(document), // $metadata operation (Get) - (ODataPathKind.Metadata, OperationType.Get) => new MetadataGetOperationHandler(document), + (ODataPathKind.Metadata, "get") => new MetadataGetOperationHandler(document), // $count operation (Get) - (ODataPathKind.DollarCount, OperationType.Get) => new DollarCountGetOperationHandler(document), + (ODataPathKind.DollarCount, "get") => new DollarCountGetOperationHandler(document), // .../namespace.typename (cast, get) - (ODataPathKind.TypeCast, OperationType.Get) => new ODataTypeCastGetOperationHandler(document), + (ODataPathKind.TypeCast, "get") => new ODataTypeCastGetOperationHandler(document), // .../entity/propertyOfComplexType (Get/Patch/Put/Delete) - (ODataPathKind.ComplexProperty, OperationType.Get) => new ComplexPropertyGetOperationHandler(document), - (ODataPathKind.ComplexProperty, OperationType.Patch) => new ComplexPropertyPatchOperationHandler(document), - (ODataPathKind.ComplexProperty, OperationType.Put) => new ComplexPropertyPutOperationHandler(document), - (ODataPathKind.ComplexProperty, OperationType.Post) => new ComplexPropertyPostOperationHandler(document), + (ODataPathKind.ComplexProperty, "get") => new ComplexPropertyGetOperationHandler(document), + (ODataPathKind.ComplexProperty, "patch") => new ComplexPropertyPatchOperationHandler(document), + (ODataPathKind.ComplexProperty, "put") => new ComplexPropertyPutOperationHandler(document), + (ODataPathKind.ComplexProperty, "post") => new ComplexPropertyPostOperationHandler(document), (_, _) => null, }; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/RefDeleteOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/RefDeleteOperationHandler.cs index 7cb17255..5211b865 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/RefDeleteOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/RefDeleteOperationHandler.cs @@ -10,6 +10,7 @@ using Microsoft.OpenApi.OData.Generator; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; using System.Linq; +using System.Net.Http; namespace Microsoft.OpenApi.OData.Operation { @@ -27,7 +28,7 @@ public RefDeleteOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Delete; + public override HttpMethod OperationType => HttpMethod.Delete; private DeleteRestrictionsType _deleteRestriction; /// diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/RefGetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/RefGetOperationHandler.cs index 1dc242b5..6f413819 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/RefGetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/RefGetOperationHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text.Json.Nodes; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; @@ -32,7 +33,7 @@ public RefGetOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; private ReadRestrictionsType _readRestriction; /// diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/RefPostOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/RefPostOperationHandler.cs index faa3b99d..04c82e54 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/RefPostOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/RefPostOperationHandler.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System.Linq; +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.OData.Common; @@ -27,7 +28,7 @@ public RefPostOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Post; + public override HttpMethod OperationType => HttpMethod.Post; private InsertRestrictionsType _insertRestriction; /// diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/RefPutOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/RefPutOperationHandler.cs index fb4d7b19..984be238 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/RefPutOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/RefPutOperationHandler.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System.Linq; +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.References; using Microsoft.OpenApi.OData.Common; @@ -27,7 +28,7 @@ public RefPutOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Patch; + public override HttpMethod OperationType => HttpMethod.Patch; private UpdateRestrictionsType _updateRestriction; /// diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonGetOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonGetOperationHandler.cs index 9b8b55a9..76e9232c 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonGetOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonGetOperationHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -32,7 +33,7 @@ public SingletonGetOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Get; + public override HttpMethod OperationType => HttpMethod.Get; private ReadRestrictionsType _readRestrictions; diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonOperationHandler.cs index dcd33ef1..7e8baa6b 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonOperationHandler.cs @@ -10,6 +10,7 @@ using Microsoft.OpenApi.OData.Common; using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Vocabulary.Core; +using System.Collections.Generic; namespace Microsoft.OpenApi.OData.Operation { @@ -53,7 +54,7 @@ protected override void SetTags(OpenApiOperation operation) { Name = tagName }); - + operation.Tags ??= new HashSet(); operation.Tags.Add(new OpenApiTagReference(tagName, _document)); // Call base.SetTags() at the end of this method. diff --git a/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonPatchOperationHandler.cs b/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonPatchOperationHandler.cs index e8cb4b94..4342f8f6 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonPatchOperationHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Operation/SingletonPatchOperationHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models.Interfaces; @@ -32,7 +33,7 @@ public SingletonPatchOperationHandler(OpenApiDocument document) : base(document) } /// - public override OperationType OperationType => OperationType.Patch; + public override HttpMethod OperationType => HttpMethod.Patch; private UpdateRestrictionsType _updateRestrictions; diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/ComplexPropertyItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/ComplexPropertyItemHandler.cs index a3397eed..f027d2f1 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/ComplexPropertyItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/ComplexPropertyItemHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; @@ -47,7 +48,7 @@ public void AddReadOperation(OpenApiPathItem item) if ((Context.Settings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths && isReadable) || !Context.Settings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } } @@ -63,7 +64,7 @@ public void AddInsertOperation(OpenApiPathItem item) if ((Context.Settings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths && isInsertable) || !Context.Settings.RequireRestrictionAnnotationsToGenerateComplexPropertyPaths) { - AddOperation(item, OperationType.Post); + AddOperation(item, HttpMethod.Post); } } } @@ -80,16 +81,16 @@ public void AddUpdateOperation(OpenApiPathItem item) { if (updateRestrictions?.IsUpdateMethodPutAndPatch == true) { - AddOperation(item, OperationType.Put); - AddOperation(item, OperationType.Patch); + AddOperation(item, HttpMethod.Put); + AddOperation(item, HttpMethod.Patch); } else if (updateRestrictions?.IsUpdateMethodPut == true) { - AddOperation(item, OperationType.Put); + AddOperation(item, HttpMethod.Put); } else { - AddOperation(item, OperationType.Patch); + AddOperation(item, HttpMethod.Patch); } } } diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/DollarCountPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/DollarCountPathItemHandler.cs index f1c124d1..c68d044d 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/DollarCountPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/DollarCountPathItemHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Edm; @@ -27,7 +28,7 @@ public DollarCountPathItemHandler(OpenApiDocument document) : base(document) /// protected override void SetOperations(OpenApiPathItem item) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } /// protected override void SetBasicInfo(OpenApiPathItem pathItem) diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/EntityPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/EntityPathItemHandler.cs index 02aef743..9b394158 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/EntityPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/EntityPathItemHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; @@ -39,7 +40,7 @@ protected override void SetOperations(OpenApiPathItem item) (readRestrictions.ReadByKeyRestrictions != null && readRestrictions.ReadByKeyRestrictions.IsReadable)) { // If we don't have Read by key read restriction, we should check the set read restrction. - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } UpdateRestrictionsType updateRestrictions = Context.Model.GetRecord(TargetPath, CapabilitiesConstants.UpdateRestrictions); @@ -50,16 +51,16 @@ protected override void SetOperations(OpenApiPathItem item) { if (updateRestrictions?.IsUpdateMethodPutAndPatch == true) { - AddOperation(item, OperationType.Put); - AddOperation(item, OperationType.Patch); + AddOperation(item, HttpMethod.Put); + AddOperation(item, HttpMethod.Patch); } else if (updateRestrictions?.IsUpdateMethodPut == true) { - AddOperation(item, OperationType.Put); + AddOperation(item, HttpMethod.Put); } else { - AddOperation(item, OperationType.Patch); + AddOperation(item, HttpMethod.Patch); } } @@ -69,7 +70,7 @@ protected override void SetOperations(OpenApiPathItem item) deleteRestrictions ??= entityDeleteRestrictions; if (deleteRestrictions?.IsDeletable ?? true) { - AddOperation(item, OperationType.Delete); + AddOperation(item, HttpMethod.Delete); } } diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/EntitySetPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/EntitySetPathItemHandler.cs index 57d11136..0240a0fe 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/EntitySetPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/EntitySetPathItemHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; @@ -41,7 +42,7 @@ protected override void SetOperations(OpenApiPathItem item) readRestrictions ??= entityReadRestrictions; if (readRestrictions?.IsReadable ?? true) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } InsertRestrictionsType insertRestrictions = Context.Model.GetRecord(TargetPath, CapabilitiesConstants.InsertRestrictions); @@ -50,7 +51,7 @@ protected override void SetOperations(OpenApiPathItem item) insertRestrictions ??= entityInsertRestrictions; if (insertRestrictions?.IsInsertable ?? true) { - AddOperation(item, OperationType.Post); + AddOperation(item, HttpMethod.Post); } } diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/MediaEntityPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/MediaEntityPathItemHandler.cs index 48613a57..48bf11f0 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/MediaEntityPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/MediaEntityPathItemHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Edm; @@ -48,7 +49,7 @@ protected override void SetOperations(OpenApiPathItem item) (readRestrictions.ReadByKeyRestrictions == null && readRestrictions.IsReadable) || (readRestrictions.ReadByKeyRestrictions != null && readRestrictions.ReadByKeyRestrictions.IsReadable)) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } UpdateRestrictionsType updateRestrictions = Context.Model.GetRecord(TargetPath, CapabilitiesConstants.UpdateRestrictions); @@ -58,7 +59,7 @@ protected override void SetOperations(OpenApiPathItem item) updateRestrictions ??= navSourceUpdateRestrictions; if (updateRestrictions?.IsUpdatable ?? true) { - AddOperation(item, OperationType.Put); + AddOperation(item, HttpMethod.Put); } DeleteRestrictionsType deleteRestrictions = Context.Model.GetRecord(TargetPath, CapabilitiesConstants.DeleteRestrictions); @@ -68,7 +69,7 @@ protected override void SetOperations(OpenApiPathItem item) deleteRestrictions ??= navSourceDeleteRestrictions; if (deleteRestrictions?.IsDeletable ?? true) { - AddOperation(item, OperationType.Delete); + AddOperation(item, HttpMethod.Delete); } } diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/MetadataPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/MetadataPathItemHandler.cs index 28d974e6..5862ad1c 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/MetadataPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/MetadataPathItemHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Edm; @@ -27,7 +28,7 @@ public MetadataPathItemHandler(OpenApiDocument document) : base(document) /// protected override void SetOperations(OpenApiPathItem item) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } /// protected override void SetBasicInfo(OpenApiPathItem pathItem) diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs index 890f24ee..21306c0d 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/NavigationPropertyPathItemHandler.cs @@ -14,6 +14,7 @@ using Microsoft.OData.Edm.Vocabularies; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; using System.Text.Json.Nodes; +using System.Net.Http; namespace Microsoft.OpenApi.OData.PathItem { @@ -126,7 +127,7 @@ protected override void SetOperations(OpenApiPathItem item) ((entityInsertRestrictions?.IsInsertable ?? true) && (navPropInsertRestrictions?.IsInsertable ?? true))) { - AddOperation(item, OperationType.Post); + AddOperation(item, HttpMethod.Post); } } } @@ -152,7 +153,7 @@ protected override void SetOperations(OpenApiPathItem item) { if (navPropInsertRestrictions?.Insertable ?? false) { - AddOperation(item, OperationType.Post); + AddOperation(item, HttpMethod.Post); } } } @@ -181,7 +182,7 @@ private void AddGetOperation(OpenApiPathItem item, NavigationPropertyRestriction bool isReadableDefault = navPropReadRestriction == null && entityReadRestriction == null; if (isReadableDefault) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); return; } @@ -193,7 +194,7 @@ private void AddGetOperation(OpenApiPathItem item, NavigationPropertyRestriction if ((navPropReadRestriction?.ReadByKeyRestrictions?.IsReadable ?? true) && (entityReadRestriction?.IsReadable ?? true)) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } } else @@ -201,7 +202,7 @@ private void AddGetOperation(OpenApiPathItem item, NavigationPropertyRestriction if ((navPropReadRestriction?.IsReadable ?? true) && (entityReadRestriction?.IsReadable ?? true)) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } } } @@ -211,7 +212,7 @@ private void AddGetOperation(OpenApiPathItem item, NavigationPropertyRestriction if ((navPropReadRestriction?.IsReadable ?? true) && (entityReadRestriction?.IsReadable ?? true)) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } } } @@ -238,13 +239,13 @@ private void AddDeleteOperation(OpenApiPathItem item, NavigationPropertyRestrict if (NavigationProperty.ContainsTarget && isDeletable) { - AddOperation(item, OperationType.Delete); + AddOperation(item, HttpMethod.Delete); } else if (navPropDeleteRestriction?.Deletable ?? false) { // Add delete operation for non-contained nav. props only if explicitly set to true via annotation // Note: Use Deletable and NOT IsDeletable - AddOperation(item, OperationType.Delete); + AddOperation(item, HttpMethod.Delete); } return; @@ -256,16 +257,16 @@ private void AddUpdateOperation(OpenApiPathItem item, UpdateRestrictionsType upd { if (updateRestrictionsType?.IsUpdateMethodPutAndPatch == true) { - AddOperation(item, OperationType.Put); - AddOperation(item, OperationType.Patch); + AddOperation(item, HttpMethod.Put); + AddOperation(item, HttpMethod.Patch); } else if (updateRestrictionsType?.IsUpdateMethodPut == true) { - AddOperation(item, OperationType.Put); + AddOperation(item, HttpMethod.Put); } else { - AddOperation(item, OperationType.Patch); + AddOperation(item, HttpMethod.Patch); } } diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/ODataTypeCastPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/ODataTypeCastPathItemHandler.cs index 13f1b406..38e4e224 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/ODataTypeCastPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/ODataTypeCastPathItemHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; @@ -29,7 +30,7 @@ public ODataTypeCastPathItemHandler(OpenApiDocument document) : base(document) /// protected override void SetOperations(OpenApiPathItem item) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } /// protected override void Initialize(ODataContext context, ODataPath path) diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/OperationImportPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/OperationImportPathItemHandler.cs index e26511d5..2d3eab0a 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/OperationImportPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/OperationImportPathItemHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; @@ -41,7 +42,7 @@ protected override void SetOperations(OpenApiPathItem item) // resource path of the action import prepended with a forward slash, and whose value is a Path // Item Object containing the keyword post with an Operation Object as value that describes // how to invoke the action import. - AddOperation(item, OperationType.Post); + AddOperation(item, HttpMethod.Post); } else { @@ -57,7 +58,7 @@ protected override void SetOperations(OpenApiPathItem item) readRestrictions ??= operationReadRestrictions; if (readRestrictions?.IsReadable ?? true) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } } } diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/OperationPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/OperationPathItemHandler.cs index 775816da..89927192 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/OperationPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/OperationPathItemHandler.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text.Json.Nodes; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; @@ -42,13 +43,13 @@ protected override void SetOperations(OpenApiPathItem item) { // The Path Item Object for a bound action contains the keyword post, // The value of the operation keyword is an Operation Object that describes how to invoke the action. - AddOperation(item, OperationType.Post); + AddOperation(item, HttpMethod.Post); } else { // The Path Item Object for a bound function contains the keyword get, // The value of the operation keyword is an Operation Object that describes how to invoke the function. - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } } diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/PathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/PathItemHandler.cs index e71b6d37..97e9c880 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/PathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/PathItemHandler.cs @@ -10,6 +10,7 @@ using Microsoft.OpenApi.OData.Operation; using Microsoft.OpenApi.OData.Properties; using System; +using System.Net.Http; namespace Microsoft.OpenApi.OData.PathItem { @@ -111,7 +112,7 @@ protected virtual void SetExtensions(OpenApiPathItem item) /// /// The path item. /// The operation type. - protected virtual void AddOperation(OpenApiPathItem item, OperationType operationType) + protected virtual void AddOperation(OpenApiPathItem item, HttpMethod operationType) { string httpMethod = operationType.ToString(); if (!Path.SupportHttpMethod(httpMethod)) diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/RefPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/RefPathItemHandler.cs index 6b245092..fffef601 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/RefPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/RefPathItemHandler.cs @@ -11,6 +11,7 @@ using Microsoft.OpenApi.OData.Edm; using Microsoft.OData.Edm.Vocabularies; using Microsoft.OpenApi.OData.Vocabulary.Capabilities; +using System.Net.Http; namespace Microsoft.OpenApi.OData.PathItem { @@ -105,7 +106,7 @@ private void AddDeleteOperation(OpenApiPathItem item, NavigationPropertyRestrict deleteRestrictions ??= restriction?.DeleteRestrictions; if (deleteRestrictions?.IsDeletable ?? true) { - AddOperation(item, OperationType.Delete); + AddOperation(item, HttpMethod.Delete); } } @@ -116,7 +117,7 @@ private void AddReadOperation(OpenApiPathItem item, NavigationPropertyRestrictio readRestrictions ??= restriction?.ReadRestrictions; if (readRestrictions?.IsReadable ?? true) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } } @@ -127,7 +128,7 @@ private void AddInsertOperation(OpenApiPathItem item, NavigationPropertyRestrict insertRestrictions ??= restriction?.InsertRestrictions; if (insertRestrictions?.IsInsertable ?? true) { - AddOperation(item, OperationType.Post); + AddOperation(item, HttpMethod.Post); } } @@ -138,7 +139,7 @@ private void AddUpdateOperation(OpenApiPathItem item, NavigationPropertyRestrict updateRestrictions ??= restriction?.UpdateRestrictions; if (updateRestrictions?.IsUpdatable ?? true) { - AddOperation(item, OperationType.Put); + AddOperation(item, HttpMethod.Put); } } diff --git a/src/Microsoft.OpenApi.OData.Reader/PathItem/SingletonPathItemHandler.cs b/src/Microsoft.OpenApi.OData.Reader/PathItem/SingletonPathItemHandler.cs index 5715c8cb..e288e1ba 100644 --- a/src/Microsoft.OpenApi.OData.Reader/PathItem/SingletonPathItemHandler.cs +++ b/src/Microsoft.OpenApi.OData.Reader/PathItem/SingletonPathItemHandler.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Common; @@ -42,7 +43,7 @@ protected override void SetOperations(OpenApiPathItem item) readRestrictions ??= singletonReadRestrictions; if (readRestrictions?.IsReadable ?? true) { - AddOperation(item, OperationType.Get); + AddOperation(item, HttpMethod.Get); } // Update a singleton @@ -52,7 +53,7 @@ protected override void SetOperations(OpenApiPathItem item) updateRestrictions ??= singletonUpdateRestrictions; if (updateRestrictions?.IsUpdatable ?? true) { - AddOperation(item, OperationType.Patch); + AddOperation(item, HttpMethod.Patch); } } diff --git a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Capabilities/UpdateRestrictionsType.cs b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Capabilities/UpdateRestrictionsType.cs index ff073e39..724d2ddc 100644 --- a/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Capabilities/UpdateRestrictionsType.cs +++ b/src/Microsoft.OpenApi.OData.Reader/Vocabulary/Capabilities/UpdateRestrictionsType.cs @@ -16,7 +16,7 @@ namespace Microsoft.OpenApi.OData.Vocabulary.Capabilities /// Enumerates HTTP methods that can be used to update entities /// [Flags] - internal enum HttpMethod + internal enum HttpUpdateMethod { /// /// The HTTP PATCH Method @@ -48,13 +48,13 @@ internal class UpdateRestrictionsType : IRecord /// /// Gets the value indicating Entities can be inserted, updated, and deleted via a PATCH request with a delta payload. /// - public bool? DeltaUpdateSupported { get; private set; } - + public bool? DeltaUpdateSupported { get; private set; } + /// /// Gets the values indicating the HTTP Method (PUT and/or PATCH) for updating an entity. /// If null, PATCH should be supported and PUT MAY be supported. /// - public HttpMethod? UpdateMethod { get; private set; } + public HttpUpdateMethod? UpdateMethod { get; private set; } /// /// Gets the value indicating Members of collections can be updated via a PATCH request with a '/$filter(...)/$each' segment. @@ -128,24 +128,24 @@ public bool IsNonUpdatableNavigationProperty(string navigationPropertyPath) /// /// Tests whether the update method for the target has been explicitly specified as PUT /// - public bool IsUpdateMethodPut => UpdateMethod.HasValue && UpdateMethod.Value == HttpMethod.PUT; - - /// - /// Tests whether the update method for the target has been explicitly specified as PATCH and PUT - /// - public bool IsUpdateMethodPutAndPatch => UpdateMethod.HasValue && - (UpdateMethod.Value & (HttpMethod.PUT | HttpMethod.PATCH)) == (HttpMethod.PUT | HttpMethod.PATCH); - - /// - /// Lists the media types acceptable for the request content - /// - /// This is not an official OASIS standard property. + public bool IsUpdateMethodPut => UpdateMethod.HasValue && UpdateMethod.Value == HttpUpdateMethod.PUT; + + /// + /// Tests whether the update method for the target has been explicitly specified as PATCH and PUT + /// + public bool IsUpdateMethodPutAndPatch => UpdateMethod.HasValue && + (UpdateMethod.Value & (HttpUpdateMethod.PUT | HttpUpdateMethod.PATCH)) == (HttpUpdateMethod.PUT | HttpUpdateMethod.PATCH); + + /// + /// Lists the media types acceptable for the request content + /// + /// This is not an official OASIS standard property. public IList RequestContentTypes { get; private set; } - /// - /// Lists the media types acceptable for the response content - /// - /// This is not an official OASIS standard property. + /// + /// Lists the media types acceptable for the response content + /// + /// This is not an official OASIS standard property. public IList ResponseContentTypes { get; private set; } /// @@ -165,8 +165,8 @@ public void Initialize(IEdmRecordExpression record) // DeltaUpdateSupported DeltaUpdateSupported = record.GetBoolean("DeltaUpdateSupported"); - // UpdateMethod - UpdateMethod = record.GetEnum("UpdateMethod"); + // UpdateMethod + UpdateMethod = record.GetEnum("UpdateMethod"); // FilterSegmentSupported FilterSegmentSupported = record.GetBoolean("FilterSegmentSupported"); @@ -175,9 +175,9 @@ public void Initialize(IEdmRecordExpression record) TypecastSegmentSupported = record.GetBoolean("TypecastSegmentSupported"); // NonUpdatableNavigationProperties - NonUpdatableNavigationProperties = record.GetCollectionPropertyPath("NonUpdatableNavigationProperties"); - - // MaxLevels + NonUpdatableNavigationProperties = record.GetCollectionPropertyPath("NonUpdatableNavigationProperties"); + + // MaxLevels MaxLevels = record.GetInteger("MaxLevels"); // Permissions @@ -203,48 +203,48 @@ public void Initialize(IEdmRecordExpression record) // ResponseContentTypes ResponseContentTypes = record.GetCollection("ResponseContentTypes"); - } - - /// - /// Merges properties of the specified object into this instance if they are null. - /// + } + + /// + /// Merges properties of the specified object into this instance if they are null. + /// /// The object containing properties to merge. - public void MergePropertiesIfNull(UpdateRestrictionsType source) - { - if (source == null) - return; - - Updatable ??= source.Updatable; - - Upsertable ??= source.Upsertable; - - DeltaUpdateSupported ??= source.DeltaUpdateSupported; - - UpdateMethod ??= source.UpdateMethod; - - FilterSegmentSupported ??= source.FilterSegmentSupported; - - TypecastSegmentSupported ??= source.TypecastSegmentSupported; - - NonUpdatableNavigationProperties ??= source.NonUpdatableNavigationProperties; - - MaxLevels ??= source.MaxLevels; - - Permissions ??= source.Permissions; - - QueryOptions ??= source.QueryOptions; - - CustomHeaders ??= source.CustomHeaders; - - CustomQueryOptions ??= source.CustomQueryOptions; - - Description ??= source.Description; - - LongDescription ??= source.LongDescription; - - RequestContentTypes ??= source.RequestContentTypes; - - ResponseContentTypes ??= source.ResponseContentTypes; + public void MergePropertiesIfNull(UpdateRestrictionsType source) + { + if (source == null) + return; + + Updatable ??= source.Updatable; + + Upsertable ??= source.Upsertable; + + DeltaUpdateSupported ??= source.DeltaUpdateSupported; + + UpdateMethod ??= source.UpdateMethod; + + FilterSegmentSupported ??= source.FilterSegmentSupported; + + TypecastSegmentSupported ??= source.TypecastSegmentSupported; + + NonUpdatableNavigationProperties ??= source.NonUpdatableNavigationProperties; + + MaxLevels ??= source.MaxLevels; + + Permissions ??= source.Permissions; + + QueryOptions ??= source.QueryOptions; + + CustomHeaders ??= source.CustomHeaders; + + CustomQueryOptions ??= source.CustomQueryOptions; + + Description ??= source.Description; + + LongDescription ??= source.LongDescription; + + RequestContentTypes ??= source.RequestContentTypes; + + ResponseContentTypes ??= source.ResponseContentTypes; } } } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/EdmModelOpenApiExtensionsTest.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/EdmModelOpenApiExtensionsTest.cs index 9d22a50c..15eddb24 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/EdmModelOpenApiExtensionsTest.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/EdmModelOpenApiExtensionsTest.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using Microsoft.OData.Edm; using Microsoft.OpenApi.Extensions; +using Microsoft.OpenApi.Writers; using Xunit; using Xunit.Abstractions; @@ -178,7 +179,8 @@ private static async Task WriteEdmModelAsOpenApi(IEdmModel model, OpenAp Assert.NotNull(document); // guard MemoryStream stream = new(); - await document.SerializeAsync(stream, settings.OpenApiSpecVersion, target); + var writerSettings = new OpenApiWriterSettings(); + await document.SerializeAsync(stream, settings.OpenApiSpecVersion, target, writerSettings); await stream.FlushAsync(); stream.Position = 0; return await new StreamReader(stream).ReadToEndAsync(); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiDocumentGeneratorTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiDocumentGeneratorTests.cs index 251ef787..cadd8ca8 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiDocumentGeneratorTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiDocumentGeneratorTests.cs @@ -42,7 +42,7 @@ public void CreateDocumentReturnsForEmptyModel() Assert.NotNull(document.Components); Assert.Null(document.ExternalDocs); - Assert.Null(document.SecurityRequirements); + Assert.Null(document.Security); } } } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs index 23d8ceda..2a411cf6 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Generator/OpenApiSchemaGeneratorTests.cs @@ -978,9 +978,8 @@ public async Task CreatePropertySchemaWithComputedAnnotationReturnsCorrectSchema ""format"": ""duration"", ""description"": ""The length of the appointment, denoted in ISO8601 format."", ""pattern"": ""^-?P([0-9]+D)?(T([0-9]+H)?([0-9]+M)?([0-9]+([.][0-9]+)?S)?)?$"", - ""type"": ""string"", - ""readOnly"": true -}"), json)); + ""type"": ""string"" +}"), json)); // TODO FIXME after resolution of https://github.com/microsoft/OpenAPI.NET/issues/2272 } else { diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Microsoft.OpenAPI.OData.Reader.Tests.csproj b/test/Microsoft.OpenAPI.OData.Reader.Tests/Microsoft.OpenAPI.OData.Reader.Tests.csproj index a98f2155..75b54007 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Microsoft.OpenAPI.OData.Reader.Tests.csproj +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Microsoft.OpenAPI.OData.Reader.Tests.csproj @@ -88,7 +88,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/OperationHandlerProviderTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/OperationHandlerProviderTests.cs index 2e3f3289..c282de6d 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/OperationHandlerProviderTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/OperationHandlerProviderTests.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System; +using System.Net.Http; using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Edm; using Xunit; @@ -13,40 +14,40 @@ namespace Microsoft.OpenApi.OData.Operation.Tests public class OperationHandlerProviderTests { [Theory] - [InlineData(ODataPathKind.EntitySet, OperationType.Get, typeof(EntitySetGetOperationHandler))] - [InlineData(ODataPathKind.EntitySet, OperationType.Post, typeof(EntitySetPostOperationHandler))] - [InlineData(ODataPathKind.Entity, OperationType.Get, typeof(EntityGetOperationHandler))] - [InlineData(ODataPathKind.Entity, OperationType.Patch, typeof(EntityPatchOperationHandler))] - [InlineData(ODataPathKind.Entity, OperationType.Delete, typeof(EntityDeleteOperationHandler))] - [InlineData(ODataPathKind.Singleton, OperationType.Get, typeof(SingletonGetOperationHandler))] - [InlineData(ODataPathKind.Singleton, OperationType.Patch, typeof(SingletonPatchOperationHandler))] - [InlineData(ODataPathKind.NavigationProperty, OperationType.Get, typeof(NavigationPropertyGetOperationHandler))] - [InlineData(ODataPathKind.NavigationProperty, OperationType.Post, typeof(NavigationPropertyPostOperationHandler))] - [InlineData(ODataPathKind.NavigationProperty, OperationType.Patch, typeof(NavigationPropertyPatchOperationHandler))] - [InlineData(ODataPathKind.NavigationProperty, OperationType.Delete, typeof(NavigationPropertyDeleteOperationHandler))] - [InlineData(ODataPathKind.Operation, OperationType.Get, typeof(EdmFunctionOperationHandler))] - [InlineData(ODataPathKind.Operation, OperationType.Post, typeof(EdmActionOperationHandler))] - [InlineData(ODataPathKind.OperationImport, OperationType.Get, typeof(EdmFunctionImportOperationHandler))] - [InlineData(ODataPathKind.OperationImport, OperationType.Post, typeof(EdmActionImportOperationHandler))] - [InlineData(ODataPathKind.Ref, OperationType.Post, typeof(RefPostOperationHandler))] - [InlineData(ODataPathKind.Ref, OperationType.Delete, typeof(RefDeleteOperationHandler))] - [InlineData(ODataPathKind.Ref, OperationType.Get, typeof(RefGetOperationHandler))] - [InlineData(ODataPathKind.Ref, OperationType.Put, typeof(RefPutOperationHandler))] - [InlineData(ODataPathKind.MediaEntity, OperationType.Get, typeof(MediaEntityGetOperationHandler))] - [InlineData(ODataPathKind.MediaEntity, OperationType.Put, typeof(MediaEntityPutOperationHandler))] - [InlineData(ODataPathKind.Metadata, OperationType.Get, typeof(MetadataGetOperationHandler))] - [InlineData(ODataPathKind.DollarCount, OperationType.Get, typeof(DollarCountGetOperationHandler))] - public void GetHandlerReturnsCorrectOperationHandlerType(ODataPathKind pathKind, OperationType operationType, Type handlerType) + [InlineData(ODataPathKind.EntitySet, "get", typeof(EntitySetGetOperationHandler))] + [InlineData(ODataPathKind.EntitySet, "post", typeof(EntitySetPostOperationHandler))] + [InlineData(ODataPathKind.Entity, "get", typeof(EntityGetOperationHandler))] + [InlineData(ODataPathKind.Entity, "patch", typeof(EntityPatchOperationHandler))] + [InlineData(ODataPathKind.Entity, "delete", typeof(EntityDeleteOperationHandler))] + [InlineData(ODataPathKind.Singleton, "get", typeof(SingletonGetOperationHandler))] + [InlineData(ODataPathKind.Singleton, "patch", typeof(SingletonPatchOperationHandler))] + [InlineData(ODataPathKind.NavigationProperty, "get", typeof(NavigationPropertyGetOperationHandler))] + [InlineData(ODataPathKind.NavigationProperty, "post", typeof(NavigationPropertyPostOperationHandler))] + [InlineData(ODataPathKind.NavigationProperty, "patch", typeof(NavigationPropertyPatchOperationHandler))] + [InlineData(ODataPathKind.NavigationProperty, "delete", typeof(NavigationPropertyDeleteOperationHandler))] + [InlineData(ODataPathKind.Operation, "get", typeof(EdmFunctionOperationHandler))] + [InlineData(ODataPathKind.Operation, "post", typeof(EdmActionOperationHandler))] + [InlineData(ODataPathKind.OperationImport, "get", typeof(EdmFunctionImportOperationHandler))] + [InlineData(ODataPathKind.OperationImport, "post", typeof(EdmActionImportOperationHandler))] + [InlineData(ODataPathKind.Ref, "post", typeof(RefPostOperationHandler))] + [InlineData(ODataPathKind.Ref, "delete", typeof(RefDeleteOperationHandler))] + [InlineData(ODataPathKind.Ref, "get", typeof(RefGetOperationHandler))] + [InlineData(ODataPathKind.Ref, "put", typeof(RefPutOperationHandler))] + [InlineData(ODataPathKind.MediaEntity, "get", typeof(MediaEntityGetOperationHandler))] + [InlineData(ODataPathKind.MediaEntity, "put", typeof(MediaEntityPutOperationHandler))] + [InlineData(ODataPathKind.Metadata, "get", typeof(MetadataGetOperationHandler))] + [InlineData(ODataPathKind.DollarCount, "get", typeof(DollarCountGetOperationHandler))] + public void GetHandlerReturnsCorrectOperationHandlerType(ODataPathKind pathKind, string operationType, Type handlerType) { // Arrange OpenApiDocument openApiDocument = new(); OperationHandlerProvider provider = new OperationHandlerProvider(); // Act - IOperationHandler hander = provider.GetHandler(pathKind, operationType, openApiDocument); + IOperationHandler handler = provider.GetHandler(pathKind, HttpMethod.Parse(operationType), openApiDocument); // Assert - Assert.Same(handlerType, hander.GetType()); + Assert.Same(handlerType, handler.GetType()); } } } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/ComplexPropertyPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/ComplexPropertyPathItemHandlerTests.cs index 7b8f6447..46c4ddfc 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/ComplexPropertyPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/ComplexPropertyPathItemHandlerTests.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; @@ -64,13 +65,13 @@ public void SetsDefaultOperations(bool useAnnotationToGeneratePath, bool annotat if (operationCount > 0) { - Assert.True(pathItem.Operations.ContainsKey(OperationType.Get)); - Assert.True(pathItem.Operations.ContainsKey(OperationType.Patch)); + Assert.True(pathItem.Operations.ContainsKey(HttpMethod.Get)); + Assert.True(pathItem.Operations.ContainsKey(HttpMethod.Patch)); } else { - Assert.False(pathItem.Operations.ContainsKey(OperationType.Get)); - Assert.False(pathItem.Operations.ContainsKey(OperationType.Patch)); + Assert.False(pathItem.Operations.ContainsKey(HttpMethod.Get)); + Assert.False(pathItem.Operations.ContainsKey(HttpMethod.Patch)); } } @@ -119,18 +120,18 @@ public void SetsUpdateOperationWithUpdateMethodUpdateRestrictions(bool useAnnota { if (annotationAvailable) { - Assert.True(pathItem.Operations.ContainsKey(OperationType.Put)); + Assert.True(pathItem.Operations.ContainsKey(HttpMethod.Put)); } else { - Assert.True(pathItem.Operations.ContainsKey(OperationType.Get)); - Assert.True(pathItem.Operations.ContainsKey(OperationType.Patch)); + Assert.True(pathItem.Operations.ContainsKey(HttpMethod.Get)); + Assert.True(pathItem.Operations.ContainsKey(HttpMethod.Patch)); } } else { - Assert.False(pathItem.Operations.ContainsKey(OperationType.Patch)); - Assert.False(pathItem.Operations.ContainsKey(OperationType.Put)); + Assert.False(pathItem.Operations.ContainsKey(HttpMethod.Patch)); + Assert.False(pathItem.Operations.ContainsKey(HttpMethod.Put)); } } @@ -175,11 +176,11 @@ public void SetsPostOnCollectionProperties(bool useAnnotationToGeneratePath, boo if (operationCount > 0) { - Assert.True(pathItem.Operations.ContainsKey(OperationType.Post)); + Assert.True(pathItem.Operations.ContainsKey(HttpMethod.Post)); } else { - Assert.False(pathItem.Operations.ContainsKey(OperationType.Post)); + Assert.False(pathItem.Operations.ContainsKey(HttpMethod.Post)); } } [Fact] @@ -256,15 +257,15 @@ public void CreatesComplexPropertyPathsBasedOnTargetPathAnnotations(string reada Assert.Equal(operationCount, pathItem.Operations.Count); if (operationCount == 1) { - Assert.True(pathItem.Operations.ContainsKey(OperationType.Patch)); - Assert.False(pathItem.Operations.ContainsKey(OperationType.Post)); - Assert.False(pathItem.Operations.ContainsKey(OperationType.Get)); + Assert.True(pathItem.Operations.ContainsKey(HttpMethod.Patch)); + Assert.False(pathItem.Operations.ContainsKey(HttpMethod.Post)); + Assert.False(pathItem.Operations.ContainsKey(HttpMethod.Get)); } else if (operationCount == 3) { - Assert.True(pathItem.Operations.ContainsKey(OperationType.Patch)); - Assert.True(pathItem.Operations.ContainsKey(OperationType.Post)); - Assert.True(pathItem.Operations.ContainsKey(OperationType.Get)); + Assert.True(pathItem.Operations.ContainsKey(HttpMethod.Patch)); + Assert.True(pathItem.Operations.ContainsKey(HttpMethod.Post)); + Assert.True(pathItem.Operations.ContainsKey(HttpMethod.Get)); } } } \ No newline at end of file diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntityPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntityPathItemHandlerTests.cs index 47a5a9d3..a78ccf99 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntityPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntityPathItemHandlerTests.cs @@ -5,6 +5,7 @@ using System; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; @@ -74,7 +75,7 @@ public void CreateEntityPathItemReturnsCorrectPathItem() Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); Assert.Equal(3, pathItem.Operations.Count); - Assert.Equal(new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete }, + Assert.Equal(new HttpMethod[] { HttpMethod.Get, HttpMethod.Patch, HttpMethod.Delete }, pathItem.Operations.Select(o => o.Key)); } @@ -103,7 +104,7 @@ public void CreateEntityPathItemReturnsCorrectPathItemWithPathParameters(bool de Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); Assert.Equal(3, pathItem.Operations.Count); - Assert.Equal(new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete }, + Assert.Equal(new HttpMethod[] { HttpMethod.Get, HttpMethod.Patch, HttpMethod.Delete }, pathItem.Operations.Select(o => o.Key)); if (declarePathParametersOnPathItem) @@ -138,15 +139,15 @@ public void CreateEntityPathItemReturnsCorrectPathItemWithReferences() Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); Assert.Equal(3, pathItem.Operations.Count); - Assert.Equal(new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete }, + Assert.Equal(new HttpMethod[] { HttpMethod.Get, HttpMethod.Patch, HttpMethod.Delete }, pathItem.Operations.Select(o => o.Key)); Assert.NotEmpty(pathItem.Description); } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Patch, OperationType.Delete })] - public void CreateEntityPathItemWorksForReadByKeyRestrictionsCapablities(bool readable, OperationType[] expected) + [InlineData(true, new string[] { "get", "patch", "delete" })] + [InlineData(false, new string[] { "patch", "delete" })] + public void CreateEntityPathItemWorksForReadByKeyRestrictionsCapablities(bool readable, string[] expected) { // Arrange string annotation = $@" @@ -165,9 +166,9 @@ public void CreateEntityPathItemWorksForReadByKeyRestrictionsCapablities(bool re } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Patch, OperationType.Delete })] - public void CreateEntityPathItemWorksForReadRestrictionsCapablities(bool readable, OperationType[] expected) + [InlineData(true, new string[] { "get", "patch", "delete" })] + [InlineData(false, new string[] { "patch", "delete" })] + public void CreateEntityPathItemWorksForReadRestrictionsCapablities(bool readable, string[] expected) { // Arrange string annotation = $@" @@ -182,9 +183,9 @@ public void CreateEntityPathItemWorksForReadRestrictionsCapablities(bool readabl } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Get, OperationType.Delete })] - public void CreateEntityPathItemWorksForUpdateRestrictionsCapablities(bool updatable, OperationType[] expected) + [InlineData(true, new string[] { "get", "patch", "delete" })] + [InlineData(false, new string[] { "get", "delete" })] + public void CreateEntityPathItemWorksForUpdateRestrictionsCapablities(bool updatable, string[] expected) { // Arrange string annotation = $@" @@ -199,9 +200,9 @@ public void CreateEntityPathItemWorksForUpdateRestrictionsCapablities(bool updat } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Get, OperationType.Patch })] - public void CreateEntityPathItemWorksForDeleteRestrictionsCapablities(bool deletable, OperationType[] expected) + [InlineData(true, new string[] { "get", "patch", "delete" })] + [InlineData(false, new string[] { "get", "patch" })] + public void CreateEntityPathItemWorksForDeleteRestrictionsCapablities(bool deletable, string[] expected) { // Arrange string annotation = $@" @@ -216,9 +217,9 @@ public void CreateEntityPathItemWorksForDeleteRestrictionsCapablities(bool delet } [Theory] - [InlineData(false, new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete })] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Put, OperationType.Delete })] - public void CreateEntityPathItemWorksForUpdateMethodRestrictionsCapabilities(bool updateMethod, OperationType[] expected) + [InlineData(false, new string[] { "get", "patch", "delete" })] + [InlineData(true, new string[] { "get", "put", "delete" })] + public void CreateEntityPathItemWorksForUpdateMethodRestrictionsCapabilities(bool updateMethod, string[] expected) { // Arrange string annotation = updateMethod ? $@" @@ -234,7 +235,7 @@ public void CreateEntityPathItemWorksForUpdateMethodRestrictionsCapabilities(boo VerifyPathItemOperations(annotation, expected); } - private void VerifyPathItemOperations(string annotation, OperationType[] expected) + private void VerifyPathItemOperations(string annotation, string[] expected) { // Arrange IEdmModel model = EntitySetPathItemHandlerTests.GetEdmModel(annotation); @@ -251,7 +252,7 @@ private void VerifyPathItemOperations(string annotation, OperationType[] expecte Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); - Assert.Equal(expected, pathItem.Operations.Select(e => e.Key)); + Assert.Equal(expected, pathItem.Operations.Select(e => e.Key.ToString().ToLowerInvariant())); } [Fact] @@ -296,7 +297,7 @@ public MyEntityPathItemHandler(OpenApiDocument document) : base(document) { } - protected override void AddOperation(OpenApiPathItem item, OperationType operationType) + protected override void AddOperation(OpenApiPathItem item, HttpMethod operationType) { item.AddOperation(operationType, new OpenApiOperation()); } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntitySetPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntitySetPathItemHandlerTests.cs index 290f5375..58afba88 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntitySetPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntitySetPathItemHandlerTests.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Xml.Linq; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Csdl; @@ -20,7 +21,7 @@ namespace Microsoft.OpenApi.OData.PathItem.Tests { public class EntitySetPathItemHandlerTests { - private EntitySetPathItemHandler _pathItemHandler = new MyEntitySetPathItemHandler(new()); + private readonly EntitySetPathItemHandler _pathItemHandler = new MyEntitySetPathItemHandler(new()); [Fact] public void CreatePathItemThrowsForNullContext() @@ -76,15 +77,15 @@ public void CreateEntitySetPathItemReturnsCorrectPathItem() Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); Assert.Equal(2, pathItem.Operations.Count); - Assert.Equal(new OperationType[] { OperationType.Get, OperationType.Post }, + Assert.Equal([HttpMethod.Get, HttpMethod.Post], pathItem.Operations.Select(o => o.Key)); Assert.NotEmpty(pathItem.Description); } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Post })] - [InlineData(false, new OperationType[] { OperationType.Post })] - public void CreateEntitySetPathItemWorksForReadRestrictionsCapablities(bool readable, OperationType[] expected) + [InlineData(true, new [] { "get", "post" })] + [InlineData(false, new [] { "post" })] + public void CreateEntitySetPathItemWorksForReadRestrictionsCapabilities(bool readable, string[] expected) { // Arrange string annotation = $@" @@ -99,9 +100,9 @@ public void CreateEntitySetPathItemWorksForReadRestrictionsCapablities(bool read } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Post })] - [InlineData(false, new OperationType[] { OperationType.Get })] - public void CreateEntitySetPathItemWorksForInsertRestrictionsCapablities(bool insertable, OperationType[] expected) + [InlineData(true, new [] { "get", "post" })] + [InlineData(false, new [] { "get" })] + public void CreateEntitySetPathItemWorksForInsertRestrictionsCapablities(bool insertable, string[] expected) { // Arrange string annotation = $@" @@ -132,10 +133,10 @@ public void CreateEntitySetPathItemWorksForReadAndInsertRestrictionsCapablities( "; // Assert - VerifyPathItemOperations(annotation, new OperationType[] { }); + VerifyPathItemOperations(annotation, []); } - private void VerifyPathItemOperations(string annotation, OperationType[] expected) + private void VerifyPathItemOperations(string annotation, string[] expected) { // Arrange IEdmModel model = GetEdmModel(annotation); @@ -151,7 +152,7 @@ private void VerifyPathItemOperations(string annotation, OperationType[] expecte Assert.NotNull(pathItem); Assert.NotNull(pathItem.Operations); - Assert.Equal(expected, pathItem.Operations.Select(e => e.Key)); + Assert.Equal(expected, pathItem.Operations.Select(e => e.Key.ToString().ToLowerInvariant())); } [Fact] @@ -216,7 +217,7 @@ public static IEdmModel GetEdmModel(string annotation, string target = "\"NS.Def internal class MyEntitySetPathItemHandler(OpenApiDocument document) : EntitySetPathItemHandler(document) { - protected override void AddOperation(OpenApiPathItem item, OperationType operationType) + protected override void AddOperation(OpenApiPathItem item, HttpMethod operationType) { item.AddOperation(operationType, new OpenApiOperation()); } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/MediaEntityPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/MediaEntityPathItemHandlerTests.cs index d7496a20..75667e4f 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/MediaEntityPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/MediaEntityPathItemHandlerTests.cs @@ -10,6 +10,7 @@ using Microsoft.OpenApi.OData.Properties; using System; using System.Linq; +using System.Net.Http; using System.Xml.Linq; using Xunit; @@ -90,17 +91,17 @@ public void CreateMediaEntityPathItemReturnsCorrectItem() Assert.NotEmpty(pathItem2.Operations); Assert.Equal(3, pathItem.Operations.Count); Assert.Equal(3, pathItem2.Operations.Count); - Assert.Equal(new OperationType[] { OperationType.Get, OperationType.Put, OperationType.Delete }, + Assert.Equal([HttpMethod.Get, HttpMethod.Put, HttpMethod.Delete], pathItem.Operations.Select(o => o.Key)); - Assert.Equal(new OperationType[] { OperationType.Get, OperationType.Put, OperationType.Delete }, + Assert.Equal([HttpMethod.Get, HttpMethod.Put, HttpMethod.Delete], pathItem2.Operations.Select(o => o.Key)); Assert.NotEmpty(pathItem.Description); } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Put, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Put, OperationType.Delete })] - public void CreateMediaEntityPathItemWorksForReadByKeyRestrictionsCapabilities(bool readable, OperationType[] expected) + [InlineData(true, new string[] { "get", "put", "delete" })] + [InlineData(false, new string[] { "put", "delete" })] + public void CreateMediaEntityPathItemWorksForReadByKeyRestrictionsCapabilities(bool readable, string[] expected) { // Arrange string annotation = $@" @@ -120,9 +121,9 @@ public void CreateMediaEntityPathItemWorksForReadByKeyRestrictionsCapabilities(b } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Put, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Get, OperationType.Delete })] - public void CreateMediaEntityPathItemWorksForUpdateRestrictionsCapabilities(bool updatable, OperationType[] expected) + [InlineData(true, new string[] { "get", "put", "delete" })] + [InlineData(false, new string[] { "get", "delete" })] + public void CreateMediaEntityPathItemWorksForUpdateRestrictionsCapabilities(bool updatable, string[] expected) { // Arrange string annotation = $@" @@ -138,9 +139,9 @@ public void CreateMediaEntityPathItemWorksForUpdateRestrictionsCapabilities(bool } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Put, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Get, OperationType.Delete })] - public void CreateMediaEntityPathItemWorksForUpdateRestrictionsCapabilitiesWithTargetPathAnnotations(bool updatable, OperationType[] expected) + [InlineData(true, new string[] { "get", "put", "delete" })] + [InlineData(false, new string[] { "get", "delete" })] + public void CreateMediaEntityPathItemWorksForUpdateRestrictionsCapabilitiesWithTargetPathAnnotations(bool updatable, string[] expected) { string annotation = $@" @@ -164,9 +165,9 @@ public void CreateMediaEntityPathItemWorksForUpdateRestrictionsCapabilitiesWithT } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Put, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Get, OperationType.Put })] - public void CreateMediaEntityPathItemWorksForDeleteRestrictionsCapabilities(bool deletable, OperationType[] expected) + [InlineData(true, new string[] { "get", "put", "delete" })] + [InlineData(false, new string[] { "get", "put" })] + public void CreateMediaEntityPathItemWorksForDeleteRestrictionsCapabilities(bool deletable, string[] expected) { // Arrange string annotation = $@" @@ -182,9 +183,9 @@ public void CreateMediaEntityPathItemWorksForDeleteRestrictionsCapabilities(bool } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Put, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Get, OperationType.Put })] - public void CreateMediaEntityPathItemWorksForDeleteRestrictionsCapabilitiesWithTargetPathAnnotations(bool deletable, OperationType[] expected) + [InlineData(true, new string[] { "get", "put", "delete" })] + [InlineData(false, new string[] { "get", "put" })] + public void CreateMediaEntityPathItemWorksForDeleteRestrictionsCapabilitiesWithTargetPathAnnotations(bool deletable, string[] expected) { // Arrange string annotation = $@" @@ -209,7 +210,7 @@ public void CreateMediaEntityPathItemWorksForDeleteRestrictionsCapabilitiesWithT VerifyPathItemOperationsForStreamPropertySegment(annotation, expected, streamPropertyTargetPathAnnotation); } - private void VerifyPathItemOperationsForStreamPropertySegment(string annotation, OperationType[] expected, string targetPathAnnotations = "") + private void VerifyPathItemOperationsForStreamPropertySegment(string annotation, string[] expected, string targetPathAnnotations = "") { // Arrange @@ -232,10 +233,10 @@ private void VerifyPathItemOperationsForStreamPropertySegment(string annotation, Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); - Assert.Equal(expected, pathItem.Operations.Select(e => e.Key)); + Assert.Equal(expected, pathItem.Operations.Select(e => e.Key.ToString().ToLowerInvariant())); } - private void VerifyPathItemOperationsForStreamContentSegment(string annotation, OperationType[] expected, string targetPathAnnotations = null) + private void VerifyPathItemOperationsForStreamContentSegment(string annotation, string[] expected, string targetPathAnnotations = null) { // Arrange IEdmModel model = GetEdmModel(annotation, targetPathAnnotations); @@ -268,8 +269,8 @@ private void VerifyPathItemOperationsForStreamContentSegment(string annotation, Assert.NotNull(pathItem2.Operations); Assert.NotEmpty(pathItem.Operations); Assert.NotEmpty(pathItem2.Operations); - Assert.Equal(expected, pathItem.Operations.Select(e => e.Key)); - Assert.Equal(expected, pathItem2.Operations.Select(e => e.Key)); + Assert.Equal(expected, pathItem.Operations.Select(e => e.Key.ToString().ToLowerInvariant())); + Assert.Equal(expected, pathItem2.Operations.Select(e => e.Key.ToString().ToLowerInvariant()));; } private IEdmModel GetEdmModel(string annotation, string targetPathAnnotation = "") @@ -315,7 +316,7 @@ private IEdmModel GetEdmModel(string annotation, string targetPathAnnotation = " internal class MyMediaEntityPathItemHandler(OpenApiDocument document) : MediaEntityPathItemHandler(document) { - protected override void AddOperation(OpenApiPathItem item, OperationType operationType) + protected override void AddOperation(OpenApiPathItem item, HttpMethod operationType) { item.AddOperation(operationType, new OpenApiOperation()); } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/NavigationPropertyPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/NavigationPropertyPathItemHandlerTests.cs index f3a0aa86..520f5d7c 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/NavigationPropertyPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/NavigationPropertyPathItemHandlerTests.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Xml.Linq; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Csdl; @@ -59,11 +60,11 @@ public void CreatePathItemThrowsForNonNavigationPropertyPath() } [Theory] - [InlineData(true, true, new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete })] - [InlineData(true, false, new OperationType[] { OperationType.Get, OperationType.Post })] - [InlineData(false, true, new OperationType[] { OperationType.Get, OperationType.Delete })] // Deletablity explicitly set via annotation - [InlineData(false, false, new OperationType[] { OperationType.Get})] - public void CreateCollectionNavigationPropertyPathItemReturnsCorrectPathItem(bool containment, bool keySegment, OperationType[] expected) + [InlineData(true, true, new string[] { "get", "patch", "delete" })] + [InlineData(true, false, new string[] { "get", "post" })] + [InlineData(false, true, new string[] { "get", "delete" })] // Deletablity explicitly set via annotation + [InlineData(false, false, new string[] { "get"})] + public void CreateCollectionNavigationPropertyPathItemReturnsCorrectPathItem(bool containment, bool keySegment, string[] expected) { string annotation = containment ? @@ -103,7 +104,7 @@ public void CreateCollectionNavigationPropertyPathItemReturnsCorrectPathItem(boo Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); - Assert.Equal(expected, pathItem.Operations.Select(o => o.Key)); + Assert.Equal(expected, pathItem.Operations.Select(o => o.Key.ToString().ToLowerInvariant())); Assert.NotEmpty(pathItem.Description); } @@ -167,9 +168,9 @@ public void CreateNavigationPropertyPathItemReturnsCorrectPathItemWithPathParame } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Patch, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Get })] - public void CreateSingleNavigationPropertyPathItemReturnsCorrectPathItem(bool containment, OperationType[] expected) + [InlineData(true, new string[] { "get", "patch", "delete" })] + [InlineData(false, new string[] { "get" })] + public void CreateSingleNavigationPropertyPathItemReturnsCorrectPathItem(bool containment, string[] expected) { // Arrange IEdmModel model = GetEdmModel(""); @@ -194,7 +195,7 @@ public void CreateSingleNavigationPropertyPathItemReturnsCorrectPathItem(bool co Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); - Assert.Equal(expected, pathItem.Operations.Select(o => o.Key)); + Assert.Equal(expected, pathItem.Operations.Select(o => o.Key.ToString().ToLowerInvariant())); } public static IEnumerable CollectionNavigationPropertyData @@ -298,13 +299,13 @@ public void CreatePathItemForNavigationPropertyAndReadRestrictions(bool hasRestr if (hasRestrictions) { if (readable) - Assert.Contains(pathItem.Operations, o => o.Key == OperationType.Get); + Assert.Contains(pathItem.Operations, o => o.Key == HttpMethod.Get); else - Assert.DoesNotContain(pathItem.Operations, o => o.Key == OperationType.Get); + Assert.DoesNotContain(pathItem.Operations, o => o.Key == HttpMethod.Get); } else { - Assert.Contains(pathItem.Operations, o => o.Key == OperationType.Get); + Assert.Contains(pathItem.Operations, o => o.Key == HttpMethod.Get); } } @@ -349,18 +350,18 @@ public void CreatePathItemForNavigationPropertyAndInsertRestrictions(bool hasRes bool isContainment = path.Segments.OfType().Last().NavigationProperty.ContainsTarget; - OperationType[] expected; + HttpMethod[] expected; if (hasRestrictions) { expected = insertable - ? (new[] { OperationType.Get, OperationType.Post }) - : (new[] { OperationType.Get }); + ? (new[] { HttpMethod.Get, HttpMethod.Post }) + : (new[] { HttpMethod.Get }); } else { expected = isContainment - ? (new[] { OperationType.Get, OperationType.Post }) - : (new[] { OperationType.Get }); + ? (new[] { HttpMethod.Get, HttpMethod.Post }) + : (new[] { HttpMethod.Get }); } Assert.Equal(expected, pathItem.Operations.Select(o => o.Key)); @@ -410,27 +411,27 @@ public void CreatePathItemForNavigationPropertyAndUpdateRestrictions(bool hasRes bool isContainment = navigationProperty.ContainsTarget; bool isCollection = navigationProperty.TargetMultiplicity() == EdmMultiplicity.Many; - OperationType[] expected; + HttpMethod[] expected; if (hasRestrictions) { if (isContainment) { expected = updatable - ? (new[] { OperationType.Get, OperationType.Patch, OperationType.Delete }) - : (new[] { OperationType.Get, OperationType.Delete }); + ? (new[] { HttpMethod.Get, HttpMethod.Patch, HttpMethod.Delete }) + : (new[] { HttpMethod.Get, HttpMethod.Delete }); } else { expected = updatable - ? (new[] { OperationType.Get, OperationType.Patch }) - : (new[] { OperationType.Get }); + ? (new[] { HttpMethod.Get, HttpMethod.Patch }) + : (new[] { HttpMethod.Get }); } } else { expected = isContainment - ? (new[] { OperationType.Get, OperationType.Patch, OperationType.Delete }) - : (new[] { OperationType.Get }); + ? (new[] { HttpMethod.Get, HttpMethod.Patch, HttpMethod.Delete }) + : (new[] { HttpMethod.Get }); } Assert.Equal(expected, pathItem.Operations.Select(o => o.Key)); @@ -480,29 +481,28 @@ public void CreatePathItemForNavigationPropertyAndUpdateMethodUpdateRestrictions var navigationProperty = path.Segments.OfType().Last().NavigationProperty; bool isContainment = navigationProperty.ContainsTarget; - bool isCollection = navigationProperty.TargetMultiplicity() == EdmMultiplicity.Many; - OperationType[] expected; + HttpMethod[] expected; if (updateMethod) { if (isContainment) { expected = updatable - ? ([OperationType.Get, OperationType.Put, OperationType.Patch, OperationType.Delete]) - : ([OperationType.Get, OperationType.Delete]); + ? ([HttpMethod.Get, HttpMethod.Put, HttpMethod.Patch, HttpMethod.Delete]) + : ([HttpMethod.Get, HttpMethod.Delete]); } else { expected = updatable - ? ([OperationType.Get, OperationType.Put, OperationType.Patch,]) - : ([OperationType.Get]); + ? ([HttpMethod.Get, HttpMethod.Put, HttpMethod.Patch,]) + : ([HttpMethod.Get]); } } else { expected = isContainment - ? ([OperationType.Get, OperationType.Patch, OperationType.Delete]) - : ([OperationType.Get]); + ? ([HttpMethod.Get, HttpMethod.Patch, HttpMethod.Delete]) + : ([HttpMethod.Get]); } @@ -543,7 +543,7 @@ public void CreatePathItemForNavigationPropertyWithRestrictionAnnotationsDefined Assert.NotNull(pathItem); Assert.NotNull(pathItem.Operations); Assert.Single(pathItem.Operations); - Assert.Equal(OperationType.Get, pathItem.Operations.FirstOrDefault().Key); + Assert.Equal(HttpMethod.Get, pathItem.Operations.FirstOrDefault().Key); } [Fact] @@ -575,7 +575,7 @@ public void CreatePathItemForNavigationPropertyWithOutOfLineRestrictionAnnotatio Assert.NotNull(pathItem); Assert.NotNull(pathItem.Operations); Assert.Equal(2, pathItem.Operations.Count); - Assert.Equal(new[] { OperationType.Get, OperationType.Patch }, pathItem.Operations.Select(o => o.Key)); + Assert.Equal(new[] { HttpMethod.Get, HttpMethod.Patch }, pathItem.Operations.Select(o => o.Key)); } [Fact] diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/OperationImportPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/OperationImportPathItemHandlerTests.cs index 280885a3..99ed868c 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/OperationImportPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/OperationImportPathItemHandlerTests.cs @@ -5,6 +5,7 @@ using System; using System.Linq; +using System.Net.Http; using System.Xml.Linq; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Csdl; @@ -58,10 +59,10 @@ public void CreatePathItemThrowsForNonOperationImportPath() } [Theory] - [InlineData("GetNearestAirport", OperationType.Get)] - [InlineData("ResetDataSource", OperationType.Post)] + [InlineData("GetNearestAirport", "get")] + [InlineData("ResetDataSource", "post")] public void CreatePathItemForOperationImportReturnsCorrectPathItem(string operationImport, - OperationType operationType) + string operationType) { // Arrange IEdmModel model = EdmModelHelper.TripServiceModel; @@ -78,18 +79,18 @@ public void CreatePathItemForOperationImportReturnsCorrectPathItem(string operat Assert.NotNull(pathItem); Assert.NotNull(pathItem.Operations); var operationKeyValue = Assert.Single(pathItem.Operations); - Assert.Equal(operationType, operationKeyValue.Key); + Assert.Equal(HttpMethod.Parse(operationType), operationKeyValue.Key); Assert.NotNull(operationKeyValue.Value); Assert.NotEmpty(pathItem.Description); } [Theory] - [InlineData(true, "GetNearestCustomers", OperationType.Get)] + [InlineData(true, "GetNearestCustomers", "get")] [InlineData(false, "GetNearestCustomers", null)] - [InlineData(true, "ResetDataSource", OperationType.Post)] - [InlineData(false, "ResetDataSource", OperationType.Post)] + [InlineData(true, "ResetDataSource", "post")] + [InlineData(false, "ResetDataSource", "post")] public void CreatePathItemForOperationImportWithReadRestrictionsReturnsCorrectPathItem(bool readable, string operationImport, - OperationType? operationType) + string operationType) { // Arrange string annotation = $@" @@ -119,7 +120,7 @@ public void CreatePathItemForOperationImportWithReadRestrictionsReturnsCorrectPa else { var operationKeyValue = Assert.Single(pathItem.Operations); - Assert.Equal(operationType, operationKeyValue.Key); + Assert.Equal(HttpMethod.Parse(operationType), operationKeyValue.Key); Assert.NotNull(operationKeyValue.Value); } } @@ -189,7 +190,7 @@ public static IEdmModel GetEdmModel(string annotation) internal class MyOperationImportPathItemHandler(OpenApiDocument document) : OperationImportPathItemHandler(document) { - protected override void AddOperation(OpenApiPathItem item, OperationType operationType) + protected override void AddOperation(OpenApiPathItem item, HttpMethod operationType) { item.AddOperation(operationType, new OpenApiOperation()); } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/OperationPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/OperationPathItemHandlerTests.cs index 3167d196..51a76e9a 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/OperationPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/OperationPathItemHandlerTests.cs @@ -5,6 +5,7 @@ using System; using System.Linq; +using System.Net.Http; using Microsoft.OData.Edm; using Microsoft.OpenApi.Any; using Microsoft.OpenApi.Interfaces; @@ -56,10 +57,10 @@ public void CreatePathItemThrowsForNonOperationPath() } [Theory] - [InlineData("GetFriendsTrips", "People", OperationType.Get)] - [InlineData("ShareTrip", "People", OperationType.Post)] + [InlineData("GetFriendsTrips", "People", "get")] + [InlineData("ShareTrip", "People", "post")] public void CreatePathItemForOperationReturnsCorrectPathItem(string operationName, string entitySet, - OperationType operationType) + string operationType) { // Arrange IEdmModel model = EdmModelHelper.TripServiceModel; @@ -80,7 +81,7 @@ public void CreatePathItemForOperationReturnsCorrectPathItem(string operationNam Assert.NotNull(pathItem); Assert.NotNull(pathItem.Operations); var operationKeyValue = Assert.Single(pathItem.Operations); - Assert.Equal(operationType, operationKeyValue.Key); + Assert.Equal(HttpMethod.Parse(operationType), operationKeyValue.Key); Assert.NotNull(operationKeyValue.Value); Assert.Equal(expectSummary, operationKeyValue.Value.Summary); diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/RefPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/RefPathItemHandlerTests.cs index 48baaf76..9679196a 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/RefPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/RefPathItemHandlerTests.cs @@ -10,7 +10,6 @@ using Microsoft.OData.Edm; using Microsoft.OData.Edm.Csdl; using Microsoft.OData.Edm.Validation; -using Microsoft.OpenApi.Models; using Microsoft.OpenApi.OData.Edm; using Microsoft.OpenApi.OData.Properties; using Xunit; @@ -19,7 +18,7 @@ namespace Microsoft.OpenApi.OData.PathItem.Tests { public class RefPathItemHandlerTest { - private RefPathItemHandler _pathItemHandler = new RefPathItemHandler(new()); + private readonly RefPathItemHandler _pathItemHandler = new RefPathItemHandler(new()); [Fact] public void CreatePathItemThrowsForNullContext() @@ -57,10 +56,10 @@ public void CreatePathItemThrowsForNonNavigationPropertyPath() } [Theory] - [InlineData(true, new OperationType[] { OperationType.Delete}, true)] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Post, OperationType.Delete })] - [InlineData(false, new OperationType[] { OperationType.Get, OperationType.Put, OperationType.Delete })] - public void CreateNavigationPropertyRefPathItemReturnsCorrectPathItem(bool collectionNav, OperationType[] expected, bool indexedColNav = false) + [InlineData(true, new string[] { "delete"}, true)] + [InlineData(true, new string[] { "get", "post", "delete" })] + [InlineData(false, new string[] { "get", "put", "delete" })] + public void CreateNavigationPropertyRefPathItemReturnsCorrectPathItem(bool collectionNav, string[] expected, bool indexedColNav = false) { // Arrange IEdmModel model = GetEdmModel(""); @@ -100,7 +99,7 @@ public void CreateNavigationPropertyRefPathItemReturnsCorrectPathItem(bool colle Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); - Assert.Equal(expected, pathItem.Operations.Select(o => o.Key)); + Assert.Equal(expected, pathItem.Operations.Select(o => o.Key.ToString().ToLowerInvariant())); Assert.NotEmpty(pathItem.Description); } diff --git a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/SingletonPathItemHandlerTests.cs b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/SingletonPathItemHandlerTests.cs index b94e63ef..73125251 100644 --- a/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/SingletonPathItemHandlerTests.cs +++ b/test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/SingletonPathItemHandlerTests.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Xml.Linq; using Microsoft.OData.Edm; using Microsoft.OData.Edm.Csdl; @@ -76,15 +77,15 @@ public void CreateSingletonPathItemReturnsCorrectPathItem() Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); Assert.Equal(2, pathItem.Operations.Count); - Assert.Equal(new OperationType[] { OperationType.Get, OperationType.Patch }, + Assert.Equal([HttpMethod.Get, HttpMethod.Patch], pathItem.Operations.Select(o => o.Key)); Assert.NotEmpty(pathItem.Description); } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Patch })] - [InlineData(false, new OperationType[] { OperationType.Patch })] - public void CreateSingletonPathItemWorksForReadRestrictionsCapablities(bool readable, OperationType[] expected) + [InlineData(true, new string[] { "get", "patch" })] + [InlineData(false, new string[] { "patch" })] + public void CreateSingletonPathItemWorksForReadRestrictionsCapablities(bool readable, string[] expected) { // Arrange string annotation = $@" @@ -99,9 +100,9 @@ public void CreateSingletonPathItemWorksForReadRestrictionsCapablities(bool read } [Theory] - [InlineData(true, new OperationType[] { OperationType.Get, OperationType.Patch })] - [InlineData(false, new OperationType[] { OperationType.Get })] - public void CreateSingletonPathItemWorksForUpdateRestrictionsCapablities(bool updatable, OperationType[] expected) + [InlineData(true, new string[] { "get", "patch" })] + [InlineData(false, new string[] { "get" })] + public void CreateSingletonPathItemWorksForUpdateRestrictionsCapablities(bool updatable, string[] expected) { // Arrange string annotation = $@" @@ -115,7 +116,7 @@ public void CreateSingletonPathItemWorksForUpdateRestrictionsCapablities(bool up VerifyPathItemOperations(annotation, expected); } - private void VerifyPathItemOperations(string annotation, OperationType[] expected) + private void VerifyPathItemOperations(string annotation, string[] expected) { // Arrange IEdmModel model = GetEdmModel(annotation); @@ -132,7 +133,7 @@ private void VerifyPathItemOperations(string annotation, OperationType[] expecte Assert.NotNull(pathItem.Operations); Assert.NotEmpty(pathItem.Operations); - Assert.Equal(expected, pathItem.Operations.Select(e => e.Key)); + Assert.Equal(expected, pathItem.Operations.Select(e => e.Key.ToString().ToLowerInvariant())); } [Fact] @@ -195,7 +196,7 @@ public MySingletonPathItemHandler(OpenApiDocument document) : base(document) { } - protected override void AddOperation(OpenApiPathItem item, OperationType operationType) + protected override void AddOperation(OpenApiPathItem item, HttpMethod operationType) { item.AddOperation(operationType, new OpenApiOperation()); }