Skip to content

Commit db8b41a

Browse files
committed
chore: additional NRT fixes
Signed-off-by: Vincent Biret <[email protected]>
1 parent 3ae498c commit db8b41a

File tree

10 files changed

+74
-70
lines changed

10 files changed

+74
-70
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ internal static string GenerateComplexPropertyPathTagName(ODataPath path, ODataC
433433
/// <param name="model">Optional: The Edm model. Used for searching for the namespace alias.</param>
434434
/// <param name="settings">The OpenAPI convert settings.</param>
435435
/// <returns>The element name, alias-prefixed or namespace-stripped if applicable.</returns>
436-
internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, OpenApiConvertSettings settings, IEdmModel model = null)
436+
internal static string StripOrAliasNamespacePrefix(IEdmSchemaElement element, OpenApiConvertSettings settings, IEdmModel? model = null)
437437
{
438438
Utils.CheckArgumentNull(element, nameof(element));
439439
Utils.CheckArgumentNull(settings, nameof(settings));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal static class OpenApiOperationExtensions
2424
/// <param name="addNoContent">Optional: Whether to add a 204 no content response.</param>
2525
/// <param name="schema">Optional: The OpenAPI schema of the response.</param>
2626
/// <param name="document">The OpenAPI document to lookup references.</param>
27-
public static void AddErrorResponses(this OpenApiOperation operation, OpenApiConvertSettings settings, OpenApiDocument document, bool addNoContent = false, IOpenApiSchema schema = null)
27+
public static void AddErrorResponses(this OpenApiOperation operation, OpenApiConvertSettings settings, OpenApiDocument document, bool addNoContent = false, IOpenApiSchema? schema = null)
2828
{
2929
Utils.CheckArgumentNull(operation, nameof(operation));
3030
Utils.CheckArgumentNull(settings, nameof(settings));
@@ -39,7 +39,7 @@ public static void AddErrorResponses(this OpenApiOperation operation, OpenApiCon
3939
{
4040
if (settings.UseSuccessStatusCodeRange)
4141
{
42-
OpenApiResponse response = null;
42+
OpenApiResponse? response = null;
4343
if (schema != null)
4444
{
4545
response = new()

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public static class Utils
2828
/// </summary>
2929
/// <typeparam name="T">The type of the term.</typeparam>
3030
/// <returns>The qualified name.</returns>
31-
public static string GetTermQualifiedName<T>()
31+
public static string? GetTermQualifiedName<T>()
3232
{
3333
object[] attributes = typeof(T).GetCustomAttributes(typeof(TermAttribute), false);
34-
if (attributes == null && attributes.Length == 0)
34+
if (attributes == null || attributes.Length == 0)
3535
{
3636
return null;
3737
}
@@ -45,7 +45,7 @@ public static string GetTermQualifiedName<T>()
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
{
@@ -129,7 +129,7 @@ internal static string ToFirstCharacterLowerCase(this string input)
129129
/// </summary>
130130
/// <param name="path">The <see cref="ODataPath"/>.</param>
131131
/// <param name="navigationPropertyName">Optional: The navigation property name.</param>
132-
internal static string NavigationPropertyPath(this ODataPath path, string navigationPropertyName = null)
132+
internal static string NavigationPropertyPath(this ODataPath path, string? navigationPropertyName = null)
133133
{
134134
string value = string.Join("/",
135135
path.Segments.OfType<ODataNavigationPropertySegment>().Select(e => e.Identifier));
@@ -176,7 +176,7 @@ private static Dictionary<string, string> GetCustomXMLAttributesValueMapping(IEd
176176
{
177177
Dictionary<string, string> attributesValueMap = new();
178178

179-
if ((!customXMLAttributesMapping?.Any() ?? true) ||
179+
if (customXMLAttributesMapping is not {Count:>0} ||
180180
model == null ||
181181
element == null)
182182
{
@@ -187,10 +187,10 @@ private static Dictionary<string, string> GetCustomXMLAttributesValueMapping(IEd
187187
{
188188
string attributeName = item.Key.Split(':').Last(); // example, 'ags:IsHidden' --> 'IsHidden'
189189
string extensionName = item.Value;
190-
EdmStringConstant customXMLAttribute = model.DirectValueAnnotationsManager.GetDirectValueAnnotations(element)?
190+
var customXMLAttribute = model.DirectValueAnnotationsManager.GetDirectValueAnnotations(element)?
191191
.Where(x => x.Name.Equals(attributeName, StringComparison.OrdinalIgnoreCase))?
192192
.FirstOrDefault()?.Value as EdmStringConstant;
193-
string attributeValue = customXMLAttribute?.Value;
193+
var attributeValue = customXMLAttribute?.Value;
194194

195195
if (!string.IsNullOrEmpty(attributeValue))
196196
{
@@ -253,7 +253,7 @@ internal static bool IsBaseTypeReferencedAsTypeInModel(
253253
/// </summary>
254254
/// <param name="segment">The target <see cref="ODataSegment"/>.</param>
255255
/// <returns>The entity type of the target <paramref name="segment"/>.</returns>
256-
internal static IEdmEntityType EntityTypeFromPathSegment(this ODataSegment segment)
256+
internal static IEdmEntityType? EntityTypeFromPathSegment(this ODataSegment segment)
257257
{
258258
CheckArgumentNull(segment, nameof(segment));
259259

@@ -279,12 +279,12 @@ internal static IEdmEntityType EntityTypeFromPathSegment(this ODataSegment segme
279279
/// </summary>
280280
/// <param name="segment">The target <see cref="ODataOperationSegment"/>.</param>
281281
/// <returns>The entity type of the target <paramref name="segment"/>.</returns>
282-
private static IEdmEntityType EntityTypeFromOperationSegment(this ODataSegment segment)
282+
private static IEdmEntityType? EntityTypeFromOperationSegment(this ODataSegment segment)
283283
{
284284
CheckArgumentNull(segment, nameof(segment));
285285

286286
if (segment is ODataOperationSegment operationSegment &&
287-
operationSegment.Operation.Parameters.FirstOrDefault() is IEdmOperationParameter bindingParameter)
287+
operationSegment.Operation?.Parameters.FirstOrDefault() is IEdmOperationParameter bindingParameter)
288288
{
289289
IEdmTypeReference bindingType = bindingParameter.Type;
290290

@@ -339,10 +339,10 @@ internal static bool TryAddPath(this IDictionary<string, IOpenApiPathItem> pathI
339339
}
340340

341341
ODataSegment lastSecondSegment = path.Segments.ElementAt(path.Count - secondLastSegmentIndex);
342-
IEdmEntityType boundEntityType = lastSecondSegment?.EntityTypeFromPathSegment();
342+
var boundEntityType = lastSecondSegment?.EntityTypeFromPathSegment();
343343

344-
IEdmEntityType operationEntityType = lastSegment.EntityTypeFromOperationSegment();
345-
IEnumerable<IEdmStructuredType> derivedTypes = (operationEntityType != null)
344+
var operationEntityType = lastSegment.EntityTypeFromOperationSegment();
345+
var derivedTypes = (operationEntityType != null)
346346
? context.Model.FindAllDerivedTypes(operationEntityType)
347347
: null;
348348

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public ODataComplexPropertySegment(IEdmStructuralProperty property)
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.ComplexProperty;
@@ -42,13 +42,13 @@ public ODataComplexPropertySegment(IEdmStructuralProperty property)
4242
/// <summary>
4343
/// Gets the type definition of the property this segment was inserted for.
4444
/// </summary>
45-
public IEdmComplexType ComplexType =>
45+
public IEdmComplexType? ComplexType =>
4646
(Property.Type.IsCollection() ? Property.Type.Definition.AsElementType() : Property.Type.AsComplex().Definition) as IEdmComplexType;
4747

4848
/// <inheritdoc />
4949
public override IEnumerable<IEdmVocabularyAnnotatable> GetAnnotables()
5050
{
51-
return new IEdmVocabularyAnnotatable[] { Property, ComplexType }.Union(ComplexType.FindAllBaseTypes());
51+
return new IEdmVocabularyAnnotatable[] { Property }.Union(ComplexType is null ? [] : [ComplexType]).Union(ComplexType?.FindAllBaseTypes() ?? []);
5252
}
5353

5454
/// <inheritdoc />

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static string GetTitle(this ODataContext context)
6161
}
6262

6363
// If no Core.Description is present, a default title has to be provided as this is a required OpenAPI field.
64-
string namespaceName = context.Model.EntityContainer != null ?
64+
var namespaceName = context.Model.EntityContainer != null ?
6565
context.Model.EntityContainer.Namespace :
6666
context.Model.DeclaredNamespaces.FirstOrDefault();
6767

@@ -113,12 +113,12 @@ private static Dictionary<string, IOpenApiExtension> GetExtensions(this ODataCon
113113
new OpenApiAny(new JsonObject
114114
{
115115
{ "toolName", "Microsoft.OpenApi.OData" },
116-
{ "toolVersion", Assembly.GetExecutingAssembly().GetName().Version.ToString() }
116+
{ "toolVersion", Assembly.GetExecutingAssembly().GetName().Version?.ToString() }
117117
})
118118
}
119119
};
120120
}
121-
return null;
121+
return [];
122122
}
123123
}
124124
}

src/Microsoft.OpenApi.OData.Reader/OpenApiConvertSettings.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public class OpenApiConvertSettings
138138
/// <summary>
139139
/// Gets/sets a value that specifies a prefix to be prepended to all generated paths.
140140
/// </summary>
141-
public string PathPrefix
141+
public string? PathPrefix
142142
{
143143
get
144144
{
@@ -166,7 +166,7 @@ public string PathPrefix
166166
/// <summary>
167167
/// Gets/sets a route path prefix provider.
168168
/// </summary>
169-
public IODataRoutePathPrefixProvider RoutePathPrefixProvider { get; set; }
169+
public IODataRoutePathPrefixProvider? RoutePathPrefixProvider { get; set; }
170170

171171
/// <summary>
172172
/// Gets/Sets a value indicating whether or not to show the OpenAPI links in the responses.
@@ -203,7 +203,7 @@ public string PathPrefix
203203
/// <summary>
204204
/// Gets/sets a the path provider.
205205
/// </summary>
206-
public IODataPathProvider PathProvider { get; set; }
206+
public IODataPathProvider? PathProvider { get; set; }
207207

208208
/// <summary>
209209
/// Gets/sets a value indicating whether or not add OData $count segments in the description for collections.
@@ -315,7 +315,7 @@ public string PathPrefix
315315
/// <summary>
316316
/// The namespace prefix to be stripped from the in method paths.
317317
/// </summary>
318-
public string NamespacePrefixToStripForInMethodPaths { get; set; }
318+
public string? NamespacePrefixToStripForInMethodPaths { get; set; }
319319

320320
/// <summary>
321321
/// Enables the use of aliases for the type cast segments to shorten the url path.

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

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -122,28 +122,34 @@ protected override void SetParameters(OpenApiOperation operation)
122122
// of just providing a comma-separated list of properties can be expressed via an array-valued
123123
// parameter with an enum constraint
124124
// $order
125-
parameter = (string.IsNullOrEmpty(TargetPath) ? null : Context.CreateOrderBy(TargetPath, ComplexPropertySegment.ComplexType))
126-
?? Context.CreateOrderBy(ComplexPropertySegment.Property, ComplexPropertySegment.ComplexType);
127-
if (parameter != null)
125+
if (ComplexPropertySegment.ComplexType is not null)
128126
{
129-
operation.Parameters.Add(parameter);
127+
parameter = (string.IsNullOrEmpty(TargetPath) ? null : Context.CreateOrderBy(TargetPath, ComplexPropertySegment.ComplexType))
128+
?? Context.CreateOrderBy(ComplexPropertySegment.Property, ComplexPropertySegment.ComplexType);
129+
if (parameter != null)
130+
{
131+
operation.Parameters.Add(parameter);
132+
}
130133
}
131134
}
132135

133-
// $select
134-
parameter = (string.IsNullOrEmpty(TargetPath) ? null : Context.CreateSelect(TargetPath, ComplexPropertySegment.ComplexType))
135-
?? Context.CreateSelect(ComplexPropertySegment.Property, ComplexPropertySegment.ComplexType);
136-
if (parameter != null)
136+
if (ComplexPropertySegment.ComplexType is not null)
137137
{
138-
operation.Parameters.Add(parameter);
139-
}
138+
// $select
139+
parameter = (string.IsNullOrEmpty(TargetPath) ? null : Context.CreateSelect(TargetPath, ComplexPropertySegment.ComplexType))
140+
?? Context.CreateSelect(ComplexPropertySegment.Property, ComplexPropertySegment.ComplexType);
141+
if (parameter != null)
142+
{
143+
operation.Parameters.Add(parameter);
144+
}
140145

141-
// $expand
142-
parameter = (string.IsNullOrEmpty(TargetPath) ? null : Context.CreateExpand(TargetPath, ComplexPropertySegment.ComplexType))
143-
?? Context.CreateExpand(ComplexPropertySegment.Property, ComplexPropertySegment.ComplexType);
144-
if (parameter != null)
145-
{
146-
operation.Parameters.Add(parameter);
146+
// $expand
147+
parameter = (string.IsNullOrEmpty(TargetPath) ? null : Context.CreateExpand(TargetPath, ComplexPropertySegment.ComplexType))
148+
?? Context.CreateExpand(ComplexPropertySegment.Property, ComplexPropertySegment.ComplexType);
149+
if (parameter != null)
150+
{
151+
operation.Parameters.Add(parameter);
152+
}
147153
}
148154
}
149155

0 commit comments

Comments
 (0)