@@ -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
0 commit comments