diff --git a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs index 1dd71942b..7efecc0f7 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiPathItem.cs @@ -17,9 +17,6 @@ namespace Microsoft.OpenApi.Models /// public class OpenApiPathItem : OpenApiElement, IOpenApiExtension { - private readonly IDictionary _operations - = new Dictionary(); - /// /// An optional, string summary, intended to apply to all operations in this path. /// @@ -33,13 +30,8 @@ private readonly IDictionary _operations /// /// Gets the definition of operations on this path. /// - public IReadOnlyDictionary Operations - { - get - { - return _operations.ToDictionary(o => o.Key.GetDisplayName(), o => o.Value); - } - } + public IDictionary Operations { get; } + = new Dictionary(); /// /// An alternative server array to service all operations in this path. @@ -64,7 +56,7 @@ public IReadOnlyDictionary Operations /// The operation item. public void AddOperation(OperationType operationType, OpenApiOperation operation) { - _operations[operationType] = operation; + Operations[operationType] = operation; } /// @@ -86,7 +78,7 @@ internal override void WriteAsV3(IOpenApiWriter writer) writer.WriteProperty(OpenApiConstants.Description, Description); // operations - foreach (var operation in _operations) + foreach (var operation in Operations) { writer.WriteOptionalObject(operation.Key.GetDisplayName(), operation.Value, (w, o) => o.WriteAsV3(w)); } @@ -116,7 +108,7 @@ internal override void WriteAsV2(IOpenApiWriter writer) writer.WriteStartObject(); // operations except "trace" - foreach (var operation in _operations) + foreach (var operation in Operations) { if (operation.Key != OperationType.Trace) { diff --git a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs index 7ee413617..f9b9a5b0f 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs @@ -17,7 +17,7 @@ public virtual void Visit(OpenApiServer server) { } public virtual void Visit(OpenApiPaths paths) { } public virtual void Visit(OpenApiPathItem pathItem) { } public virtual void Visit(OpenApiServerVariable serverVariable) { } - public virtual void Visit(IReadOnlyDictionary operations) { } + public virtual void Visit(IDictionary operations) { } public virtual void Visit(OpenApiOperation operation) { } public virtual void Visit(IList parameters) { } public virtual void Visit(OpenApiParameter parameter) { } diff --git a/test/Microsoft.OpenApi.Readers.Tests/CallbackTests.cs b/test/Microsoft.OpenApi.Readers.Tests/CallbackTests.cs index 17ecfcf68..aba1b80ac 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/CallbackTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/CallbackTests.cs @@ -4,6 +4,7 @@ // ------------------------------------------------------------ using System.Linq; +using Microsoft.OpenApi.Models; using Xunit; namespace Microsoft.OpenApi.Readers.Tests @@ -18,11 +19,11 @@ public void LoadSimpleCallback() var openApiDoc = new OpenApiStreamReader().Read(stream, out var context); var path = openApiDoc.Paths.First().Value; - var subscribeOperation = path.Operations["post"]; + var subscribeOperation = path.Operations[OperationType.Post]; var callback = subscribeOperation.Callbacks["mainHook"]; var pathItem = callback.PathItems.First().Value; - var operation = pathItem.Operations["post"]; + var operation = pathItem.Operations[OperationType.Post]; Assert.NotNull(operation); } @@ -49,7 +50,7 @@ public void LoadSimpleCallbackWithRefs() var operationPair = pathItem.Operations.First(); var cboperation = operationPair.Value; - Assert.Equal("post", operationPair.Key); + Assert.Equal(OperationType.Post, operationPair.Key); Assert.NotNull(callback); } diff --git a/test/Microsoft.OpenApi.Readers.Tests/OperationTests.cs b/test/Microsoft.OpenApi.Readers.Tests/OperationTests.cs index 3c4709318..b0e381f25 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/OperationTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/OperationTests.cs @@ -28,7 +28,7 @@ public void CheckPetStoreFirstOperation() { var firstPath = _PetStoreDoc.Paths.First().Value; var firstOperation = firstPath.Operations.First(); - Assert.Equal("get", firstOperation.Key); + Assert.Equal(OperationType.Get, firstOperation.Key); Assert.Equal("findPets", firstOperation.Value.OperationId); Assert.Equal(2, firstOperation.Value.Parameters.Count); } @@ -65,7 +65,7 @@ public void DoesAPathExist() [Fact] public void GetPostOperation() { - var postOperation = _PetStoreDoc.Paths["/pets"].Operations["post"]; + var postOperation = _PetStoreDoc.Paths["/pets"].Operations[OperationType.Post]; Assert.Equal("addPet", postOperation.OperationId); @@ -75,7 +75,7 @@ public void GetPostOperation() [Fact] public void GetResponses() { - var getOperation = _PetStoreDoc.Paths["/pets"].Operations["get"]; + var getOperation = _PetStoreDoc.Paths["/pets"].Operations[OperationType.Get]; var responses = getOperation.Responses; diff --git a/test/Microsoft.OpenApi.Readers.Tests/SchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/SchemaTests.cs index ff54070cb..060900a2c 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/SchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/SchemaTests.cs @@ -3,6 +3,7 @@ // Licensed under the MIT License (MIT). See LICENSE in the repo root for license information. // ------------------------------------------------------------ +using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Readers.ParseNodes; using Microsoft.OpenApi.Readers.V3; using Xunit; @@ -18,7 +19,7 @@ public void CheckPetStoreApiInfo() var openApiDoc = new OpenApiStreamReader().Read(stream, out var context); - var operation = openApiDoc.Paths["/pets"].Operations["get"]; + var operation = openApiDoc.Paths["/pets"].Operations[OperationType.Get]; var schema = operation.Responses["200"].Content["application/json"].Schema; Assert.NotNull(schema); }