Skip to content

Commit c725267

Browse files
committed
fix: path item reference implementation
Signed-off-by: Vincent Biret <[email protected]>
1 parent a72aa29 commit c725267

38 files changed

+213
-259
lines changed

src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public override void Visit(OpenApiSchema schema)
5151
base.Visit(schema);
5252
}
5353

54-
public override void Visit(OpenApiPathItem pathItem)
54+
public override void Visit(IOpenApiPathItem pathItem)
5555
{
5656
if (pathItem.Operations.TryGetValue(OperationType.Put, out var value) &&
5757
value.OperationId != null)
@@ -81,13 +81,13 @@ public override void Visit(OpenApiOperation operation)
8181
operationId = ResolveODataCastOperationId(operationId);
8282
operationId = ResolveByRefOperationId(operationId);
8383
// Verb segment resolution should always be last. user.get -> user_Get
84-
operationId = ResolveVerbSegmentInOpertationId(operationId);
84+
operationId = ResolveVerbSegmentInOperationId(operationId);
8585

8686
operation.OperationId = operationId;
8787
base.Visit(operation);
8888
}
8989

90-
private static string ResolveVerbSegmentInOpertationId(string operationId)
90+
private static string ResolveVerbSegmentInOperationId(string operationId)
9191
{
9292
var charPos = operationId.LastIndexOf('.', operationId.Length - 1);
9393
if (operationId.Contains('_', StringComparison.OrdinalIgnoreCase) || charPos < 0)

src/Microsoft.OpenApi.Hidi/StatsVisitor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override void Visit(IDictionary<string, IOpenApiHeader> headers)
3434

3535
public int PathItemCount { get; set; }
3636

37-
public override void Visit(OpenApiPathItem pathItem)
37+
public override void Visit(IOpenApiPathItem pathItem)
3838
{
3939
PathItemCount++;
4040
}

src/Microsoft.OpenApi.Workbench/StatsVisitor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public override void Visit(IDictionary<string, IOpenApiHeader> headers)
3434

3535
public int PathItemCount { get; set; }
3636

37-
public override void Visit(OpenApiPathItem pathItem)
37+
public override void Visit(IOpenApiPathItem pathItem)
3838
{
3939
PathItemCount++;
4040
}

src/Microsoft.OpenApi/Models/Interfaces/IOpenApiCallback.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ public interface IOpenApiCallback : IOpenApiSerializable, IOpenApiReadOnlyExtens
1414
/// <summary>
1515
/// A Path Item Object used to define a callback request and expected responses.
1616
/// </summary>
17-
public Dictionary<RuntimeExpression, OpenApiPathItem> PathItems { get; }
17+
public Dictionary<RuntimeExpression, IOpenApiPathItem> PathItems { get; }
1818
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
using System.Collections.Generic;
3+
using Microsoft.OpenApi.Interfaces;
4+
5+
namespace Microsoft.OpenApi.Models.Interfaces;
6+
7+
/// <summary>
8+
/// Defines the base properties for the path item object.
9+
/// This interface is provided for type assertions but should not be implemented by package consumers beyond automatic mocking.
10+
/// </summary>
11+
public interface IOpenApiPathItem : IOpenApiDescribedElement, IOpenApiSummarizedElement, IOpenApiSerializable, IOpenApiReadOnlyExtensible
12+
{
13+
/// <summary>
14+
/// Gets the definition of operations on this path.
15+
/// </summary>
16+
public IDictionary<OperationType, OpenApiOperation> Operations { get; }
17+
18+
/// <summary>
19+
/// An alternative server array to service all operations in this path.
20+
/// </summary>
21+
public IList<OpenApiServer> Servers { get; }
22+
23+
/// <summary>
24+
/// A list of parameters that are applicable for all the operations described under this path.
25+
/// These parameters can be overridden at the operation level, but cannot be removed there.
26+
/// </summary>
27+
public IList<IOpenApiParameter> Parameters { get; }
28+
}

src/Microsoft.OpenApi/Models/OpenApiCallback.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.OpenApi.Models
1616
public class OpenApiCallback : IOpenApiReferenceable, IOpenApiExtensible, IOpenApiCallback
1717
{
1818
/// <inheritdoc/>
19-
public Dictionary<RuntimeExpression, OpenApiPathItem> PathItems { get; set; }
19+
public Dictionary<RuntimeExpression, IOpenApiPathItem> PathItems { get; set; }
2020
= [];
2121

2222

@@ -40,11 +40,11 @@ public OpenApiCallback(IOpenApiCallback callback)
4040
}
4141

4242
/// <summary>
43-
/// Add a <see cref="OpenApiPathItem"/> into the <see cref="PathItems"/>.
43+
/// Add a <see cref="IOpenApiPathItem"/> into the <see cref="PathItems"/>.
4444
/// </summary>
4545
/// <param name="expression">The runtime expression.</param>
4646
/// <param name="pathItem">The path item.</param>
47-
public void AddPathItem(RuntimeExpression expression, OpenApiPathItem pathItem)
47+
public void AddPathItem(RuntimeExpression expression, IOpenApiPathItem pathItem)
4848
{
4949
Utils.CheckArgumentNull(expression);
5050
Utils.CheckArgumentNull(pathItem);

src/Microsoft.OpenApi/Models/OpenApiComponents.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public class OpenApiComponents : IOpenApiSerializable, IOpenApiExtensible
6666
public IDictionary<string, IOpenApiCallback>? Callbacks { get; set; } = new Dictionary<string, IOpenApiCallback>();
6767

6868
/// <summary>
69-
/// An object to hold reusable <see cref="OpenApiPathItem"/> Object.
69+
/// An object to hold reusable <see cref="IOpenApiPathItem"/> Object.
7070
/// </summary>
71-
public IDictionary<string, OpenApiPathItem>? PathItems { get; set; } = new Dictionary<string, OpenApiPathItem>();
71+
public IDictionary<string, IOpenApiPathItem>? PathItems { get; set; } = new Dictionary<string, IOpenApiPathItem>();
7272

7373
/// <summary>
7474
/// This object MAY be extended with Specification Extensions.
@@ -94,7 +94,7 @@ public OpenApiComponents(OpenApiComponents? components)
9494
SecuritySchemes = components?.SecuritySchemes != null ? new Dictionary<string, OpenApiSecurityScheme>(components.SecuritySchemes) : null;
9595
Links = components?.Links != null ? new Dictionary<string, IOpenApiLink>(components.Links) : null;
9696
Callbacks = components?.Callbacks != null ? new Dictionary<string, IOpenApiCallback>(components.Callbacks) : null;
97-
PathItems = components?.PathItems != null ? new Dictionary<string, OpenApiPathItem>(components.PathItems) : null;
97+
PathItems = components?.PathItems != null ? new Dictionary<string, IOpenApiPathItem>(components.PathItems) : null;
9898
Extensions = components?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(components.Extensions) : null;
9999
}
100100

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public class OpenApiDocument : IOpenApiSerializable, IOpenApiExtensible, IOpenAp
5656
/// A map of requests initiated other than by an API call, for example by an out of band registration.
5757
/// The key name is a unique string to refer to each webhook, while the (optionally referenced) Path Item Object describes a request that may be initiated by the API provider and the expected responses
5858
/// </summary>
59-
public IDictionary<string, OpenApiPathItem>? Webhooks { get; set; } = new Dictionary<string, OpenApiPathItem>();
59+
public IDictionary<string, IOpenApiPathItem>? Webhooks { get; set; } = new Dictionary<string, IOpenApiPathItem>();
6060

6161
/// <summary>
6262
/// An element to hold various schemas for the specification.
@@ -113,7 +113,7 @@ public OpenApiDocument(OpenApiDocument? document)
113113
JsonSchemaDialect = document?.JsonSchemaDialect ?? JsonSchemaDialect;
114114
Servers = document?.Servers != null ? new List<OpenApiServer>(document.Servers) : null;
115115
Paths = document?.Paths != null ? new(document?.Paths) : new OpenApiPaths();
116-
Webhooks = document?.Webhooks != null ? new Dictionary<string, OpenApiPathItem>(document.Webhooks) : null;
116+
Webhooks = document?.Webhooks != null ? new Dictionary<string, IOpenApiPathItem>(document.Webhooks) : null;
117117
Components = document?.Components != null ? new(document?.Components) : null;
118118
SecurityRequirements = document?.SecurityRequirements != null ? new List<OpenApiSecurityRequirement>(document.SecurityRequirements) : null;
119119
Tags = document?.Tags != null ? new List<OpenApiTag>(document.Tags) : null;
@@ -612,7 +612,7 @@ public bool AddComponent<T>(string id, T componentToRegister)
612612
Components.Callbacks.Add(id, openApiCallback);
613613
break;
614614
case OpenApiPathItem openApiPathItem:
615-
Components.PathItems ??= new Dictionary<string, OpenApiPathItem>();
615+
Components.PathItems ??= new Dictionary<string, IOpenApiPathItem>();
616616
Components.PathItems.Add(id, openApiPathItem);
617617
break;
618618
case OpenApiExample openApiExample:

src/Microsoft.OpenApi/Models/OpenApiPathItem.cs

+17-41
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,26 @@ namespace Microsoft.OpenApi.Models
1313
/// <summary>
1414
/// Path Item Object: to describe the operations available on a single path.
1515
/// </summary>
16-
public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable
16+
public class OpenApiPathItem : IOpenApiExtensible, IOpenApiReferenceable, IOpenApiPathItem
1717
{
18-
/// <summary>
19-
/// An optional, string summary, intended to apply to all operations in this path.
20-
/// </summary>
21-
public virtual string Summary { get; set; }
18+
/// <inheritdoc/>
19+
public string Summary { get; set; }
2220

23-
/// <summary>
24-
/// An optional, string description, intended to apply to all operations in this path.
25-
/// </summary>
26-
public virtual string Description { get; set; }
21+
/// <inheritdoc/>
22+
public string Description { get; set; }
2723

28-
/// <summary>
29-
/// Gets the definition of operations on this path.
30-
/// </summary>
31-
public virtual IDictionary<OperationType, OpenApiOperation> Operations { get; set; }
24+
/// <inheritdoc/>
25+
public IDictionary<OperationType, OpenApiOperation> Operations { get; set; }
3226
= new Dictionary<OperationType, OpenApiOperation>();
3327

34-
/// <summary>
35-
/// An alternative server array to service all operations in this path.
36-
/// </summary>
37-
public virtual IList<OpenApiServer> Servers { get; set; } = new List<OpenApiServer>();
38-
39-
/// <summary>
40-
/// A list of parameters that are applicable for all the operations described under this path.
41-
/// These parameters can be overridden at the operation level, but cannot be removed there.
42-
/// </summary>
43-
public virtual IList<IOpenApiParameter> Parameters { get; set; } = new List<IOpenApiParameter>();
28+
/// <inheritdoc/>
29+
public IList<OpenApiServer> Servers { get; set; } = [];
4430

45-
/// <summary>
46-
/// This object MAY be extended with Specification Extensions.
47-
/// </summary>
48-
public virtual IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
31+
/// <inheritdoc/>
32+
public IList<IOpenApiParameter> Parameters { get; set; } = [];
4933

50-
/// <summary>
51-
/// Indicates if object is populated with data or is just a reference to the data
52-
/// </summary>
53-
public bool UnresolvedReference { get; set; }
54-
55-
/// <summary>
56-
/// Reference object.
57-
/// </summary>
58-
public OpenApiReference Reference { get; set; }
34+
/// <inheritdoc/>
35+
public IDictionary<string, IOpenApiExtension> Extensions { get; set; } = new Dictionary<string, IOpenApiExtension>();
5936

6037
/// <summary>
6138
/// Add one operation into this path item.
@@ -75,30 +52,29 @@ public OpenApiPathItem() { }
7552
/// <summary>
7653
/// Initializes a clone of an <see cref="OpenApiPathItem"/> object
7754
/// </summary>
78-
public OpenApiPathItem(OpenApiPathItem pathItem)
55+
public OpenApiPathItem(IOpenApiPathItem pathItem)
7956
{
57+
Utils.CheckArgumentNull(pathItem);
8058
Summary = pathItem?.Summary ?? Summary;
8159
Description = pathItem?.Description ?? Description;
8260
Operations = pathItem?.Operations != null ? new Dictionary<OperationType, OpenApiOperation>(pathItem.Operations) : null;
8361
Servers = pathItem?.Servers != null ? new List<OpenApiServer>(pathItem.Servers) : null;
8462
Parameters = pathItem?.Parameters != null ? new List<IOpenApiParameter>(pathItem.Parameters) : null;
8563
Extensions = pathItem?.Extensions != null ? new Dictionary<string, IOpenApiExtension>(pathItem.Extensions) : null;
86-
UnresolvedReference = pathItem?.UnresolvedReference ?? UnresolvedReference;
87-
Reference = pathItem?.Reference != null ? new(pathItem?.Reference) : null;
8864
}
8965

9066
/// <summary>
9167
/// Serialize <see cref="OpenApiPathItem"/> to Open Api v3.1
9268
/// </summary>
93-
public virtual void SerializeAsV31(IOpenApiWriter writer)
69+
public void SerializeAsV31(IOpenApiWriter writer)
9470
{
9571
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_1, (writer, element) => element.SerializeAsV31(writer));
9672
}
9773

9874
/// <summary>
9975
/// Serialize <see cref="OpenApiPathItem"/> to Open Api v3.0
10076
/// </summary>
101-
public virtual void SerializeAsV3(IOpenApiWriter writer)
77+
public void SerializeAsV3(IOpenApiWriter writer)
10278
{
10379
SerializeInternal(writer, OpenApiSpecVersion.OpenApi3_0, (writer, element) => element.SerializeAsV3(writer));
10480
}

src/Microsoft.OpenApi/Models/OpenApiPaths.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4+
using Microsoft.OpenApi.Models.Interfaces;
5+
46
namespace Microsoft.OpenApi.Models
57
{
68
/// <summary>
79
/// Paths object.
810
/// </summary>
9-
public class OpenApiPaths : OpenApiExtensibleDictionary<OpenApiPathItem>
11+
public class OpenApiPaths : OpenApiExtensibleDictionary<IOpenApiPathItem>
1012
{
1113
/// <summary>
1214
/// Parameterless constructor

src/Microsoft.OpenApi/Models/References/OpenApiCallbackReference.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ internal OpenApiCallbackReference(OpenApiCallback target, string referenceId):ba
4242
}
4343

4444
/// <inheritdoc/>
45-
public Dictionary<RuntimeExpression, OpenApiPathItem> PathItems { get => Target?.PathItems; }
45+
public Dictionary<RuntimeExpression, IOpenApiPathItem> PathItems { get => Target?.PathItems; }
4646

4747
/// <inheritdoc/>
4848
public IDictionary<string, IOpenApiExtension> Extensions { get => Target?.Extensions; }

0 commit comments

Comments
 (0)