Skip to content

Commit 9215341

Browse files
Only add By{Key} suffix to operationIds for alternate key paths (#330)
1 parent 2d4ebb5 commit 9215341

20 files changed

+331
-303
lines changed

src/Microsoft.OpenApi.OData.Reader/Microsoft.OpenAPI.OData.Reader.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.2.0-preview10</Version>
18+
<Version>1.2.0-preview11</Version>
1919
<Description>This package contains the codes you need to convert OData CSDL to Open API Document of Model.</Description>
2020
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2121
<PackageTags>Microsoft OpenApi OData EDM</PackageTags>
@@ -32,6 +32,7 @@
3232
- Adds support for configuring the default value of derived types' @odata.type property #304
3333
- Adds OData query parameters to $count endpoints #313
3434
- Finds all the derived types for a schema element #84
35+
- Add support for paths with alternate keys #120, #329
3536
</PackageReleaseNotes>
3637
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
3738
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,25 @@ protected override void SetBasicInfo(OpenApiOperation operation)
3939
ODataKeySegment keySegment = Path.LastSegment as ODataKeySegment;
4040

4141
// Description
42-
string placeHolder = $"Delete entity from {EntitySet.Name} by key ({keySegment.Identifier})";
42+
string placeHolder = $"Delete entity from {EntitySet.Name}";
43+
if (keySegment.IsAlternateKey)
44+
{
45+
placeHolder = $"{placeHolder} by {keySegment.Identifier}";
46+
}
4347
operation.Summary = _deleteRestrictions?.Description ?? placeHolder;
4448
operation.Description = _deleteRestrictions?.LongDescription;
4549

4650
// OperationId
4751
if (Context.Settings.EnableOperationId)
4852
{
4953
string typeName = entityType.Name;
50-
string keyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
51-
operation.OperationId = $"{EntitySet.Name}.{typeName}.Delete{Utils.UpperFirstChar(typeName)}By{keyName}";
54+
string operationName =$"Delete{Utils.UpperFirstChar(typeName)}";
55+
if (keySegment.IsAlternateKey)
56+
{
57+
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
58+
operationName = $"{operationName}By{alternateKeyName}";
59+
}
60+
operation.OperationId = $"{EntitySet.Name}.{typeName}.{operationName}";
5261
}
5362
}
5463

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,27 @@ protected override void SetBasicInfo(OpenApiOperation operation)
3838
{
3939
IEdmEntityType entityType = EntitySet.EntityType();
4040
ODataKeySegment keySegment = Path.LastSegment as ODataKeySegment;
41-
41+
4242
// Description
43-
string placeHolder = $"Get entity from {EntitySet.Name} by key ({keySegment.Identifier})";
43+
string placeHolder = "Get entity from " + EntitySet.Name + " by key";
44+
if (keySegment.IsAlternateKey)
45+
{
46+
placeHolder = $"{placeHolder} ({keySegment.Identifier})";
47+
}
4448
operation.Summary = _readRestrictions?.ReadByKeyRestrictions?.Description ?? placeHolder;
4549
operation.Description = _readRestrictions?.ReadByKeyRestrictions?.LongDescription ?? Context.Model.GetDescriptionAnnotation(entityType);
4650

4751
// OperationId
4852
if (Context.Settings.EnableOperationId)
4953
{
5054
string typeName = entityType.Name;
51-
string keyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
52-
operation.OperationId = $"{EntitySet.Name}.{typeName}.Get{Utils.UpperFirstChar(typeName)}By{keyName}";
55+
string operationName = $"Get{Utils.UpperFirstChar(typeName)}";
56+
if (keySegment.IsAlternateKey)
57+
{
58+
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
59+
operationName = $"{operationName}By{alternateKeyName}";
60+
}
61+
operation.OperationId = $"{EntitySet.Name}.{typeName}.{operationName}";
5362
}
5463
}
5564

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,25 @@ protected override void SetBasicInfo(OpenApiOperation operation)
3535
ODataKeySegment keySegment = Path.LastSegment as ODataKeySegment;
3636

3737
// Summary and Description
38-
string placeHolder = $"Update entity in {EntitySet.Name} by key ({keySegment.Identifier})";
38+
string placeHolder = "Update entity in " + EntitySet.Name;
39+
if (keySegment.IsAlternateKey)
40+
{
41+
placeHolder = $"{placeHolder} by {keySegment.Identifier}";
42+
}
3943
operation.Summary = _updateRestrictions?.Description ?? placeHolder;
4044
operation.Description = _updateRestrictions?.LongDescription;
4145

4246
// OperationId
4347
if (Context.Settings.EnableOperationId)
4448
{
4549
string typeName = entityType.Name;
46-
string keyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
47-
operation.OperationId = $"{EntitySet.Name}.{typeName}.Update{Utils.UpperFirstChar(typeName)}By{keyName}";
50+
string operationName = $"Update{ Utils.UpperFirstChar(typeName)}";
51+
if (keySegment.IsAlternateKey)
52+
{
53+
string alternateKeyName = string.Join("", keySegment.Identifier.Split(',').Select(static x => Utils.UpperFirstChar(x)));
54+
operationName = $"{operationName}By{alternateKeyName}";
55+
}
56+
operation.OperationId = $"{EntitySet.Name}.{typeName}.{operationName}";
4857
}
4958
}
5059

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void CreateEntityDeleteOperationReturnsCorrectOperation(bool enableOperat
5353

5454
if (enableOperationId)
5555
{
56-
Assert.Equal("Customers.Customer.DeleteCustomerByID", delete.OperationId);
56+
Assert.Equal("Customers.Customer.DeleteCustomer", delete.OperationId);
5757
}
5858
else
5959
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void CreateEntityGetOperationReturnsCorrectOperation(bool enableOperation
5757

5858
if (enableOperationId)
5959
{
60-
Assert.Equal("Customers.Customer.GetCustomerByID", get.OperationId);
60+
Assert.Equal("Customers.Customer.GetCustomer", get.OperationId);
6161
}
6262
else
6363
{

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

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

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

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.UpdateCustomerByID", putOperation.OperationId);
69+
Assert.Equal("Customers.Customer.UpdateCustomer", putOperation.OperationId);
7070
}
7171
else
7272
{

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@
123123
"tags": [
124124
"City.City"
125125
],
126-
"summary": "Get entity from City by key (Name)",
127-
"operationId": "City.City.GetCityByName",
126+
"summary": "Get entity from City by key",
127+
"operationId": "City.City.GetCity",
128128
"produces": [
129129
"application/json"
130130
],
@@ -179,8 +179,8 @@
179179
"tags": [
180180
"City.City"
181181
],
182-
"summary": "Update entity in City by key (Name)",
183-
"operationId": "City.City.UpdateCityByName",
182+
"summary": "Update entity in City",
183+
"operationId": "City.City.UpdateCity",
184184
"consumes": [
185185
"application/json"
186186
],
@@ -217,8 +217,8 @@
217217
"tags": [
218218
"City.City"
219219
],
220-
"summary": "Delete entity from City by key (Name)",
221-
"operationId": "City.City.DeleteCityByName",
220+
"summary": "Delete entity from City",
221+
"operationId": "City.City.DeleteCity",
222222
"parameters": [
223223
{
224224
"in": "path",
@@ -383,8 +383,8 @@
383383
"tags": [
384384
"CountryOrRegion.CountryOrRegion"
385385
],
386-
"summary": "Get entity from CountryOrRegion by key (Name)",
387-
"operationId": "CountryOrRegion.CountryOrRegion.GetCountryOrRegionByName",
386+
"summary": "Get entity from CountryOrRegion by key",
387+
"operationId": "CountryOrRegion.CountryOrRegion.GetCountryOrRegion",
388388
"produces": [
389389
"application/json"
390390
],
@@ -439,8 +439,8 @@
439439
"tags": [
440440
"CountryOrRegion.CountryOrRegion"
441441
],
442-
"summary": "Update entity in CountryOrRegion by key (Name)",
443-
"operationId": "CountryOrRegion.CountryOrRegion.UpdateCountryOrRegionByName",
442+
"summary": "Update entity in CountryOrRegion",
443+
"operationId": "CountryOrRegion.CountryOrRegion.UpdateCountryOrRegion",
444444
"consumes": [
445445
"application/json"
446446
],
@@ -477,8 +477,8 @@
477477
"tags": [
478478
"CountryOrRegion.CountryOrRegion"
479479
],
480-
"summary": "Delete entity from CountryOrRegion by key (Name)",
481-
"operationId": "CountryOrRegion.CountryOrRegion.DeleteCountryOrRegionByName",
480+
"summary": "Delete entity from CountryOrRegion",
481+
"operationId": "CountryOrRegion.CountryOrRegion.DeleteCountryOrRegion",
482482
"parameters": [
483483
{
484484
"in": "path",
@@ -737,8 +737,8 @@
737737
"tags": [
738738
"People.Person"
739739
],
740-
"summary": "Get entity from People by key (UserName)",
741-
"operationId": "People.Person.GetPersonByUserName",
740+
"summary": "Get entity from People by key",
741+
"operationId": "People.Person.GetPerson",
742742
"produces": [
743743
"application/json"
744744
],
@@ -796,8 +796,8 @@
796796
"tags": [
797797
"People.Person"
798798
],
799-
"summary": "Update entity in People by key (UserName)",
800-
"operationId": "People.Person.UpdatePersonByUserName",
799+
"summary": "Update entity in People",
800+
"operationId": "People.Person.UpdatePerson",
801801
"consumes": [
802802
"application/json"
803803
],
@@ -834,8 +834,8 @@
834834
"tags": [
835835
"People.Person"
836836
],
837-
"summary": "Delete entity from People by key (UserName)",
838-
"operationId": "People.Person.DeletePersonByUserName",
837+
"summary": "Delete entity from People",
838+
"operationId": "People.Person.DeletePerson",
839839
"parameters": [
840840
{
841841
"in": "path",

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ paths:
7878
get:
7979
tags:
8080
- City.City
81-
summary: Get entity from City by key (Name)
82-
operationId: City.City.GetCityByName
81+
summary: Get entity from City by key
82+
operationId: City.City.GetCity
8383
produces:
8484
- application/json
8585
parameters:
@@ -116,8 +116,8 @@ paths:
116116
patch:
117117
tags:
118118
- City.City
119-
summary: Update entity in City by key (Name)
120-
operationId: City.City.UpdateCityByName
119+
summary: Update entity in City
120+
operationId: City.City.UpdateCity
121121
consumes:
122122
- application/json
123123
parameters:
@@ -142,8 +142,8 @@ paths:
142142
delete:
143143
tags:
144144
- City.City
145-
summary: Delete entity from City by key (Name)
146-
operationId: City.City.DeleteCityByName
145+
summary: Delete entity from City
146+
operationId: City.City.DeleteCity
147147
parameters:
148148
- in: path
149149
name: Name
@@ -246,8 +246,8 @@ paths:
246246
get:
247247
tags:
248248
- CountryOrRegion.CountryOrRegion
249-
summary: Get entity from CountryOrRegion by key (Name)
250-
operationId: CountryOrRegion.CountryOrRegion.GetCountryOrRegionByName
249+
summary: Get entity from CountryOrRegion by key
250+
operationId: CountryOrRegion.CountryOrRegion.GetCountryOrRegion
251251
produces:
252252
- application/json
253253
parameters:
@@ -284,8 +284,8 @@ paths:
284284
patch:
285285
tags:
286286
- CountryOrRegion.CountryOrRegion
287-
summary: Update entity in CountryOrRegion by key (Name)
288-
operationId: CountryOrRegion.CountryOrRegion.UpdateCountryOrRegionByName
287+
summary: Update entity in CountryOrRegion
288+
operationId: CountryOrRegion.CountryOrRegion.UpdateCountryOrRegion
289289
consumes:
290290
- application/json
291291
parameters:
@@ -310,8 +310,8 @@ paths:
310310
delete:
311311
tags:
312312
- CountryOrRegion.CountryOrRegion
313-
summary: Delete entity from CountryOrRegion by key (Name)
314-
operationId: CountryOrRegion.CountryOrRegion.DeleteCountryOrRegionByName
313+
summary: Delete entity from CountryOrRegion
314+
operationId: CountryOrRegion.CountryOrRegion.DeleteCountryOrRegion
315315
parameters:
316316
- in: path
317317
name: Name
@@ -481,8 +481,8 @@ paths:
481481
get:
482482
tags:
483483
- People.Person
484-
summary: Get entity from People by key (UserName)
485-
operationId: People.Person.GetPersonByUserName
484+
summary: Get entity from People by key
485+
operationId: People.Person.GetPerson
486486
produces:
487487
- application/json
488488
parameters:
@@ -522,8 +522,8 @@ paths:
522522
patch:
523523
tags:
524524
- People.Person
525-
summary: Update entity in People by key (UserName)
526-
operationId: People.Person.UpdatePersonByUserName
525+
summary: Update entity in People
526+
operationId: People.Person.UpdatePerson
527527
consumes:
528528
- application/json
529529
parameters:
@@ -548,8 +548,8 @@ paths:
548548
delete:
549549
tags:
550550
- People.Person
551-
summary: Delete entity from People by key (UserName)
552-
operationId: People.Person.DeletePersonByUserName
551+
summary: Delete entity from People
552+
operationId: People.Person.DeletePerson
553553
parameters:
554554
- in: path
555555
name: UserName

0 commit comments

Comments
 (0)