Skip to content

Commit 661b05a

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

17 files changed

+48
-48
lines changed

src/Microsoft.OpenApi.OData.Reader/Common/CryptographyExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static string GetHashSHA256(this string input)
2222
Utils.CheckArgumentNull(input, nameof(input));
2323

2424
var inputBytes = Encoding.UTF8.GetBytes(input);
25-
var hashBytes = hasher.Value.ComputeHash(inputBytes);
25+
if (hasher.Value?.ComputeHash(inputBytes) is not {} hashBytes) return string.Empty;
2626
var hash = new StringBuilder();
2727
foreach (var b in hashBytes)
2828
{

src/Microsoft.OpenApi.OData.Reader/Common/EdmModelHelper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ internal static bool NavigationRestrictionsAllowsNavigability(
9595
{
9696
items[lastItemIndex] = prefix + Utils.UpperFirstChar(items[lastItemIndex]);
9797
}
98-
else
98+
else if (Utils.UpperFirstChar(items[lastItemIndex]) is string lastIdentifier)
9999
{
100-
items[lastItemIndex] = Utils.UpperFirstChar(items[lastItemIndex]);
100+
items[lastItemIndex] = lastIdentifier;
101101
}
102102

103103
return GenerateNavigationPropertyPathOperationId(items);
@@ -122,9 +122,9 @@ internal static bool NavigationRestrictionsAllowsNavigability(
122122
{
123123
items.Add(prefix + Utils.UpperFirstChar(lastSegmentIdentifier));
124124
}
125-
else
125+
else if (Utils.UpperFirstChar(lastSegmentIdentifier) is string lastIdentifier)
126126
{
127-
items.Add(Utils.UpperFirstChar(lastSegmentIdentifier));
127+
items.Add(lastIdentifier);
128128
}
129129

130130
return GenerateNavigationPropertyPathOperationId(items);
@@ -327,7 +327,7 @@ internal static string GenerateComplexPropertyPathTagName(ODataPath path, ODataC
327327

328328
List<string> tagNameItems = tagName?.Split('.').ToList() ?? [];
329329

330-
if (tagNameItems.Count < context.Settings.TagDepth)
330+
if (tagNameItems.Count < context.Settings.TagDepth && complexSegment.ComplexType is not null)
331331
{
332332
tagNameItems.Add(complexSegment.ComplexType.Name);
333333
}

src/Microsoft.OpenApi.OData.Reader/Common/Utils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static class Utils
4545
/// </summary>
4646
/// <param name="input">The input string.</param>
4747
/// <returns>The changed string.</returns>
48-
public static string? UpperFirstChar(string input)
48+
public static string? UpperFirstChar(string? input)
4949
{
5050
if (input == null)
5151
{

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ internal static class EdmVocabularyAnnotationExtensions
128128
public static T? GetRecord<T>(this IEdmModel model, IEdmVocabularyAnnotatable target)
129129
where T : class, IRecord, new()
130130
{
131-
string qualifiedName = Utils.GetTermQualifiedName<T>();
132-
return model.GetRecord<T>(target, qualifiedName);
131+
return Utils.GetTermQualifiedName<T>() is string qualifiedName ? model.GetRecord<T>(target, qualifiedName) : null;
133132
}
134133

135134
/// <summary>
@@ -243,8 +242,7 @@ internal static class EdmVocabularyAnnotationExtensions
243242
public static IEnumerable<T>? GetCollection<T>(this IEdmModel model, IEdmVocabularyAnnotatable target)
244243
where T : IRecord, new()
245244
{
246-
string qualifiedName = Utils.GetTermQualifiedName<T>();
247-
return GetCollection<T>(model, target, qualifiedName);
245+
return Utils.GetTermQualifiedName<T>() is string qualifiedName ? GetCollection<T>(model, target, qualifiedName) : null;
248246
}
249247

250248
/// <summary>
@@ -349,9 +347,8 @@ internal static class EdmVocabularyAnnotationExtensions
349347
Debug.Assert(e.ExpressionKind == EdmExpressionKind.Record);
350348

351349
IEdmRecordExpression recordExpression = (IEdmRecordExpression)e;
352-
Authorization auth = Authorization.CreateAuthorization(recordExpression);
353-
return auth;
354-
});
350+
return Authorization.CreateAuthorization(recordExpression);
351+
}).OfType<Authorization>();
355352
}
356353
}
357354
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public static Dictionary<IEdmEntityType, IList<IEdmNavigationSource>> LoadAllNav
109109
/// </summary>
110110
/// <param name="entityType">The given entity type.</param>
111111
/// <returns>All base types or null.</returns>
112-
public static IEnumerable<IEdmEntityType>? FindAllBaseTypes(this IEdmEntityType entityType)
112+
public static IEnumerable<IEdmEntityType> FindAllBaseTypes(this IEdmEntityType entityType)
113113
{
114114
if (entityType == null)
115115
{
@@ -129,7 +129,7 @@ public static Dictionary<IEdmEntityType, IList<IEdmNavigationSource>> LoadAllNav
129129
/// </summary>
130130
/// <param name="complexType">The given complex type.</param>
131131
/// <returns>All base types or null.</returns>
132-
public static IEnumerable<IEdmComplexType>? FindAllBaseTypes(this IEdmComplexType complexType)
132+
public static IEnumerable<IEdmComplexType> FindAllBaseTypes(this IEdmComplexType complexType)
133133
{
134134
if (complexType == null)
135135
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public ODataNavigationPropertySegment(IEdmNavigationProperty navigationProperty)
4242
/// <inheritdoc />
4343
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
4444
{
45-
return new IEdmVocabularyAnnotatable[] { NavigationProperty, EntityType }.Union(EntityType.FindAllBaseTypes());
45+
return new IEdmVocabularyAnnotatable[] { NavigationProperty, EntityType }.Union(EntityType.FindAllBaseTypes() ?? []);
4646
}
4747

4848
/// <inheritdoc />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private ODataRefSegment()
2828
}
2929

3030
/// <inheritdoc />
31-
public override IEdmEntityType EntityType => null;
31+
public override IEdmEntityType? EntityType => null;
3232

3333
/// <inheritdoc />
3434
public override ODataSegmentKind Kind => ODataSegmentKind.Ref;

src/Microsoft.OpenApi.OData.Reader/Edm/ODataStreamContentSegment.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 ODataStreamContentSegment : ODataSegment
1717
{
1818
/// <inheritdoc />
19-
public override IEdmEntityType EntityType => null;
19+
public override IEdmEntityType? EntityType => null;
2020
/// <inheritdoc />
2121
public override ODataSegmentKind Kind => ODataSegmentKind.StreamContent;
2222

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public ODataStreamPropertySegment(string streamPropertyName)
2626
}
2727

2828
/// <inheritdoc />
29-
public override IEdmEntityType EntityType => null;
29+
public override IEdmEntityType? EntityType => null;
3030

3131
/// <inheritdoc />
3232
public override ODataSegmentKind Kind => ODataSegmentKind.StreamProperty;

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using Microsoft.OpenApi.Models;
99
using Microsoft.OpenApi.OData.Common;
1010
using Microsoft.OpenApi.OData.Edm;
11-
using Microsoft.OpenApi.OData.Vocabulary.Authorization;
1211
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
1312
using Microsoft.OpenApi.Models.References;
1413

@@ -36,12 +35,16 @@ public static IEnumerable<OpenApiSecurityRequirement> CreateSecurityRequirements
3635
{
3736
foreach (PermissionType permission in permissions)
3837
{
38+
if (string.IsNullOrEmpty(permission.SchemeName))
39+
{
40+
continue;
41+
}
3942
yield return new OpenApiSecurityRequirement
4043
{
4144
[
4245
new OpenApiSecuritySchemeReference(permission.SchemeName, document)
43-
] = new List<string>(permission.Scopes?.Select(c => c.Scope) ?? new List<string>())
44-
};
46+
] = [.. permission.Scopes?.Select(c => c.Scope).OfType<string>() ?? []]
47+
};
4548
}
4649
}
4750
}

0 commit comments

Comments
 (0)