Skip to content

Commit 286be91

Browse files
authored
Merge pull request #768 from microsoft/fix/obsolete-apis
fix/obsolete apis
2 parents 1dda088 + 02ba3db commit 286be91

File tree

9 files changed

+44
-32
lines changed

9 files changed

+44
-32
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
}

test/Microsoft.OpenAPI.OData.Reader.Tests/Vocabulary/Capabilities/CustomParameterTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
44
// ------------------------------------------------------------
55

6+
using System;
67
using System.IO;
78
using System.Xml;
89
using Microsoft.OData.Edm;
@@ -29,7 +30,7 @@ public void InitializeCustomParameterWithRecordSuccess()
2930
new EdmPropertyConstructor("ExampleValues",
3031
new EdmCollectionExpression(
3132
new EdmRecordExpression(new EdmPropertyConstructor("Value", new EdmStringConstant("html"))),
32-
new EdmRecordExpression(new EdmPropertyConstructor("Value", new EdmTimeOfDayConstant(new TimeOfDay(3, 4, 5, 6)))))));
33+
new EdmRecordExpression(new EdmPropertyConstructor("Value", new EdmTimeOfDayConstant(new TimeOnly(3, 4, 5, 6)))))));
3334

3435
// Act
3536
CustomParameter parameter = new CustomParameter();
@@ -102,7 +103,7 @@ private static void VerifyCustomParameter(CustomParameter parameter)
102103
value = parameter.ExampleValues[1];
103104
Assert.Null(value.Description);
104105
Assert.NotNull(value.Value);
105-
Assert.Equal(new TimeOfDay(3, 4, 5, 6), value.Value.Value);
106+
Assert.Equal(new TimeOnly(3, 4, 5, 6).ToString("HH:mm:ss.fffffff"), value.Value.Value.ToString());
106107
}
107108

108109
private IEdmModel GetEdmModel(string annotation)

test/Microsoft.OpenAPI.OData.Reader.Tests/Vocabulary/Capabilities/RevisionRecordTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public void InitializeWithDeprecatedRevisionsTypeRecordSuccess()
4343
{
4444
// Arrange
4545
IEdmRecordExpression record = new EdmRecordExpression(
46-
new EdmPropertyConstructor("Date", new EdmDateConstant(new Date(2021, 8, 24))),
47-
new EdmPropertyConstructor("RemovalDate", new EdmDateConstant(new Date(2021, 10, 24))),
46+
new EdmPropertyConstructor("Date", new EdmDateConstant(new DateOnly(2021, 8, 24))),
47+
new EdmPropertyConstructor("RemovalDate", new EdmDateConstant(new DateOnly(2021, 10, 24))),
4848
new EdmPropertyConstructor("Kind", new EdmEnumMemberExpression(deprecatedValue)),
4949
new EdmPropertyConstructor("Description", new EdmStringConstant("The identityProvider API is deprecated and will stop returning data on March 2023. Please use the new identityProviderBase API.")),
5050
new EdmPropertyConstructor("Version", new EdmStringConstant("2021-05/test")));
@@ -71,15 +71,15 @@ public void WorksForAllKinds()
7171
{
7272
// Arrange
7373
IEdmRecordExpression record1 = new EdmRecordExpression(
74-
new EdmPropertyConstructor("Date", new EdmDateConstant(new Date(2021, 8, 24))),
75-
new EdmPropertyConstructor("RemovalDate", new EdmDateConstant(new Date(2021, 10, 24))),
74+
new EdmPropertyConstructor("Date", new EdmDateConstant(new DateOnly(2021, 8, 24))),
75+
new EdmPropertyConstructor("RemovalDate", new EdmDateConstant(new DateOnly(2021, 10, 24))),
7676
new EdmPropertyConstructor("Kind", new EdmEnumMemberExpression(addedValue)),
7777
new EdmPropertyConstructor("Description", new EdmStringConstant("The identityProvider API is deprecated and will stop returning data on March 2023. Please use the new identityProviderBase API.")),
7878
new EdmPropertyConstructor("Version", new EdmStringConstant("2021-05/test")));
7979

8080
IEdmRecordExpression record2 = new EdmRecordExpression(
81-
new EdmPropertyConstructor("Date", new EdmDateConstant(new Date(2023, 3, 2))),
82-
new EdmPropertyConstructor("RemovalDate", new EdmDateConstant(new Date(2023, 05, 30))),
81+
new EdmPropertyConstructor("Date", new EdmDateConstant(new DateOnly(2023, 3, 2))),
82+
new EdmPropertyConstructor("RemovalDate", new EdmDateConstant(new DateOnly(2023, 05, 30))),
8383
new EdmPropertyConstructor("Kind", new EdmEnumMemberExpression(deprecatedValue)),
8484
new EdmPropertyConstructor("Description", new EdmStringConstant("Private preview test.")),
8585
new EdmPropertyConstructor("Version", new EdmStringConstant("2023-03/test")));

test/Microsoft.OpenAPI.OData.Reader.Tests/Vocabulary/Core/PrimitiveExampleValueTests.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public void InitializeWithPrimitiveValueRecordSuccess()
6969
new object[] { @"Int=""42""", (long)42 },
7070
new object[] { @"Bool=""true""", true },
7171
new object[] { @"Bool=""false""", false },
72-
new object[] { @"TimeOfDay=""15:38:25.1090000""", new TimeOfDay(15, 38, 25, 109) },
73-
new object[] { @"Date=""2014-10-13""", new Date(2014, 10, 13) },
72+
new object[] { @"TimeOfDay=""15:38:25.1090000""", new TimeOnly(15, 38, 25, 109) },
73+
new object[] { @"Date=""2014-10-13""", new DateOnly(2014, 10, 13) },
7474
new object[] { @"Duration=""PT0S""", new TimeSpan() },
7575
// new object[] { @"Binary=""AQ==""", new byte[] { 1 }, }, has problem in ODL?
7676
new object[] { @"Float=""3.14""", 3.14 },
@@ -106,7 +106,18 @@ public void PrimitiveExamplevalueInitializeWorksForPrimitiveData(string data, ob
106106
Assert.NotNull(value);
107107
Assert.Equal("Primitive example value", value.Description);
108108
Assert.NotNull(value.Value);
109-
Assert.Equal(except, value.Value.Value);
109+
switch (except)
110+
{
111+
case DateOnly dateOnly:
112+
Assert.Equal(dateOnly.ToString("yyyy-MM-dd"), value.Value.Value.ToString());
113+
break;
114+
case TimeOnly timeOnly:
115+
Assert.Equal(timeOnly.ToString("HH:mm:ss.fffffff"), value.Value.Value.ToString());
116+
break;
117+
default:
118+
Assert.Equal(except, value.Value.Value);
119+
break;
120+
}
110121
}
111122

112123
private IEdmModel GetEdmModel(string annotation)

0 commit comments

Comments
 (0)