Skip to content

Commit a4df88b

Browse files
committed
feat: lookup document is being passed to all handlers
Signed-off-by: Vincent Biret <[email protected]>
1 parent 316a0fd commit a4df88b

File tree

6 files changed

+31
-29
lines changed

6 files changed

+31
-29
lines changed

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiPathItemGenerator.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ internal static class OpenApiPathItemGenerator
2222
/// Create a map of <see cref="OpenApiPathItem"/>.
2323
/// </summary>
2424
/// <param name="context">The OData context.</param>
25+
/// <param name="document">The Open API document to use to lookup references.</param>
2526
/// <returns>The created map of <see cref="OpenApiPathItem"/>.</returns>
26-
public static IDictionary<string, OpenApiPathItem> CreatePathItems(this ODataContext context)
27+
public static IDictionary<string, OpenApiPathItem> CreatePathItems(this ODataContext context, OpenApiDocument document)
2728
{
2829
Utils.CheckArgumentNull(context, nameof(context));
2930

@@ -37,7 +38,7 @@ public static IDictionary<string, OpenApiPathItem> CreatePathItems(this ODataCon
3738
settings.EnableKeyAsSegment = context.KeyAsSegment;
3839
foreach (ODataPath path in context.AllPaths)
3940
{
40-
IPathItemHandler handler = context.PathItemHandlerProvider.GetHandler(path.Kind);
41+
IPathItemHandler handler = context.PathItemHandlerProvider.GetHandler(path.Kind, document);
4142
if (handler == null)
4243
{
4344
continue;

src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiPathsGenerator.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ internal static class OpenApiPathsGenerator
2222
/// and whose value is a Path Item Object.
2323
/// </summary>
2424
/// <param name="context">The OData context.</param>
25+
/// <param name="document">The Open API document to use to lookup references.</param>
2526
/// <returns>The created <see cref="OpenApiPaths"/> object.</returns>
26-
public static OpenApiPaths CreatePaths(this ODataContext context)
27+
public static OpenApiPaths CreatePaths(this ODataContext context, OpenApiDocument document)
2728
{
2829
Utils.CheckArgumentNull(context, nameof(context));
2930

3031
// Due to the power and flexibility of OData a full representation of all service capabilities
3132
// in the Paths Object is typically not feasible, so this mapping only describes the minimum
3233
// information desired in the Paths Object.
33-
OpenApiPaths paths = new();
34-
foreach (var item in context.CreatePathItems())
34+
OpenApiPaths paths = [];
35+
foreach (var item in context.CreatePathItems(document))
3536
{
3637
paths.Add(item.Key, item.Value);
3738
}

src/Microsoft.OpenApi.OData.Reader/Operation/IOperationHandlerProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ internal interface IOperationHandlerProvider
1818
/// </summary>
1919
/// <param name="pathKind">The path kind.</param>
2020
/// <param name="operationType">The operation type.</param>
21+
/// <param name="document">The Open API document to use to lookup references.</param>
2122
/// <returns>The corresponding <see cref="IOperationHandler"/>.</returns>
22-
IOperationHandler GetHandler(ODataPathKind pathKind, OperationType operationType);
23+
IOperationHandler GetHandler(ODataPathKind pathKind, OperationType operationType, OpenApiDocument document);
2324
}
2425
}

src/Microsoft.OpenApi.OData.Reader/Operation/OperationHandlerProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Microsoft.OpenApi.OData.Operation
1515
internal class OperationHandlerProvider : IOperationHandlerProvider
1616
{
1717
/// <inheritdoc/>
18-
public IOperationHandler GetHandler(ODataPathKind pathKind, OperationType operationType)
18+
public IOperationHandler GetHandler(ODataPathKind pathKind, OperationType operationType, OpenApiDocument document)
1919
{
2020
return (pathKind, operationType) switch
2121
{

src/Microsoft.OpenApi.OData.Reader/PathItem/IPathItemHandlerProvider.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// ------------------------------------------------------------
55

6+
using Microsoft.OpenApi.Models;
67
using Microsoft.OpenApi.OData.Edm;
78

89
namespace Microsoft.OpenApi.OData.PathItem
@@ -16,7 +17,8 @@ internal interface IPathItemHandlerProvider
1617
/// Get the <see cref="IPathItemHandler"/> based on the path type.
1718
/// </summary>
1819
/// <param name="pathKind">The path kind.</param>
20+
/// <param name="document">The Open API document to use to lookup references.</param>
1921
/// <returns>The <see cref="IPathItemHandler"/>.</returns>
20-
IPathItemHandler GetHandler(ODataPathKind pathKind);
22+
IPathItemHandler GetHandler(ODataPathKind pathKind, OpenApiDocument document);
2123
}
2224
}

src/Microsoft.OpenApi.OData.Reader/PathItem/PathItemHandlerProvider.cs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// ------------------------------------------------------------
55

6-
using System.Collections.Generic;
6+
using Microsoft.OpenApi.Models;
77
using Microsoft.OpenApi.OData.Edm;
88

99
namespace Microsoft.OpenApi.OData.PathItem
@@ -13,52 +13,49 @@ namespace Microsoft.OpenApi.OData.PathItem
1313
/// </summary>
1414
internal class PathItemHandlerProvider : IPathItemHandlerProvider
1515
{
16-
private readonly IDictionary<ODataPathKind, IPathItemHandler> _handlers = new Dictionary<ODataPathKind, IPathItemHandler>
16+
/// <inheritdoc/>
17+
public IPathItemHandler GetHandler(ODataPathKind pathKind, OpenApiDocument document)
1718
{
19+
return pathKind switch {
1820
// EntitySet
19-
{ ODataPathKind.EntitySet, new EntitySetPathItemHandler() },
21+
ODataPathKind.EntitySet => new EntitySetPathItemHandler(document),
2022

2123
// Entity
22-
{ ODataPathKind.Entity, new EntityPathItemHandler() },
24+
ODataPathKind.Entity => new EntityPathItemHandler(document),
2325

2426
// Singleton
25-
{ ODataPathKind.Singleton, new SingletonPathItemHandler() },
27+
ODataPathKind.Singleton => new SingletonPathItemHandler(document),
2628

2729
// Navigation property
28-
{ ODataPathKind.NavigationProperty, new NavigationPropertyPathItemHandler() },
30+
ODataPathKind.NavigationProperty => new NavigationPropertyPathItemHandler(document),
2931

3032
// Edm Operation
31-
{ ODataPathKind.Operation, new OperationPathItemHandler() },
33+
ODataPathKind.Operation => new OperationPathItemHandler(document),
3234

3335
// Edm OperationImport
34-
{ ODataPathKind.OperationImport, new OperationImportPathItemHandler() },
36+
ODataPathKind.OperationImport => new OperationImportPathItemHandler(document),
3537

3638
// Edm Ref
37-
{ ODataPathKind.Ref, new RefPathItemHandler() },
39+
ODataPathKind.Ref => new RefPathItemHandler(document),
3840

3941
// Media Entity
40-
{ ODataPathKind.MediaEntity, new MediaEntityPathItemHandler() },
42+
ODataPathKind.MediaEntity => new MediaEntityPathItemHandler(document),
4143

4244
// $Metadata
43-
{ ODataPathKind.Metadata, new MetadataPathItemHandler() },
45+
ODataPathKind.Metadata => new MetadataPathItemHandler(document),
4446

4547
// $count
46-
{ ODataPathKind.DollarCount, new DollarCountPathItemHandler() },
48+
ODataPathKind.DollarCount => new DollarCountPathItemHandler(document),
4749

4850
// ~/groups/{id}/members/microsoft.graph.user
49-
{ ODataPathKind.TypeCast, new ODataTypeCastPathItemHandler() },
51+
ODataPathKind.TypeCast => new ODataTypeCastPathItemHandler(document),
5052

5153
// ~/users/{id}/mailboxSettings
52-
{ ODataPathKind.ComplexProperty, new ComplexPropertyItemHandler() },
54+
ODataPathKind.ComplexProperty => new ComplexPropertyItemHandler(document),
5355

5456
// Unknown
55-
{ ODataPathKind.Unknown, null },
56-
};
57-
58-
/// <inheritdoc/>
59-
public IPathItemHandler GetHandler(ODataPathKind pathKind)
60-
{
61-
return _handlers[pathKind];
57+
_ => null,
58+
};
6259
}
6360
}
6461
}

0 commit comments

Comments
 (0)