Skip to content

Commit 2a1633d

Browse files
irvinesundaybaywet
authored andcommitted
Adds nullable to double schema conversions (#589)
* Update double schema * Update integration file tests * Update release notes Signed-off-by: Vincent Biret <[email protected]>
1 parent bbce0a8 commit 2a1633d

10 files changed

+42
-40
lines changed

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

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ protected override void Initialize(ODataContext context, ODataPath path)
2323
{
2424
base.Initialize(context, path);
2525

26-
_updateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(TargetPath, CapabilitiesConstants.UpdateRestrictions);
27-
var complexPropertyUpdateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(ComplexPropertySegment.Property, CapabilitiesConstants.UpdateRestrictions);
28-
_updateRestrictions?.MergePropertiesIfNull(complexPropertyUpdateRestrictions);
26+
_updateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(TargetPath, CapabilitiesConstants.UpdateRestrictions);
27+
var complexPropertyUpdateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(ComplexPropertySegment.Property, CapabilitiesConstants.UpdateRestrictions);
28+
_updateRestrictions?.MergePropertiesIfNull(complexPropertyUpdateRestrictions);
2929
_updateRestrictions ??= complexPropertyUpdateRestrictions;
3030
}
3131

@@ -40,7 +40,8 @@ protected override void SetBasicInfo(OpenApiOperation operation)
4040
// OperationId
4141
if (Context.Settings.EnableOperationId)
4242
{
43-
operation.OperationId = EdmModelHelper.GenerateComplexPropertyPathOperationId(Path, "Update");
43+
string prefix = OperationType == OperationType.Patch ? "Update" : "Set";
44+
operation.OperationId = EdmModelHelper.GenerateComplexPropertyPathOperationId(Path, prefix);
4445
}
4546
}
4647

@@ -101,37 +102,37 @@ protected override void AppendCustomParameters(OpenApiOperation operation)
101102

102103
private OpenApiSchema GetOpenApiSchema()
103104
{
104-
var schema = new OpenApiSchema
105-
{
106-
UnresolvedReference = true,
107-
Reference = new OpenApiReference
108-
{
109-
Type = ReferenceType.Schema,
110-
Id = ComplexPropertySegment.ComplexType.FullName()
111-
}
112-
};
113-
114-
if (ComplexPropertySegment.Property.Type.IsCollection())
115-
{
105+
var schema = new OpenApiSchema
106+
{
107+
UnresolvedReference = true,
108+
Reference = new OpenApiReference
109+
{
110+
Type = ReferenceType.Schema,
111+
Id = ComplexPropertySegment.ComplexType.FullName()
112+
}
113+
};
114+
115+
if (ComplexPropertySegment.Property.Type.IsCollection())
116+
{
116117
return new OpenApiSchema
117118
{
118119
Type = Constants.ObjectType,
119-
Properties = new Dictionary<string, OpenApiSchema>
120-
{
121-
{
120+
Properties = new Dictionary<string, OpenApiSchema>
121+
{
122+
{
122123
"value",
123124
new OpenApiSchema
124125
{
125126
Type = "array",
126127
Items = schema
127-
}
128-
}
128+
}
129+
}
129130
}
130-
};
131-
}
132-
else
133-
{
134-
return schema;
131+
};
132+
}
133+
else
134+
{
135+
return schema;
135136
}
136137
}
137138
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ protected override void SetBasicInfo(OpenApiOperation operation)
5050
if (Context.Settings.EnableOperationId)
5151
{
5252
string typeName = entityType.Name;
53-
string operationName = $"Update{ Utils.UpperFirstChar(typeName)}";
53+
string prefix = OperationType == OperationType.Patch ? "Update" : "Set";
54+
string operationName = $"{prefix}{ Utils.UpperFirstChar(typeName)}";
5455
if (keySegment.IsAlternateKey)
5556
{
5657
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected override void SetBasicInfo(OpenApiOperation operation)
4141
// OperationId
4242
if (Context.Settings.EnableOperationId)
4343
{
44-
string prefix = "Update";
44+
string prefix = OperationType == OperationType.Patch ? "Update" : "Set";
4545
operation.OperationId = GetOperationId(prefix);
4646
}
4747

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void CreateComplexPropertyPutOperationReturnsCorrectOperationForSingle(bo
6161

6262
if (enableOperationId)
6363
{
64-
Assert.Equal("Customers.UpdateBillingAddress", put.OperationId);
64+
Assert.Equal("Customers.SetBillingAddress", put.OperationId);
6565
}
6666
else
6767
{
@@ -108,7 +108,7 @@ public void CreateComplexPropertyPutOperationReturnsCorrectOperationForCollectio
108108

109109
if (enableOperationId)
110110
{
111-
Assert.Equal("Customers.UpdateAlternativeAddresses", put.OperationId);
111+
Assert.Equal("Customers.SetAlternativeAddresses", put.OperationId);
112112
}
113113
else
114114
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void CreateEntityPutOperationReturnsCorrectOperation(bool enableOperation
6666

6767
if (enableOperationId)
6868
{
69-
Assert.Equal("Customers.Customer.UpdateCustomer", putOperation.OperationId);
69+
Assert.Equal("Customers.Customer.SetCustomer", putOperation.OperationId);
7070
}
7171
else
7272
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void CreateNavigationPutOperationReturnsCorrectOperation(bool enableOpera
7171

7272
if (enableOperationId)
7373
{
74-
Assert.Equal("People.UpdateBestFriend", operation.OperationId);
74+
Assert.Equal("People.SetBestFriend", operation.OperationId);
7575
}
7676
else
7777
{

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
"Airlines.Airline"
166166
],
167167
"summary": "Update entity in Airlines",
168-
"operationId": "Airlines.Airline.UpdateAirline",
168+
"operationId": "Airlines.Airline.SetAirline",
169169
"consumes": [
170170
"application/json"
171171
],
@@ -534,7 +534,7 @@
534534
"Airports.AirportLocation"
535535
],
536536
"summary": "Update property Location value.",
537-
"operationId": "Airports.UpdateLocation",
537+
"operationId": "Airports.SetLocation",
538538
"consumes": [
539539
"application/json"
540540
],

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.V2.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ paths:
107107
tags:
108108
- Airlines.Airline
109109
summary: Update entity in Airlines
110-
operationId: Airlines.Airline.UpdateAirline
110+
operationId: Airlines.Airline.SetAirline
111111
consumes:
112112
- application/json
113113
parameters:
@@ -349,7 +349,7 @@ paths:
349349
tags:
350350
- Airports.AirportLocation
351351
summary: Update property Location value.
352-
operationId: Airports.UpdateLocation
352+
operationId: Airports.SetLocation
353353
consumes:
354354
- application/json
355355
parameters:

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"Airlines.Airline"
193193
],
194194
"summary": "Update entity in Airlines",
195-
"operationId": "Airlines.Airline.UpdateAirline",
195+
"operationId": "Airlines.Airline.SetAirline",
196196
"parameters": [
197197
{
198198
"name": "AirlineCode",
@@ -609,7 +609,7 @@
609609
"Airports.AirportLocation"
610610
],
611611
"summary": "Update property Location value.",
612-
"operationId": "Airports.UpdateLocation",
612+
"operationId": "Airports.SetLocation",
613613
"parameters": [
614614
{
615615
"name": "IcaoCode",

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/TripService.OpenApi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ paths:
125125
tags:
126126
- Airlines.Airline
127127
summary: Update entity in Airlines
128-
operationId: Airlines.Airline.UpdateAirline
128+
operationId: Airlines.Airline.SetAirline
129129
parameters:
130130
- name: AirlineCode
131131
in: path
@@ -398,7 +398,7 @@ paths:
398398
tags:
399399
- Airports.AirportLocation
400400
summary: Update property Location value.
401-
operationId: Airports.UpdateLocation
401+
operationId: Airports.SetLocation
402402
parameters:
403403
- name: IcaoCode
404404
in: path

0 commit comments

Comments
 (0)