Skip to content

Commit b15301d

Browse files
committed
chore: additional NRT fixes
Signed-off-by: Vincent Biret <[email protected]>
1 parent 661b05a commit b15301d

16 files changed

+51
-40
lines changed

src/Microsoft.OpenApi.OData.Reader/Edm/ODataDollarCountSegment.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ public class ODataDollarCountSegment : ODataSegment
1717
/// <summary>
1818
/// Get the static instance of $count segment.
1919
/// </summary>
20-
internal static ODataDollarCountSegment Instance = new();
20+
internal static readonly ODataDollarCountSegment Instance = new();
2121

2222
/// <inheritdoc />
23-
public override IEdmEntityType EntityType => null;
23+
public override IEdmEntityType? EntityType => null;
2424

2525
/// <inheritdoc />
2626
public override ODataSegmentKind Kind => ODataSegmentKind.DollarCount;

src/Microsoft.OpenApi.OData.Reader/Edm/ODataKeySegment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public override string Identifier
5959
get
6060
{
6161
IList<string> keys = IsAlternateKey ?
62-
KeyMappings.Values.ToList() :
62+
KeyMappings?.Values.ToList() ?? [] :
6363
EntityType.Key().Select(static x => x.Name).ToList();
6464

6565
return string.Join(",", keys);

src/Microsoft.OpenApi.OData.Reader/Edm/ODataMetadataSegment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.OpenApi.OData.Edm
1616
public class ODataMetadataSegment : ODataSegment
1717
{
1818
/// <inheritdoc />
19-
public override IEdmEntityType EntityType => null;
19+
public override IEdmEntityType? EntityType => null;
2020
/// <inheritdoc />
2121
public override ODataSegmentKind Kind => ODataSegmentKind.Metadata;
2222

src/Microsoft.OpenApi.OData.Reader/Edm/ODataNavigationSourceSegment.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ public ODataNavigationSourceSegment(IEdmNavigationSource navigationSource)
4242
/// <inheritdoc />
4343
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
4444
{
45-
return new IEdmVocabularyAnnotatable[] { NavigationSource as IEdmVocabularyAnnotatable, EntityType }.Union(EntityType.FindAllBaseTypes());
45+
return (NavigationSource is IEdmVocabularyAnnotatable source ? new IEdmVocabularyAnnotatable[]{source} : [])
46+
.Union([EntityType])
47+
.Union(EntityType.FindAllBaseTypes());
4648
}
4749

4850
/// <inheritdoc />

src/Microsoft.OpenApi.OData.Reader/Edm/ODataPathProvider.cs

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,40 @@ public virtual IEnumerable<ODataPath> GetPaths(IEdmModel model, OpenApiConvertSe
5757

5858
Initialize(model);
5959

60-
// entity set
61-
foreach (IEdmEntitySet entitySet in _model.EntityContainer.EntitySets())
60+
if (_model is not null)
6261
{
63-
if (CanFilter(entitySet))
64-
{
65-
RetrieveNavigationSourcePaths(entitySet, settings);
66-
}
67-
}
62+
// entity set
63+
foreach (var entitySet in _model.EntityContainer.EntitySets())
64+
{
65+
if (CanFilter(entitySet))
66+
{
67+
RetrieveNavigationSourcePaths(entitySet, settings);
68+
}
69+
}
6870

69-
// singleton
70-
foreach (IEdmSingleton singleton in _model.EntityContainer.Singletons())
71-
{
72-
if (CanFilter(singleton))
73-
{
74-
RetrieveNavigationSourcePaths(singleton, settings);
75-
}
71+
// singleton
72+
foreach (var singleton in _model.EntityContainer.Singletons())
73+
{
74+
if (CanFilter(singleton))
75+
{
76+
RetrieveNavigationSourcePaths(singleton, settings);
77+
}
78+
}
7679
}
7780

7881
// bound operations
7982
RetrieveBoundOperationPaths(settings);
8083

81-
// unbound operations
82-
foreach (IEdmOperationImport import in _model.EntityContainer.OperationImports())
84+
if (_model is not null)
8385
{
84-
if (CanFilter(import))
85-
{
86-
AppendPath(new ODataPath(new ODataOperationImportSegment(import)));
87-
}
86+
// unbound operations
87+
foreach (IEdmOperationImport import in _model.EntityContainer.OperationImports())
88+
{
89+
if (CanFilter(import))
90+
{
91+
AppendPath(new ODataPath(new ODataOperationImportSegment(import)));
92+
}
93+
}
8894
}
8995

9096
return MergePaths();

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ public static void AddComponentsToDocument(this ODataContext context, OpenApiDoc
3232
context.AddRequestBodiesToDocument(document);
3333
context.AddExamplesToDocument(document);
3434
context.AddSecuritySchemesToDocument(document);
35-
document.Components.Links = null;
36-
document.Components.Callbacks = null;
37-
document.Components.Extensions = null;
35+
if (document.Components is not null)
36+
{
37+
document.Components.Links = null;
38+
document.Components.Callbacks = null;
39+
document.Components.Extensions = null;
40+
}
3841
}
3942
}
4043
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void AddExamplesToDocument(this ODataContext context, OpenApiDocum
4747
}
4848
}
4949

50-
private static OpenApiExample CreateExample(this ODataContext context, IEdmType edmType, OpenApiDocument document)
50+
private static OpenApiExample? CreateExample(this ODataContext context, IEdmType edmType, OpenApiDocument document)
5151
{
5252
Debug.Assert(context != null);
5353
Debug.Assert(edmType != null);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void AddPathItemsToDocument(this ODataContext context, OpenApiDocu
3939
settings.EnableKeyAsSegment = context.KeyAsSegment;
4040
foreach (ODataPath path in context.AllPaths)
4141
{
42-
IPathItemHandler handler = context.PathItemHandlerProvider.GetHandler(path.Kind, document);
42+
var handler = context.PathItemHandlerProvider.GetHandler(path.Kind, document);
4343
if (handler == null)
4444
{
4545
continue;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ public static OpenApiResponses CreateResponses(this ODataContext context, IEdmOp
121121

122122
OpenApiResponses responses = new();
123123

124-
if (operation.IsAction() && operation.ReturnType == null)
124+
if (operation.IsAction() && operation.ReturnType == null && Constants.StatusCode204.GetResponse(document) is {} x204Response)
125125
{
126-
responses.Add(Constants.StatusCode204, Constants.StatusCode204.GetResponse(document));
126+
responses.Add(Constants.StatusCode204, x204Response);
127127
}
128128
else if (context.Model.OperationTargetsMultiplePaths(operation))
129129
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ protected override void SetParameters(OpenApiOperation operation)
4040
return;
4141
}
4242

43-
if (OperationImportSegment.ParameterMappings != null &&
43+
if (OperationImportSegment?.ParameterMappings != null &&
4444
Context?.CreateParameters(functionImport.Function, _document, OperationImportSegment.ParameterMappings) is {} functionParamMappings)
4545
{
4646
operation.Parameters ??= [];

0 commit comments

Comments
 (0)