Skip to content

Commit 9237f38

Browse files
authored
Generates unique DELETE operation ids of $ref paths for indexed collection navigation properties (#513)
* Get unique operation id for $ref DELETE with index nav. prop. * Add new reusable property * Update tests * Update release notes
1 parent aad727a commit 9237f38

11 files changed

+111
-101
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,13 @@
1515
<TargetFrameworks>netstandard2.0</TargetFrameworks>
1616
<PackageId>Microsoft.OpenApi.OData</PackageId>
1717
<SignAssembly>true</SignAssembly>
18-
<Version>1.6.0</Version>
18+
<Version>1.6.1</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>
2222
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET.OData</RepositoryUrl>
2323
<PackageReleaseNotes>
24-
- Reads annotations on structural properties of stream types for media entity paths #399
25-
- Updates the format of the request body schema of a collection of complex property #423
26-
- Adds a delete operation and a required @id query parameter to collection-valued navigation property paths with $ref #453
27-
- Fixes inconsistency of nullability of schemas of properties that are a collection of structured types #467
28-
- Generates $expand query parameter for operations whose return type is a collection #481
29-
- Adds delete operation for non-contained navigation properties only if explicitly allowed via annotation #483
30-
- Appends parameters and fixes operation ids of navigation property paths generated via composable functions #486
31-
- Use alternate keys in the generation of operation ids of operations and navigation property alternate paths #488
32-
- Fixes operation ids of paths with type cast segments #492
33-
- Uses convert setting to toggle between generating query options schemas of type string array or enums #197
34-
- Adds ability to change the response or request body content media type based on custom annotation properties #405
24+
- Generates unique DELETE operation ids of $ref paths for indexed collection navigation properties #513
3525
</PackageReleaseNotes>
3626
<AssemblyName>Microsoft.OpenApi.OData.Reader</AssemblyName>
3727
<AssemblyOriginatorKeyFile>..\..\tool\Microsoft.OpenApi.OData.snk</AssemblyOriginatorKeyFile>

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ internal abstract class NavigationPropertyOperationHandler : OperationHandler
3939
/// <summary>
4040
/// Gets a bool value indicating whether the last segment is a key segment.
4141
/// </summary>
42-
protected bool LastSegmentIsKeySegment { get; private set; }
42+
protected bool LastSegmentIsKeySegment { get; private set; }
43+
44+
/// <summary>
45+
/// Gets a bool value indicating whether the second last segment in a $ref path is a key segment
46+
/// </summary>
47+
protected bool SecondLastSegmentIsKeySegment { get; private set; }
4348

4449
/// <summary>
4550
/// Gets a bool value indicating whether the last segment is a $ref segment.
@@ -55,7 +60,8 @@ protected override void Initialize(ODataContext context, ODataPath path)
5560
NavigationSource = navigationSourceSegment.NavigationSource;
5661

5762
LastSegmentIsKeySegment = path.LastSegment is ODataKeySegment;
58-
LastSegmentIsRefSegment = path.LastSegment is ODataRefSegment;
63+
LastSegmentIsRefSegment = path.LastSegment is ODataRefSegment;
64+
SecondLastSegmentIsKeySegment = Path.Segments.Reverse().Skip(1).Take(1).Single().Kind == ODataSegmentKind.Key;
5965
NavigationProperty = path.OfType<ODataNavigationPropertySegment>().Last().NavigationProperty;
6066

6167
IEdmEntitySet entitySet = NavigationSource as IEdmEntitySet;

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

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

6-
using System.Linq;
76
using Microsoft.OData.Edm;
87
using Microsoft.OpenApi.Models;
98
using Microsoft.OpenApi.OData.Common;
109
using Microsoft.OpenApi.OData.Edm;
1110
using Microsoft.OpenApi.OData.Generator;
1211
using Microsoft.OpenApi.OData.Vocabulary.Capabilities;
12+
using System.Linq;
1313

1414
namespace Microsoft.OpenApi.OData.Operation
1515
{
@@ -40,8 +40,22 @@ protected override void SetBasicInfo(OpenApiOperation operation)
4040
// OperationId
4141
if (Context.Settings.EnableOperationId)
4242
{
43-
string prefix = "DeleteRef";
44-
operation.OperationId = GetOperationId(prefix);
43+
string prefix = "DeleteRef";
44+
var segments = GetOperationId().Split('.').ToList();
45+
46+
if (SecondLastSegmentIsKeySegment)
47+
{
48+
segments[segments.Count - 1] = Utils.ToFirstCharacterLowerCase(segments[segments.Count - 1]);
49+
var lastSegment = prefix + Utils.UpperFirstChar(NavigationProperty.ToEntityType().Name);
50+
segments.Add(lastSegment);
51+
operation.OperationId = string.Join(".", segments);
52+
}
53+
else
54+
{
55+
var lastSegment = segments.LastOrDefault();
56+
segments[segments.Count - 1] = prefix + lastSegment;
57+
operation.OperationId = string.Join(".", segments);
58+
}
4559
}
4660
}
4761

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@
760760
"Documents.RevisionDto"
761761
],
762762
"summary": "Delete ref of navigation property Revisions for Documents",
763-
"operationId": "Documents.DeleteRefRevisions",
763+
"operationId": "Documents.revisions.DeleteRefRevisionDto",
764764
"parameters": [
765765
{
766766
"in": "path",
@@ -1673,7 +1673,7 @@
16731673
"Libraries.DocumentDto"
16741674
],
16751675
"summary": "Delete ref of navigation property Documents for Libraries",
1676-
"operationId": "Libraries.DeleteRefDocuments",
1676+
"operationId": "Libraries.documents.DeleteRefDocumentDto",
16771677
"parameters": [
16781678
{
16791679
"in": "path",
@@ -3688,7 +3688,7 @@
36883688
"Tasks.RevisionDto"
36893689
],
36903690
"summary": "Delete ref of navigation property Revisions for Tasks",
3691-
"operationId": "Tasks.DeleteRefRevisions",
3691+
"operationId": "Tasks.revisions.DeleteRefRevisionDto",
36923692
"parameters": [
36933693
{
36943694
"in": "path",

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ paths:
541541
tags:
542542
- Documents.RevisionDto
543543
summary: Delete ref of navigation property Revisions for Documents
544-
operationId: Documents.DeleteRefRevisions
544+
operationId: Documents.revisions.DeleteRefRevisionDto
545545
parameters:
546546
- in: path
547547
name: Id
@@ -1185,7 +1185,7 @@ paths:
11851185
tags:
11861186
- Libraries.DocumentDto
11871187
summary: Delete ref of navigation property Documents for Libraries
1188-
operationId: Libraries.DeleteRefDocuments
1188+
operationId: Libraries.documents.DeleteRefDocumentDto
11891189
parameters:
11901190
- in: path
11911191
name: Id
@@ -2623,7 +2623,7 @@ paths:
26232623
tags:
26242624
- Tasks.RevisionDto
26252625
summary: Delete ref of navigation property Revisions for Tasks
2626-
operationId: Tasks.DeleteRefRevisions
2626+
operationId: Tasks.revisions.DeleteRefRevisionDto
26272627
parameters:
26282628
- in: path
26292629
name: Id

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@
851851
"Documents.RevisionDto"
852852
],
853853
"summary": "Delete ref of navigation property Revisions for Documents",
854-
"operationId": "Documents.DeleteRefRevisions",
854+
"operationId": "Documents.revisions.DeleteRefRevisionDto",
855855
"parameters": [
856856
{
857857
"name": "Id",
@@ -1863,7 +1863,7 @@
18631863
"Libraries.DocumentDto"
18641864
],
18651865
"summary": "Delete ref of navigation property Documents for Libraries",
1866-
"operationId": "Libraries.DeleteRefDocuments",
1866+
"operationId": "Libraries.documents.DeleteRefDocumentDto",
18671867
"parameters": [
18681868
{
18691869
"name": "Id",
@@ -4128,7 +4128,7 @@
41284128
"Tasks.RevisionDto"
41294129
],
41304130
"summary": "Delete ref of navigation property Revisions for Tasks",
4131-
"operationId": "Tasks.DeleteRefRevisions",
4131+
"operationId": "Tasks.revisions.DeleteRefRevisionDto",
41324132
"parameters": [
41334133
{
41344134
"name": "Id",

test/Microsoft.OpenAPI.OData.Reader.Tests/Resources/Multiple.Schema.OpenApi.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ paths:
602602
tags:
603603
- Documents.RevisionDto
604604
summary: Delete ref of navigation property Revisions for Documents
605-
operationId: Documents.DeleteRefRevisions
605+
operationId: Documents.revisions.DeleteRefRevisionDto
606606
parameters:
607607
- name: Id
608608
in: path
@@ -1312,7 +1312,7 @@ paths:
13121312
tags:
13131313
- Libraries.DocumentDto
13141314
summary: Delete ref of navigation property Documents for Libraries
1315-
operationId: Libraries.DeleteRefDocuments
1315+
operationId: Libraries.documents.DeleteRefDocumentDto
13161316
parameters:
13171317
- name: Id
13181318
in: path
@@ -2913,7 +2913,7 @@ paths:
29132913
tags:
29142914
- Tasks.RevisionDto
29152915
summary: Delete ref of navigation property Revisions for Tasks
2916-
operationId: Tasks.DeleteRefRevisions
2916+
operationId: Tasks.revisions.DeleteRefRevisionDto
29172917
parameters:
29182918
- name: Id
29192919
in: path

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,7 +2238,7 @@
22382238
"Me.Person"
22392239
],
22402240
"summary": "Delete ref of navigation property Friends for Me",
2241-
"operationId": "Me.DeleteRefFriends",
2241+
"operationId": "Me.friends.DeleteRefPerson",
22422242
"parameters": [
22432243
{
22442244
"in": "path",
@@ -4261,7 +4261,7 @@
42614261
"Me.Person"
42624262
],
42634263
"summary": "Delete ref of navigation property Friends for Me",
4264-
"operationId": "Me.AsEmployee.DeleteRefFriends",
4264+
"operationId": "Me.AsEmployee.friends.DeleteRefPerson",
42654265
"parameters": [
42664266
{
42674267
"in": "path",
@@ -5228,7 +5228,7 @@
52285228
"Me.Person"
52295229
],
52305230
"summary": "Delete ref of navigation property Peers for Me",
5231-
"operationId": "Me.AsEmployee.DeleteRefPeers",
5231+
"operationId": "Me.AsEmployee.peers.DeleteRefPerson",
52325232
"parameters": [
52335233
{
52345234
"in": "path",
@@ -6329,7 +6329,7 @@
63296329
"Me.Trips.PlanItem"
63306330
],
63316331
"summary": "Delete ref of navigation property PlanItems for Me",
6332-
"operationId": "Me.AsEmployee.Trips.DeleteRefPlanItems",
6332+
"operationId": "Me.AsEmployee.Trips.planItems.DeleteRefPlanItem",
63336333
"parameters": [
63346334
{
63356335
"in": "path",
@@ -7768,7 +7768,7 @@
77687768
"Me.Person"
77697769
],
77707770
"summary": "Delete ref of navigation property DirectReports for Me",
7771-
"operationId": "Me.AsManager.DeleteRefDirectReports",
7771+
"operationId": "Me.AsManager.directReports.DeleteRefPerson",
77727772
"parameters": [
77737773
{
77747774
"in": "path",
@@ -8491,7 +8491,7 @@
84918491
"Me.Person"
84928492
],
84938493
"summary": "Delete ref of navigation property Friends for Me",
8494-
"operationId": "Me.AsManager.DeleteRefFriends",
8494+
"operationId": "Me.AsManager.friends.DeleteRefPerson",
84958495
"parameters": [
84968496
{
84978497
"in": "path",
@@ -9910,7 +9910,7 @@
99109910
"Me.Trips.PlanItem"
99119911
],
99129912
"summary": "Delete ref of navigation property PlanItems for Me",
9913-
"operationId": "Me.AsManager.Trips.DeleteRefPlanItems",
9913+
"operationId": "Me.AsManager.Trips.planItems.DeleteRefPlanItem",
99149914
"parameters": [
99159915
{
99169916
"in": "path",
@@ -10749,7 +10749,7 @@
1074910749
"Me.Trips.PlanItem"
1075010750
],
1075110751
"summary": "Delete ref of navigation property PlanItems for Me",
10752-
"operationId": "Me.Trips.DeleteRefPlanItems",
10752+
"operationId": "Me.Trips.planItems.DeleteRefPlanItem",
1075310753
"parameters": [
1075410754
{
1075510755
"in": "path",
@@ -12414,7 +12414,7 @@
1241412414
"NewComePeople.Person"
1241512415
],
1241612416
"summary": "Delete ref of navigation property Friends for NewComePeople",
12417-
"operationId": "NewComePeople.DeleteRefFriends",
12417+
"operationId": "NewComePeople.friends.DeleteRefPerson",
1241812418
"parameters": [
1241912419
{
1242012420
"in": "path",
@@ -14250,7 +14250,7 @@
1425014250
"NewComePeople.Trips.PlanItem"
1425114251
],
1425214252
"summary": "Delete ref of navigation property PlanItems for NewComePeople",
14253-
"operationId": "NewComePeople.Trips.DeleteRefPlanItems",
14253+
"operationId": "NewComePeople.Trips.planItems.DeleteRefPlanItem",
1425414254
"parameters": [
1425514255
{
1425614256
"in": "path",
@@ -16015,7 +16015,7 @@
1601516015
"People.Person"
1601616016
],
1601716017
"summary": "Delete ref of navigation property Friends for People",
16018-
"operationId": "People.DeleteRefFriends",
16018+
"operationId": "People.friends.DeleteRefPerson",
1601916019
"parameters": [
1602016020
{
1602116021
"in": "path",
@@ -18428,7 +18428,7 @@
1842818428
"People.Person"
1842918429
],
1843018430
"summary": "Delete ref of navigation property Friends for People",
18431-
"operationId": "People.AsEmployee.DeleteRefFriends",
18431+
"operationId": "People.AsEmployee.friends.DeleteRefPerson",
1843218432
"parameters": [
1843318433
{
1843418434
"in": "path",
@@ -19565,7 +19565,7 @@
1956519565
"People.Person"
1956619566
],
1956719567
"summary": "Delete ref of navigation property Peers for People",
19568-
"operationId": "People.AsEmployee.DeleteRefPeers",
19568+
"operationId": "People.AsEmployee.peers.DeleteRefPerson",
1956919569
"parameters": [
1957019570
{
1957119571
"in": "path",
@@ -20834,7 +20834,7 @@
2083420834
"People.Trips.PlanItem"
2083520835
],
2083620836
"summary": "Delete ref of navigation property PlanItems for People",
20837-
"operationId": "People.AsEmployee.Trips.DeleteRefPlanItems",
20837+
"operationId": "People.AsEmployee.Trips.planItems.DeleteRefPlanItem",
2083820838
"parameters": [
2083920839
{
2084020840
"in": "path",
@@ -22551,7 +22551,7 @@
2255122551
"People.Person"
2255222552
],
2255322553
"summary": "Delete ref of navigation property DirectReports for People",
22554-
"operationId": "People.AsManager.DeleteRefDirectReports",
22554+
"operationId": "People.AsManager.directReports.DeleteRefPerson",
2255522555
"parameters": [
2255622556
{
2255722557
"in": "path",
@@ -23394,7 +23394,7 @@
2339423394
"People.Person"
2339523395
],
2339623396
"summary": "Delete ref of navigation property Friends for People",
23397-
"operationId": "People.AsManager.DeleteRefFriends",
23397+
"operationId": "People.AsManager.friends.DeleteRefPerson",
2339823398
"parameters": [
2339923399
{
2340023400
"in": "path",
@@ -25039,7 +25039,7 @@
2503925039
"People.Trips.PlanItem"
2504025040
],
2504125041
"summary": "Delete ref of navigation property PlanItems for People",
25042-
"operationId": "People.AsManager.Trips.DeleteRefPlanItems",
25042+
"operationId": "People.AsManager.Trips.planItems.DeleteRefPlanItem",
2504325043
"parameters": [
2504425044
{
2504525045
"in": "path",
@@ -25998,7 +25998,7 @@
2599825998
"People.Trips.PlanItem"
2599925999
],
2600026000
"summary": "Delete ref of navigation property PlanItems for People",
26001-
"operationId": "People.Trips.DeleteRefPlanItems",
26001+
"operationId": "People.Trips.planItems.DeleteRefPlanItem",
2600226002
"parameters": [
2600326003
{
2600426004
"in": "path",

0 commit comments

Comments
 (0)