Skip to content

Commit b888063

Browse files
committed
chore: upgrades from using obsolete APIs
1 parent 0fb398e commit b888063

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,16 +872,16 @@ private void RetrieveBoundOperationPaths(OpenApiConvertSettings convertSettings)
872872
var functionPaths = _allOperationPaths.Where(x => x.LastSegment is ODataOperationSegment operationSegment
873873
&& operationSegment.Operation is IEdmFunction edmFunction
874874
&& edmFunction.IsComposable
875-
&& edmFunction.ReturnType != null
876-
&& edmFunction.ReturnType.Definition is IEdmEntityType);
875+
&& edmFunction.GetReturn()?.Type is { } retType
876+
&& retType.Definition is IEdmEntityType);
877877

878878
foreach( var functionPath in functionPaths)
879879
{
880880
if (functionPath.LastSegment is not ODataOperationSegment operationSegment
881881
|| operationSegment.Operation is not IEdmFunction edmFunction
882882
|| !edmFunction.IsComposable
883-
|| edmFunction.ReturnType == null
884-
|| edmFunction.ReturnType.Definition is not IEdmEntityType returnBindingEntityType)
883+
|| edmFunction.GetReturn()?.Type is not { } retType
884+
|| retType.Definition is not IEdmEntityType returnBindingEntityType)
885885
{
886886
continue;
887887
}
@@ -1194,7 +1194,7 @@ private void AppendBoundOperationOnOperationPath(IEdmOperation edmOperation, boo
11941194
if (path.LastSegment is not ODataOperationSegment operationSegment
11951195
|| (path.Segments.Count > 1 && path.Segments[path.Segments.Count - 2] is ODataOperationSegment)
11961196
|| operationSegment.Operation is not IEdmFunction edmFunction || !edmFunction.IsComposable
1197-
|| edmFunction.ReturnType == null || !edmFunction.ReturnType.Definition.Equals(bindingEntityType)
1197+
|| edmFunction.GetReturn()?.Type is not { } retType || !retType.Definition.Equals(bindingEntityType)
11981198
|| isCollection
11991199
|| _model is not null && !EdmModelHelper.IsOperationAllowed(_model, edmOperation, operationSegment.Operation, true))
12001200
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public void Visit(IEdmModel model)
4949

5050
private void VisitOperation(IEdmOperation operation)
5151
{
52-
if (operation.ReturnType != null)
52+
if (operation.GetReturn() is {} operationReturn)
5353
{
54-
this.VisitTypeReference(operation.ReturnType);
54+
this.VisitTypeReference(operationReturn.Type);
5555
}
5656

5757
foreach (var parameter in operation.Parameters)

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

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

118118
OpenApiResponses responses = new();
119119

120-
if (operation.IsAction() && operation.ReturnType == null && Constants.StatusCode204.GetResponse(document) is {} x204Response)
120+
if (operation.IsAction() && operation.GetReturn()?.Type == null && Constants.StatusCode204.GetResponse(document) is {} x204Response)
121121
{
122122
responses.Add(Constants.StatusCode204, x204Response);
123123
}
@@ -150,19 +150,19 @@ public static OpenApiResponses CreateResponses(this ODataContext context, IEdmOp
150150

151151
public static OpenApiResponse? CreateOperationResponse(this ODataContext context, IEdmOperation operation, OpenApiDocument document)
152152
{
153-
if (operation.ReturnType == null)
153+
if (operation.GetReturn()?.Type is not {} returnType)
154154
return null;
155155

156156
IOpenApiSchema schema;
157-
if (operation.ReturnType.IsCollection())
157+
if (returnType.IsCollection())
158158
{
159159
OpenApiSchema baseSchema = new()
160160
{
161161
Type = JsonSchemaType.Object,
162162
Properties = new Dictionary<string, IOpenApiSchema>
163163
{
164164
{
165-
"value", context.CreateEdmTypeSchema(operation.ReturnType, document)
165+
"value", context.CreateEdmTypeSchema(returnType, document)
166166
}
167167
}
168168
};
@@ -202,12 +202,12 @@ public static OpenApiResponses CreateResponses(this ODataContext context, IEdmOp
202202

203203
if (schema is OpenApiSchema openApiSchema)
204204
{
205-
openApiSchema.Title = operation.ReturnType.Definition.AsElementType() is not IEdmEntityType entityType
205+
openApiSchema.Title = returnType.Definition.AsElementType() is not IEdmEntityType entityType
206206
? null : $"Collection of {entityType.Name}";
207207
openApiSchema.Type = JsonSchemaType.Object;
208208
}
209209
}
210-
else if (operation.ReturnType.IsPrimitive())
210+
else if (returnType.IsPrimitive())
211211
{
212212
// A property or operation response that is of a primitive type is represented as an object with a single name/value pair,
213213
// whose name is value and whose value is a primitive value.
@@ -217,18 +217,18 @@ public static OpenApiResponses CreateResponses(this ODataContext context, IEdmOp
217217
Properties = new Dictionary<string, IOpenApiSchema>
218218
{
219219
{
220-
"value", context.CreateEdmTypeSchema(operation.ReturnType, document)
220+
"value", context.CreateEdmTypeSchema(returnType, document)
221221
}
222222
}
223223
};
224224
}
225225
else
226226
{
227-
schema = context.CreateEdmTypeSchema(operation.ReturnType, document);
227+
schema = context.CreateEdmTypeSchema(returnType, document);
228228
}
229229

230230
string? mediaType = Constants.ApplicationJsonMediaType;
231-
if (operation.ReturnType.AsPrimitive()?.PrimitiveKind() == EdmPrimitiveTypeKind.Stream)
231+
if (returnType.AsPrimitive()?.PrimitiveKind() == EdmPrimitiveTypeKind.Stream)
232232
{
233233
mediaType = context.Model.GetString(operation, CoreConstants.MediaType);
234234

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ protected override void AppendCustomParameters(OpenApiOperation operation)
254254

255255
private void AppendSystemQueryOptions(IEdmFunction function, OpenApiOperation operation)
256256
{
257-
if (function.ReturnType.IsCollection() && Context is not null)
257+
if (function.GetReturn()?.Type is {} functionReturnType && functionReturnType.IsCollection() && Context is not null)
258258
{
259259
operation.Parameters ??= [];
260260
// $top
@@ -287,7 +287,7 @@ private void AppendSystemQueryOptions(IEdmFunction function, OpenApiOperation op
287287
operation.Parameters.AppendParameter(countParameter);
288288
}
289289

290-
if (function.ReturnType?.Definition?.AsElementType() is IEdmEntityType entityType)
290+
if (functionReturnType?.Definition?.AsElementType() is IEdmEntityType entityType)
291291
{
292292
// $select
293293
if (Context.CreateSelect(function, entityType) is {} selectParameter)
@@ -347,7 +347,7 @@ protected override void SetExternalDocs(OpenApiOperation operation)
347347
// <inheritdoc/>
348348
protected override void SetExtensions(OpenApiOperation operation)
349349
{
350-
if (Context is { Settings.EnablePagination: true } && EdmOperation?.ReturnType?.TypeKind() == EdmTypeKind.Collection)
350+
if (Context is { Settings.EnablePagination: true } && EdmOperation?.GetReturn()?.Type?.TypeKind() == EdmTypeKind.Collection)
351351
{
352352
var extension = new JsonObject
353353
{

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmActionOperationHandlerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public void CreateOperationForEdmActionWithCollectionReturnTypeContainsXMsPageab
342342
var operation = _operationHandler.CreateOperation(context, path);
343343

344344
// Assert
345-
if (enablePagination && action.ReturnType.IsCollection())
345+
if (enablePagination && action.GetReturn()?.Type?.IsCollection() == true)
346346
{
347347
Assert.True(operation.Extensions.ContainsKey(Common.Constants.xMsPageable));
348348
}

test/Microsoft.OpenAPI.OData.Reader.Tests/Operation/EdmFunctionOperationHandlerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ public void CreateOperationForEdmFunctionWithCollectionReturnTypeContainsXMsPage
546546
var operation = _operationHandler.CreateOperation(context, path);
547547

548548
// Assert
549-
if (enablePagination && function.ReturnType.IsCollection())
549+
if (enablePagination && function.GetReturn()?.Type?.IsCollection() == true)
550550
{
551551
Assert.True(operation.Extensions.ContainsKey(Common.Constants.xMsPageable));
552552
}

0 commit comments

Comments
 (0)