@@ -19,17 +19,17 @@ namespace Microsoft.OpenApi.OData.Edm
1919 /// </summary>
2020 public class ODataPathProvider : IODataPathProvider
2121 {
22- private IDictionary < IEdmEntityType , IList < IEdmNavigationSource > > _allNavigationSources ;
22+ private Dictionary < IEdmEntityType , IList < IEdmNavigationSource > > ? _allNavigationSources ;
2323
24- private IDictionary < IEdmEntityType , IList < ODataPath > > _allNavigationSourcePaths =
24+ private readonly IDictionary < IEdmEntityType , IList < ODataPath > > _allNavigationSourcePaths =
2525 new Dictionary < IEdmEntityType , IList < ODataPath > > ( ) ;
2626
27- private IDictionary < IEdmEntityType , IList < ODataPath > > _allNavigationPropertyPaths =
27+ private readonly IDictionary < IEdmEntityType , IList < ODataPath > > _allNavigationPropertyPaths =
2828 new Dictionary < IEdmEntityType , IList < ODataPath > > ( ) ;
2929
30- private IList < ODataPath > _allOperationPaths = new List < ODataPath > ( ) ;
30+ private readonly List < ODataPath > _allOperationPaths = [ ] ;
3131
32- private IEdmModel _model ;
32+ private IEdmModel ? _model ;
3333
3434 private readonly IDictionary < IEdmEntityType , IList < ODataPath > > _dollarCountPaths =
3535 new Dictionary < IEdmEntityType , IList < ODataPath > > ( ) ;
@@ -52,7 +52,7 @@ public virtual IEnumerable<ODataPath> GetPaths(IEdmModel model, OpenApiConvertSe
5252 {
5353 if ( model == null || model . EntityContainer == null )
5454 {
55- return Enumerable . Empty < ODataPath > ( ) ;
55+ return [ ] ;
5656 }
5757
5858 Initialize ( model ) ;
@@ -734,7 +734,7 @@ private void CreateTypeCastPaths(ODataPath currentPath, OpenApiConvertSettings c
734734 if ( ! convertSettings . EnableODataTypeCast )
735735 return ;
736736
737- var annotedTypeNames = GetDerivedTypeConstaintTypeNames ( annotable ) ;
737+ var annotedTypeNames = GetDerivedTypeConstraintTypeNames ( annotable ) ;
738738
739739 if ( ! annotedTypeNames . Any ( ) && convertSettings . RequireDerivedTypesConstraintForODataTypeCastSegments )
740740 return ; // we don't want to generate any downcast path item if there is no type cast annotation.
@@ -1099,11 +1099,11 @@ private bool HasUnsatisfiedDerivedTypeConstraint(
10991099 OpenApiConvertSettings convertSettings )
11001100 {
11011101 return convertSettings . RequireDerivedTypesConstraintForBoundOperations &&
1102- ! GetDerivedTypeConstaintTypeNames ( annotatable )
1102+ ! GetDerivedTypeConstraintTypeNames ( annotatable )
11031103 . Any ( c => c . Equals ( baseType . FullName ( ) , StringComparison . OrdinalIgnoreCase ) ) ;
11041104 }
1105- private IEnumerable < string > GetDerivedTypeConstaintTypeNames ( IEdmVocabularyAnnotatable annotatable ) =>
1106- _model . GetCollection ( annotatable , "Org.OData.Validation.V1.DerivedTypeConstraint" ) ?? Enumerable . Empty < string > ( ) ;
1105+ private IEnumerable < string > GetDerivedTypeConstraintTypeNames ( IEdmVocabularyAnnotatable annotatable ) =>
1106+ _model ? . GetCollection ( annotatable , "Org.OData.Validation.V1.DerivedTypeConstraint" ) ?? [ ] ;
11071107
11081108 private void AppendBoundOperationOnDerivedNavigationPropertyPath (
11091109 IEdmOperation edmOperation ,
@@ -1112,11 +1112,11 @@ private void AppendBoundOperationOnDerivedNavigationPropertyPath(
11121112 OpenApiConvertSettings convertSettings )
11131113 {
11141114 if ( ! convertSettings . AppendBoundOperationsOnDerivedTypeCastSegments ) return ;
1115- bool isEscapedFunction = _model . IsUrlEscapeFunction ( edmOperation ) ;
1115+ bool isEscapedFunction = _model ? . IsUrlEscapeFunction ( edmOperation ) ?? false ;
11161116
11171117 foreach ( var baseType in bindingEntityType . FindAllBaseTypes ( ) )
11181118 {
1119- if ( _allNavigationPropertyPaths . TryGetValue ( baseType , out IList < ODataPath > paths ) )
1119+ if ( _allNavigationPropertyPaths . TryGetValue ( baseType , out var paths ) )
11201120 {
11211121 foreach ( var path in paths . Where ( x => ! _pathKindToSkipForNavigationProperties . Contains ( x . Kind ) ) )
11221122 {
@@ -1126,7 +1126,7 @@ private void AppendBoundOperationOnDerivedNavigationPropertyPath(
11261126 continue ;
11271127 }
11281128
1129- if ( ! EdmModelHelper . IsOperationAllowed ( _model , edmOperation , npSegment . NavigationProperty , npSegment . NavigationProperty . ContainsTarget ) )
1129+ if ( _model is not null && ! EdmModelHelper . IsOperationAllowed ( _model , edmOperation , npSegment . NavigationProperty , npSegment . NavigationProperty . ContainsTarget ) )
11301130 {
11311131 continue ;
11321132 }
@@ -1173,7 +1173,7 @@ private void AppendBoundOperationOnDerivedNavigationPropertyPath(
11731173
11741174 private void AppendBoundOperationOnOperationPath ( IEdmOperation edmOperation , bool isCollection , IEdmEntityType bindingEntityType )
11751175 {
1176- bool isEscapedFunction = _model . IsUrlEscapeFunction ( edmOperation ) ;
1176+ bool isEscapedFunction = _model ? . IsUrlEscapeFunction ( edmOperation ) ?? false ;
11771177
11781178 // only composable functions
11791179 var paths = _allOperationPaths . Where ( x => x . LastSegment is ODataOperationSegment operationSegment
@@ -1187,7 +1187,7 @@ private void AppendBoundOperationOnOperationPath(IEdmOperation edmOperation, boo
11871187 || operationSegment . Operation is not IEdmFunction edmFunction || ! edmFunction . IsComposable
11881188 || edmFunction . ReturnType == null || ! edmFunction . ReturnType . Definition . Equals ( bindingEntityType )
11891189 || isCollection
1190- || ! EdmModelHelper . IsOperationAllowed ( _model , edmOperation , operationSegment . Operation , true ) )
1190+ || _model is not null && ! EdmModelHelper . IsOperationAllowed ( _model , edmOperation , operationSegment . Operation , true ) )
11911191 {
11921192 continue ;
11931193 }
@@ -1199,7 +1199,10 @@ private void AppendBoundOperationOnOperationPath(IEdmOperation edmOperation, boo
11991199 }
12001200
12011201 ODataPath newOperationPath = path . Clone ( ) ;
1202- newOperationPath . Push ( new ODataOperationSegment ( edmOperation , isEscapedFunction , _model ) ) ;
1202+ if ( _model is not null )
1203+ {
1204+ newOperationPath . Push ( new ODataOperationSegment ( edmOperation , isEscapedFunction , _model ) ) ;
1205+ }
12031206 AppendPath ( newOperationPath ) ;
12041207 }
12051208 }
0 commit comments