Skip to content

Commit

Permalink
Merge pull request #629 from microsoft/fix/port-601
Browse files Browse the repository at this point in the history
Updates PUT operation id prefix from Update to Set (#601)
  • Loading branch information
baywet authored Jan 2, 2025
2 parents efa9aad + c89dc73 commit 481ad4b
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ protected override void Initialize(ODataContext context, ODataPath path)
{
base.Initialize(context, path);

_updateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(TargetPath, CapabilitiesConstants.UpdateRestrictions);
var complexPropertyUpdateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(ComplexPropertySegment.Property, CapabilitiesConstants.UpdateRestrictions);
_updateRestrictions?.MergePropertiesIfNull(complexPropertyUpdateRestrictions);
_updateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(TargetPath, CapabilitiesConstants.UpdateRestrictions);
var complexPropertyUpdateRestrictions = Context.Model.GetRecord<UpdateRestrictionsType>(ComplexPropertySegment.Property, CapabilitiesConstants.UpdateRestrictions);
_updateRestrictions?.MergePropertiesIfNull(complexPropertyUpdateRestrictions);
_updateRestrictions ??= complexPropertyUpdateRestrictions;
}

Expand All @@ -40,7 +40,8 @@ protected override void SetBasicInfo(OpenApiOperation operation)
// OperationId
if (Context.Settings.EnableOperationId)
{
operation.OperationId = EdmModelHelper.GenerateComplexPropertyPathOperationId(Path, "Update");
string prefix = OperationType == OperationType.Patch ? "Update" : "Set";
operation.OperationId = EdmModelHelper.GenerateComplexPropertyPathOperationId(Path, prefix);
}
}

Expand Down Expand Up @@ -101,37 +102,37 @@ protected override void AppendCustomParameters(OpenApiOperation operation)

private OpenApiSchema GetOpenApiSchema()
{
var schema = new OpenApiSchema
{
UnresolvedReference = true,
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = ComplexPropertySegment.ComplexType.FullName()
}
};

if (ComplexPropertySegment.Property.Type.IsCollection())
{
var schema = new OpenApiSchema
{
UnresolvedReference = true,
Reference = new OpenApiReference
{
Type = ReferenceType.Schema,
Id = ComplexPropertySegment.ComplexType.FullName()
}
};

if (ComplexPropertySegment.Property.Type.IsCollection())
{
return new OpenApiSchema
{
Type = Constants.ObjectType,
Properties = new Dictionary<string, OpenApiSchema>
{
{
Properties = new Dictionary<string, OpenApiSchema>
{
{
"value",
new OpenApiSchema
{
Type = "array",
Items = schema
}
}
}
}
}
};
}
else
{
return schema;
};
}
else
{
return schema;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ protected override void SetBasicInfo(OpenApiOperation operation)
if (Context.Settings.EnableOperationId)
{
string typeName = entityType.Name;
string operationName = $"Update{ Utils.UpperFirstChar(typeName)}";
string prefix = OperationType == OperationType.Patch ? "Update" : "Set";
string operationName = $"{prefix}{ Utils.UpperFirstChar(typeName)}";
if (keySegment.IsAlternateKey)
{
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override void SetBasicInfo(OpenApiOperation operation)
// OperationId
if (Context.Settings.EnableOperationId)
{
string prefix = "Update";
string prefix = OperationType == OperationType.Patch ? "Update" : "Set";
operation.OperationId = GetOperationId(prefix);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void CreateComplexPropertyPutOperationReturnsCorrectOperationForSingle(bo

if (enableOperationId)
{
Assert.Equal("Customers.UpdateBillingAddress", put.OperationId);
Assert.Equal("Customers.SetBillingAddress", put.OperationId);
}
else
{
Expand Down Expand Up @@ -108,7 +108,7 @@ public void CreateComplexPropertyPutOperationReturnsCorrectOperationForCollectio

if (enableOperationId)
{
Assert.Equal("Customers.UpdateAlternativeAddresses", put.OperationId);
Assert.Equal("Customers.SetAlternativeAddresses", put.OperationId);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void CreateEntityPutOperationReturnsCorrectOperation(bool enableOperation

if (enableOperationId)
{
Assert.Equal("Customers.Customer.UpdateCustomer", putOperation.OperationId);
Assert.Equal("Customers.Customer.SetCustomer", putOperation.OperationId);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void CreateNavigationPutOperationReturnsCorrectOperation(bool enableOpera

if (enableOperationId)
{
Assert.Equal("People.UpdateBestFriend", operation.OperationId);
Assert.Equal("People.SetBestFriend", operation.OperationId);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
"Airlines.Airline"
],
"summary": "Update entity in Airlines",
"operationId": "Airlines.Airline.UpdateAirline",
"operationId": "Airlines.Airline.SetAirline",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -534,7 +534,7 @@
"Airports.AirportLocation"
],
"summary": "Update property Location value.",
"operationId": "Airports.UpdateLocation",
"operationId": "Airports.SetLocation",
"consumes": [
"application/json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ paths:
tags:
- Airlines.Airline
summary: Update entity in Airlines
operationId: Airlines.Airline.UpdateAirline
operationId: Airlines.Airline.SetAirline
consumes:
- application/json
parameters:
Expand Down Expand Up @@ -349,7 +349,7 @@ paths:
tags:
- Airports.AirportLocation
summary: Update property Location value.
operationId: Airports.UpdateLocation
operationId: Airports.SetLocation
consumes:
- application/json
parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"Airlines.Airline"
],
"summary": "Update entity in Airlines",
"operationId": "Airlines.Airline.UpdateAirline",
"operationId": "Airlines.Airline.SetAirline",
"parameters": [
{
"name": "AirlineCode",
Expand Down Expand Up @@ -609,7 +609,7 @@
"Airports.AirportLocation"
],
"summary": "Update property Location value.",
"operationId": "Airports.UpdateLocation",
"operationId": "Airports.SetLocation",
"parameters": [
{
"name": "IcaoCode",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ paths:
tags:
- Airlines.Airline
summary: Update entity in Airlines
operationId: Airlines.Airline.UpdateAirline
operationId: Airlines.Airline.SetAirline
parameters:
- name: AirlineCode
in: path
Expand Down Expand Up @@ -398,7 +398,7 @@ paths:
tags:
- Airports.AirportLocation
summary: Update property Location value.
operationId: Airports.UpdateLocation
operationId: Airports.SetLocation
parameters:
- name: IcaoCode
in: path
Expand Down

0 comments on commit 481ad4b

Please sign in to comment.