Skip to content

Commit 316a0fd

Browse files
committed
feat: draft migrates all path item handler to accept document for lookup
1 parent e87b64c commit 316a0fd

13 files changed

+153
-47
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ namespace Microsoft.OpenApi.OData.PathItem;
1313

1414
internal class ComplexPropertyItemHandler : PathItemHandler
1515
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="ComplexPropertyItemHandler"/> class.
18+
/// </summary>
19+
/// <param name="document">The document to use for references lookup.</param>
20+
public ComplexPropertyItemHandler(OpenApiDocument document) : base(document)
21+
{
22+
23+
}
1624
/// <inheritdoc/>
1725
protected override ODataPathKind HandleKind => ODataPathKind.ComplexProperty;
1826

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ namespace Microsoft.OpenApi.OData.PathItem
1313
/// </summary>
1414
internal class DollarCountPathItemHandler : PathItemHandler
1515
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="DollarCountPathItemHandler"/> class.
18+
/// </summary>
19+
/// <param name="document">The document to use for references lookup.</param>
20+
public DollarCountPathItemHandler(OpenApiDocument document) : base(document)
21+
{
22+
23+
}
1624
/// <inheritdoc/>
1725
protected override ODataPathKind HandleKind => ODataPathKind.DollarCount;
1826

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ namespace Microsoft.OpenApi.OData.PathItem
1616
/// </summary>
1717
internal class EntityPathItemHandler : EntitySetPathItemHandler
1818
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="EntityPathItemHandler"/> class.
21+
/// </summary>
22+
/// <param name="document">The document to use for references lookup.</param>
23+
public EntityPathItemHandler(OpenApiDocument document) : base(document)
24+
{
25+
26+
}
1927
/// <inheritdoc/>
2028
protected override ODataPathKind HandleKind => ODataPathKind.Entity;
2129

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ namespace Microsoft.OpenApi.OData.PathItem
1616
/// </summary>
1717
internal class EntitySetPathItemHandler : PathItemHandler
1818
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="EntitySetPathItemHandler"/> class.
21+
/// </summary>
22+
/// <param name="document">The document to use for references lookup.</param>
23+
public EntitySetPathItemHandler(OpenApiDocument document) : base(document)
24+
{
25+
26+
}
1927
/// <inheritdoc/>
2028
protected override ODataPathKind HandleKind => ODataPathKind.EntitySet;
2129

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ namespace Microsoft.OpenApi.OData.PathItem
1515
/// </summary>
1616
internal class MediaEntityPathItemHandler : PathItemHandler
1717
{
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="MediaEntityPathItemHandler"/> class.
20+
/// </summary>
21+
/// <param name="document">The document to use for references lookup.</param>
22+
public MediaEntityPathItemHandler(OpenApiDocument document) : base(document)
23+
{
24+
25+
}
1826
/// <inheritdoc/>
1927
protected override ODataPathKind HandleKind => ODataPathKind.MediaEntity;
2028

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ namespace Microsoft.OpenApi.OData.PathItem
1313
/// </summary>
1414
internal class MetadataPathItemHandler : PathItemHandler
1515
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="MetadataPathItemHandler"/> class.
18+
/// </summary>
19+
/// <param name="document">The document to use for references lookup.</param>
20+
public MetadataPathItemHandler(OpenApiDocument document) : base(document)
21+
{
22+
23+
}
1624
/// <inheritdoc/>
1725
protected override ODataPathKind HandleKind => ODataPathKind.Metadata;
1826

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

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ namespace Microsoft.OpenApi.OData.PathItem
2222
/// </summary>
2323
internal class NavigationPropertyPathItemHandler : PathItemHandler
2424
{
25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="NavigationPropertyPathItemHandler"/> class.
27+
/// </summary>
28+
/// <param name="document">The document to use for references lookup.</param>
29+
public NavigationPropertyPathItemHandler(OpenApiDocument document) : base(document)
30+
{
31+
32+
}
2533
/// <inheritdoc/>
2634
protected override ODataPathKind HandleKind => ODataPathKind.NavigationProperty;
2735

@@ -75,19 +83,19 @@ protected override void SetOperations(OpenApiPathItem item)
7583
AddGetOperation(item, restriction);
7684

7785
// Update restrictions
78-
UpdateRestrictionsType navPropUpdateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(TargetPath, CapabilitiesConstants.UpdateRestrictions);
79-
navPropUpdateRestrictions?.MergePropertiesIfNull(restriction?.UpdateRestrictions);
86+
UpdateRestrictionsType navPropUpdateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(TargetPath, CapabilitiesConstants.UpdateRestrictions);
87+
navPropUpdateRestrictions?.MergePropertiesIfNull(restriction?.UpdateRestrictions);
8088
navPropUpdateRestrictions ??= restriction?.UpdateRestrictions;
8189
UpdateRestrictionsType updateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(NavigationProperty);
82-
navPropUpdateRestrictions?.MergePropertiesIfNull(updateRestrictions);
90+
navPropUpdateRestrictions?.MergePropertiesIfNull(updateRestrictions);
8391
navPropUpdateRestrictions ??= updateRestrictions;
8492

8593
// Insert restrictions
86-
InsertRestrictionsType navPropInsertRestrictions = Context.Model.GetRecord<InsertRestrictionsType>(TargetPath, CapabilitiesConstants.InsertRestrictions);
87-
navPropInsertRestrictions?.MergePropertiesIfNull(restriction?.InsertRestrictions);
94+
InsertRestrictionsType navPropInsertRestrictions = Context.Model.GetRecord<InsertRestrictionsType>(TargetPath, CapabilitiesConstants.InsertRestrictions);
95+
navPropInsertRestrictions?.MergePropertiesIfNull(restriction?.InsertRestrictions);
8896
navPropInsertRestrictions ??= restriction?.InsertRestrictions;
8997
InsertRestrictionsType insertRestrictions = Context.Model.GetRecord<InsertRestrictionsType>(NavigationProperty);
90-
navPropInsertRestrictions?.MergePropertiesIfNull(insertRestrictions);
98+
navPropInsertRestrictions?.MergePropertiesIfNull(insertRestrictions);
9199
navPropInsertRestrictions ??= insertRestrictions;
92100

93101
// Entity insert restrictions
@@ -162,11 +170,11 @@ protected override void SetOperations(OpenApiPathItem item)
162170

163171
private void AddGetOperation(OpenApiPathItem item, NavigationPropertyRestriction restriction)
164172
{
165-
ReadRestrictionsType navPropReadRestriction = Context.Model.GetRecord<ReadRestrictionsType>(TargetPath, CapabilitiesConstants.ReadRestrictions);
166-
navPropReadRestriction?.MergePropertiesIfNull(restriction?.ReadRestrictions);
173+
ReadRestrictionsType navPropReadRestriction = Context.Model.GetRecord<ReadRestrictionsType>(TargetPath, CapabilitiesConstants.ReadRestrictions);
174+
navPropReadRestriction?.MergePropertiesIfNull(restriction?.ReadRestrictions);
167175
navPropReadRestriction ??= restriction?.ReadRestrictions;
168176
ReadRestrictionsType readRestrictions = Context.Model.GetRecord<ReadRestrictionsType>(NavigationProperty);
169-
navPropReadRestriction?.MergePropertiesIfNull(readRestrictions);
177+
navPropReadRestriction?.MergePropertiesIfNull(readRestrictions);
170178
navPropReadRestriction ??= readRestrictions;
171179

172180
ReadRestrictionsType entityReadRestriction = Context.Model.GetRecord<ReadRestrictionsType>(_navPropEntityType);
@@ -212,54 +220,54 @@ private void AddDeleteOperation(OpenApiPathItem item, NavigationPropertyRestrict
212220
{
213221
Debug.Assert(!LastSegmentIsRefSegment);
214222

215-
DeleteRestrictionsType navPropDeleteRestriction = Context.Model.GetRecord<DeleteRestrictionsType>(TargetPath, CapabilitiesConstants.DeleteRestrictions);
216-
navPropDeleteRestriction?.MergePropertiesIfNull(restriction?.DeleteRestrictions);
223+
DeleteRestrictionsType navPropDeleteRestriction = Context.Model.GetRecord<DeleteRestrictionsType>(TargetPath, CapabilitiesConstants.DeleteRestrictions);
224+
navPropDeleteRestriction?.MergePropertiesIfNull(restriction?.DeleteRestrictions);
217225
navPropDeleteRestriction ??= restriction?.DeleteRestrictions;
218226
DeleteRestrictionsType insertRestrictions = Context.Model.GetRecord<DeleteRestrictionsType>(NavigationProperty);
219-
navPropDeleteRestriction?.MergePropertiesIfNull(insertRestrictions);
220-
navPropDeleteRestriction ??= insertRestrictions;
221-
222-
if (!(NavigationProperty.TargetMultiplicity() != EdmMultiplicity.Many || LastSegmentIsKeySegment))
223-
return;
224-
225-
DeleteRestrictionsType entityDeleteRestriction = Context.Model.GetRecord<DeleteRestrictionsType>(_navPropEntityType);
226-
bool isDeletable =
227-
(navPropDeleteRestriction == null && entityDeleteRestriction == null) ||
228-
((entityDeleteRestriction?.IsDeletable ?? true) &&
229-
(navPropDeleteRestriction?.IsDeletable ?? true));
230-
227+
navPropDeleteRestriction?.MergePropertiesIfNull(insertRestrictions);
228+
navPropDeleteRestriction ??= insertRestrictions;
229+
230+
if (!(NavigationProperty.TargetMultiplicity() != EdmMultiplicity.Many || LastSegmentIsKeySegment))
231+
return;
232+
233+
DeleteRestrictionsType entityDeleteRestriction = Context.Model.GetRecord<DeleteRestrictionsType>(_navPropEntityType);
234+
bool isDeletable =
235+
(navPropDeleteRestriction == null && entityDeleteRestriction == null) ||
236+
((entityDeleteRestriction?.IsDeletable ?? true) &&
237+
(navPropDeleteRestriction?.IsDeletable ?? true));
238+
231239
if (NavigationProperty.ContainsTarget && isDeletable)
232-
{
233-
AddOperation(item, OperationType.Delete);
240+
{
241+
AddOperation(item, OperationType.Delete);
234242
}
235-
else if (navPropDeleteRestriction?.Deletable ?? false)
236-
{
237-
// Add delete operation for non-contained nav. props only if explicitly set to true via annotation
238-
// Note: Use Deletable and NOT IsDeletable
239-
AddOperation(item, OperationType.Delete);
243+
else if (navPropDeleteRestriction?.Deletable ?? false)
244+
{
245+
// Add delete operation for non-contained nav. props only if explicitly set to true via annotation
246+
// Note: Use Deletable and NOT IsDeletable
247+
AddOperation(item, OperationType.Delete);
240248
}
241249

242250
return;
243251
}
244252

245253
private void AddUpdateOperation(OpenApiPathItem item, UpdateRestrictionsType updateRestrictionsType)
246254
{
247-
if (updateRestrictionsType?.IsUpdatable ?? true)
248-
{
249-
if (updateRestrictionsType?.IsUpdateMethodPutAndPatch == true)
250-
{
251-
AddOperation(item, OperationType.Put);
252-
AddOperation(item, OperationType.Patch);
253-
}
254-
else if (updateRestrictionsType?.IsUpdateMethodPut == true)
255-
{
256-
AddOperation(item, OperationType.Put);
257-
}
258-
else
259-
{
260-
AddOperation(item, OperationType.Patch);
261-
}
262-
}
255+
if (updateRestrictionsType?.IsUpdatable ?? true)
256+
{
257+
if (updateRestrictionsType?.IsUpdateMethodPutAndPatch == true)
258+
{
259+
AddOperation(item, OperationType.Put);
260+
AddOperation(item, OperationType.Patch);
261+
}
262+
else if (updateRestrictionsType?.IsUpdateMethodPut == true)
263+
{
264+
AddOperation(item, OperationType.Put);
265+
}
266+
else
267+
{
268+
AddOperation(item, OperationType.Patch);
269+
}
270+
}
263271

264272
}
265273

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ namespace Microsoft.OpenApi.OData.PathItem;
1515
/// </summary>
1616
internal class ODataTypeCastPathItemHandler : PathItemHandler
1717
{
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="ODataTypeCastPathItemHandler"/> class.
20+
/// </summary>
21+
/// <param name="document">The document to use for references lookup.</param>
22+
public ODataTypeCastPathItemHandler(OpenApiDocument document) : base(document)
23+
{
24+
25+
}
1826
/// <inheritdoc/>
1927
protected override ODataPathKind HandleKind => ODataPathKind.TypeCast;
2028

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ namespace Microsoft.OpenApi.OData.PathItem
1616
/// </summary>
1717
internal class OperationImportPathItemHandler : PathItemHandler
1818
{
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="OperationImportPathItemHandler"/> class.
21+
/// </summary>
22+
/// <param name="document">The document to use for references lookup.</param>
23+
public OperationImportPathItemHandler(OpenApiDocument document) : base(document)
24+
{
25+
26+
}
1927
/// <inheritdoc/>
2028
protected override ODataPathKind HandleKind => ODataPathKind.OperationImport;
2129

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ namespace Microsoft.OpenApi.OData.PathItem
1919
/// </summary>
2020
internal class OperationPathItemHandler : PathItemHandler
2121
{
22+
/// <summary>
23+
/// Initializes a new instance of the <see cref="OperationPathItemHandler"/> class.
24+
/// </summary>
25+
/// <param name="document">The document to use for references lookup.</param>
26+
public OperationPathItemHandler(OpenApiDocument document) : base(document)
27+
{
28+
29+
}
2230
/// <inheritdoc/>
2331
protected override ODataPathKind HandleKind => ODataPathKind.Operation;
2432

0 commit comments

Comments
 (0)