Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates PUT operation id prefix from Update to Set (#601) #629

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 Expand Up @@ -97,7 +98,7 @@
{
Schema = schema
});
};

Check warning on line 101 in src/Microsoft.OpenApi.OData.Reader/Operation/EntityUpdateOperationHandler.cs

View workflow job for this annotation

GitHub Actions / Build

Remove this empty statement. (https://rules.sonarsource.com/csharp/RSPEC-1116)

return content;
}
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
Loading