Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/Microsoft.OpenApi/Models/OpenApiPathItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ namespace Microsoft.OpenApi.Models
/// </summary>
public class OpenApiPathItem : OpenApiElement, IOpenApiExtension
{
private readonly IDictionary<OperationType, OpenApiOperation> _operations
= new Dictionary<OperationType, OpenApiOperation>();

/// <summary>
/// An optional, string summary, intended to apply to all operations in this path.
/// </summary>
Expand All @@ -33,13 +30,8 @@ private readonly IDictionary<OperationType, OpenApiOperation> _operations
/// <summary>
/// Gets the definition of operations on this path.
/// </summary>
public IReadOnlyDictionary<string, OpenApiOperation> Operations
{
get
{
return _operations.ToDictionary(o => o.Key.GetDisplayName(), o => o.Value);
}
}
public IDictionary<OperationType, OpenApiOperation> Operations { get; }
= new Dictionary<OperationType, OpenApiOperation>();

/// <summary>
/// An alternative server array to service all operations in this path.
Expand All @@ -64,7 +56,7 @@ public IReadOnlyDictionary<string, OpenApiOperation> Operations
/// <param name="operation">The operation item.</param>
public void AddOperation(OperationType operationType, OpenApiOperation operation)
{
_operations[operationType] = operation;
Operations[operationType] = operation;
}

/// <summary>
Expand All @@ -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));
}
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,OpenApiOperation> operations) { }
public virtual void Visit(IDictionary<OperationType,OpenApiOperation> operations) { }
public virtual void Visit(OpenApiOperation operation) { }
public virtual void Visit(IList<OpenApiParameter> parameters) { }
public virtual void Visit(OpenApiParameter parameter) { }
Expand Down
7 changes: 4 additions & 3 deletions test/Microsoft.OpenApi.Readers.Tests/CallbackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ------------------------------------------------------------

using System.Linq;
using Microsoft.OpenApi.Models;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions test/Microsoft.OpenApi.Readers.Tests/OperationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand All @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion test/Microsoft.OpenApi.Readers.Tests/SchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down