Skip to content

Commit 494f302

Browse files
Microsoft Graph DevX ToolingMicrosoft Graph DevX Tooling
authored andcommitted
Updated operation handler to make use of EDMOperation object instead of using Odata operation segment. Updated test files and regenerated yaml and json resource files
1 parent 3b4b0d1 commit 494f302

11 files changed

+189
-97
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected override void SetBasicInfo(OpenApiOperation operation)
8585
{
8686
if (segment is ODataKeySegment keySegment)
8787
{
88-
if (!keySegment.IsAlternateKey)
88+
if (!keySegment.IsAlternateKey)
8989
{
9090
identifiers.Add(segment.EntityType.Name);
9191
continue;
@@ -152,7 +152,7 @@ protected override void SetTags(OpenApiOperation operation)
152152
/// <param name="tagName">The generated tag name.</param>
153153
/// <param name="skip">The number of segments to skip.</param>
154154
private void GenerateTagName(out string tagName, int skip = 1)
155-
{
155+
{
156156
var targetSegment = Path.Segments.Reverse().Skip(skip).FirstOrDefault();
157157

158158
switch (targetSegment)
@@ -166,21 +166,17 @@ private void GenerateTagName(out string tagName, int skip = 1)
166166
skip += 1;
167167
GenerateTagName(out tagName, skip);
168168
break;
169-
// If the operation is a function or action, append the word "Function" or "Action" to the tag name
170-
case ODataOperationSegment operationSegment:
169+
default:
171170
tagName = NavigationSource.Name + "." + NavigationSource.EntityType().Name;
172-
if(operationSegment.Operation.IsAction())
171+
if (EdmOperation.IsAction())
173172
{
174173
tagName += ".Actions";
175174
}
176-
177-
if(operationSegment.Operation.IsFunction())
175+
else if (EdmOperation.IsFunction())
178176
{
179177
tagName += ".Functions";
180178
}
181-
break;
182-
default:
183-
tagName = NavigationSource.Name + "." + NavigationSource.EntityType().Name;
179+
184180
break;
185181
}
186182
}
@@ -198,7 +194,7 @@ protected override void SetParameters(OpenApiOperation operation)
198194
}
199195

200196
/// <inheritdoc/>
201-
protected override void SetResponses(OpenApiOperation operation)
197+
protected override void SetResponses(OpenApiOperation operation)
202198
{
203199
operation.Responses = Context.CreateResponses(EdmOperation);
204200
base.SetResponses(operation);
@@ -298,10 +294,10 @@ protected override void SetCustomLinkRelType()
298294
{
299295
LinkRelKey key = EdmOperation.IsAction() ? LinkRelKey.Action : LinkRelKey.Function;
300296
Context.Settings.CustomHttpMethodLinkRelMapping.TryGetValue(key, out string linkRelValue);
301-
CustomLinkRel = linkRelValue;
297+
CustomLinkRel = linkRelValue;
302298
}
303299
}
304-
300+
305301
/// <inheritdoc/>
306302
protected override void SetExternalDocs(OpenApiOperation operation)
307303
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void CreateOperationForEdmActionReturnsCorrectOperation()
4040
Assert.Equal("Details of the shared trip.", operation.Description);
4141
Assert.NotNull(operation.Tags);
4242
var tag = Assert.Single(operation.Tags);
43-
Assert.Equal("People.Person", tag.Name);
43+
Assert.Equal("People.Person.Actions", tag.Name);
4444

4545
Assert.NotNull(operation.Parameters);
4646
Assert.Single(operation.Parameters);
@@ -79,7 +79,7 @@ public void CreateOperationForEdmActionReturnsCorrectOperationHierarchicalClass(
7979
Assert.Equal($"Invoke action {actionName}", operation.Summary);
8080
Assert.NotNull(operation.Tags);
8181
var tag = Assert.Single(operation.Tags);
82-
Assert.Equal($"{entitySetName}.AccountApiModel", tag.Name);
82+
Assert.Equal($"{entitySetName}.AccountApiModel.Actions", tag.Name);
8383

8484
Assert.NotNull(operation.Parameters);
8585
Assert.Single(operation.Parameters);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void CreateOperationForEdmFunctionReturnsCorrectOperation(bool useHTTPSta
100100
Assert.Equal("Invoke function GetFavoriteAirline", operation.Summary);
101101
Assert.NotNull(operation.Tags);
102102
var tag = Assert.Single(operation.Tags);
103-
Assert.Equal("People.Person", tag.Name);
103+
Assert.Equal("People.Person.Functions", tag.Name);
104104

105105
Assert.NotNull(operation.Parameters);
106106
Assert.Single(operation.Parameters);
@@ -138,7 +138,7 @@ public void CreateOperationForEdmFunctionReturnsCorrectOperationHierarchicalClas
138138
Assert.Equal("Collection of contract attachments.", operation.Description);
139139
Assert.NotNull(operation.Tags);
140140
var tag = Assert.Single(operation.Tags);
141-
Assert.Equal($"{entitySetName}.AccountApiModel", tag.Name);
141+
Assert.Equal($"{entitySetName}.AccountApiModel.Functions", tag.Name);
142142

143143
Assert.NotNull(operation.Parameters);
144144
Assert.Equal(6, operation.Parameters.Count); // id, top, skip, count, search, filter

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@
591591
"/Documents({Id})/Default.Upload": {
592592
"post": {
593593
"tags": [
594-
"Documents.DocumentDto"
594+
"Documents.DocumentDto.Actions"
595595
],
596596
"summary": "Invoke action Upload",
597597
"operationId": "Documents.DocumentDto.Upload",
@@ -3519,7 +3519,7 @@
35193519
"/Tasks({Id})/Default.Upload": {
35203520
"post": {
35213521
"tags": [
3522-
"Tasks.DocumentDto"
3522+
"Tasks.DocumentDto.Actions"
35233523
],
35243524
"summary": "Invoke action Upload",
35253525
"operationId": "Tasks.DocumentDto.Upload",
@@ -6275,6 +6275,10 @@
62756275
"name": "Documents.DocumentDto",
62766276
"x-ms-docs-toc-type": "page"
62776277
},
6278+
{
6279+
"name": "Documents.DocumentDto.Actions",
6280+
"x-ms-docs-toc-type": "container"
6281+
},
62786282
{
62796283
"name": "Documents.RevisionDto",
62806284
"x-ms-docs-toc-type": "page"
@@ -6315,6 +6319,10 @@
63156319
"name": "Tasks.DocumentDto",
63166320
"x-ms-docs-toc-type": "page"
63176321
},
6322+
{
6323+
"name": "Tasks.DocumentDto.Actions",
6324+
"x-ms-docs-toc-type": "container"
6325+
},
63186326
{
63196327
"name": "Tasks.RevisionDto",
63206328
"x-ms-docs-toc-type": "page"

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ paths:
413413
'/Documents({Id})/Default.Upload':
414414
post:
415415
tags:
416-
- Documents.DocumentDto
416+
- Documents.DocumentDto.Actions
417417
summary: Invoke action Upload
418418
operationId: Documents.DocumentDto.Upload
419419
parameters:
@@ -2495,7 +2495,7 @@ paths:
24952495
'/Tasks({Id})/Default.Upload':
24962496
post:
24972497
tags:
2498-
- Tasks.DocumentDto
2498+
- Tasks.DocumentDto.Actions
24992499
summary: Invoke action Upload
25002500
operationId: Tasks.DocumentDto.Upload
25012501
parameters:
@@ -4545,6 +4545,8 @@ tags:
45454545
x-ms-docs-toc-type: page
45464546
- name: Documents.DocumentDto
45474547
x-ms-docs-toc-type: page
4548+
- name: Documents.DocumentDto.Actions
4549+
x-ms-docs-toc-type: container
45484550
- name: Documents.RevisionDto
45494551
x-ms-docs-toc-type: page
45504552
- name: Documents.DocumentTagRelDto
@@ -4565,6 +4567,8 @@ tags:
45654567
x-ms-docs-toc-type: page
45664568
- name: Tasks.DocumentDto
45674569
x-ms-docs-toc-type: page
4570+
- name: Tasks.DocumentDto.Actions
4571+
x-ms-docs-toc-type: container
45684572
- name: Tasks.RevisionDto
45694573
x-ms-docs-toc-type: page
45704574
- name: Tasks.DocumentTagRelDto

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@
663663
"description": "Provides operations to call the Upload method.",
664664
"post": {
665665
"tags": [
666-
"Documents.DocumentDto"
666+
"Documents.DocumentDto.Actions"
667667
],
668668
"summary": "Invoke action Upload",
669669
"operationId": "Documents.DocumentDto.Upload",
@@ -3940,7 +3940,7 @@
39403940
"description": "Provides operations to call the Upload method.",
39413941
"post": {
39423942
"tags": [
3943-
"Tasks.DocumentDto"
3943+
"Tasks.DocumentDto.Actions"
39443944
],
39453945
"summary": "Invoke action Upload",
39463946
"operationId": "Tasks.DocumentDto.Upload",
@@ -7481,6 +7481,10 @@
74817481
"name": "Documents.DocumentDto",
74827482
"x-ms-docs-toc-type": "page"
74837483
},
7484+
{
7485+
"name": "Documents.DocumentDto.Actions",
7486+
"x-ms-docs-toc-type": "container"
7487+
},
74847488
{
74857489
"name": "Documents.RevisionDto",
74867490
"x-ms-docs-toc-type": "page"
@@ -7521,6 +7525,10 @@
75217525
"name": "Tasks.DocumentDto",
75227526
"x-ms-docs-toc-type": "page"
75237527
},
7528+
{
7529+
"name": "Tasks.DocumentDto.Actions",
7530+
"x-ms-docs-toc-type": "container"
7531+
},
75247532
{
75257533
"name": "Tasks.RevisionDto",
75267534
"x-ms-docs-toc-type": "page"

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ paths:
460460
description: Provides operations to call the Upload method.
461461
post:
462462
tags:
463-
- Documents.DocumentDto
463+
- Documents.DocumentDto.Actions
464464
summary: Invoke action Upload
465465
operationId: Documents.DocumentDto.Upload
466466
parameters:
@@ -2771,7 +2771,7 @@ paths:
27712771
description: Provides operations to call the Upload method.
27722772
post:
27732773
tags:
2774-
- Tasks.DocumentDto
2774+
- Tasks.DocumentDto.Actions
27752775
summary: Invoke action Upload
27762776
operationId: Tasks.DocumentDto.Upload
27772777
parameters:
@@ -5384,6 +5384,8 @@ tags:
53845384
x-ms-docs-toc-type: page
53855385
- name: Documents.DocumentDto
53865386
x-ms-docs-toc-type: page
5387+
- name: Documents.DocumentDto.Actions
5388+
x-ms-docs-toc-type: container
53875389
- name: Documents.RevisionDto
53885390
x-ms-docs-toc-type: page
53895391
- name: Documents.DocumentTagRelDto
@@ -5404,6 +5406,8 @@ tags:
54045406
x-ms-docs-toc-type: page
54055407
- name: Tasks.DocumentDto
54065408
x-ms-docs-toc-type: page
5409+
- name: Tasks.DocumentDto.Actions
5410+
x-ms-docs-toc-type: container
54075411
- name: Tasks.RevisionDto
54085412
x-ms-docs-toc-type: page
54095413
- name: Tasks.DocumentTagRelDto

0 commit comments

Comments
 (0)