Skip to content
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 @@ -3,10 +3,8 @@
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.OData.Edm;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
Expand Down Expand Up @@ -66,7 +64,26 @@ protected override void SetBasicInfo(OpenApiOperation operation)
// OperationId
if (Context.Settings.EnableOperationId)
{
string operationId = String.Join(".", Path.Segments.Where(s => !(s is ODataKeySegment)).Select(s => s.Identifier));
// When the key segment is available,
// its EntityType name will be used
// in the operationId to avoid potential
// duplicates in entity vs entityset functions/actions

List<string> identifiers = new();
foreach (ODataSegment segment in Path.Segments)
{
if (segment is not ODataKeySegment)
Copy link
Contributor

@thewahome thewahome Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice!

{
identifiers.Add(segment.Identifier);
}
else
{
identifiers.Add(segment.EntityType.Name);
}
}

string operationId = string.Join(".", identifiers);

if (EdmOperation.IsAction())
{
operation.OperationId = operationId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,25 @@ public void CreateOperationForEdmActionReturnsCorrectOperationId(bool enableOper
new ODataKeySegment(customer),
new ODataOperationSegment(action));

ODataPath path2 = new ODataPath(new ODataNavigationSourceSegment(customers),
new ODataOperationSegment(action));

// Act
var operation = _operationHandler.CreateOperation(context, path);
var operation2 = _operationHandler.CreateOperation(context, path2);

// Assert
Assert.NotNull(operation);

if (enableOperationId)
{
Assert.Equal("Customers.MyAction", operation.OperationId);
Assert.Equal("Customers.Customer.MyAction", operation.OperationId);
Assert.Equal("Customers.MyAction", operation2.OperationId);
}
else
{
Assert.Null(operation.OperationId);
Assert.Null(operation2.OperationId);
}
}

Expand Down Expand Up @@ -171,7 +177,7 @@ public void CreateOperationForEdmActionWithTypeCastReturnsCorrectOperationId(boo

if (enableOperationId)
{
Assert.Equal("Customers.NS.VipCustomer.MyAction", operation.OperationId);
Assert.Equal("Customers.Customer.NS.VipCustomer.MyAction", operation.OperationId);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,19 +116,25 @@ public void CreateOperationForEdmFunctionReturnsCorrectOperationId(bool enableOp
new ODataKeySegment(customer),
new ODataOperationSegment(function));

ODataPath path2 = new ODataPath(new ODataNavigationSourceSegment(customers),
new ODataOperationSegment(function));

// Act
var operation = _operationHandler.CreateOperation(context, path);
var operation2 = _operationHandler.CreateOperation(context, path2);

// Assert
Assert.NotNull(operation);

if (enableOperationId)
{
Assert.Equal("Customers.MyFunction", operation.OperationId);
Assert.Equal("Customers.Customer.MyFunction", operation.OperationId);
Assert.Equal("Customers.MyFunction", operation2.OperationId);
}
else
{
Assert.Null(operation.OperationId);
Assert.Null(operation2.OperationId);
}
}

Expand Down Expand Up @@ -171,7 +177,7 @@ public void CreateOperationForEdmFunctionWithTypeCastReturnsCorrectOperationId(b

if (enableOperationId)
{
Assert.Equal("Customers.NS.VipCustomer.MyFunction", operation.OperationId);
Assert.Equal("Customers.Customer.NS.VipCustomer.MyFunction", operation.OperationId);
}
else
{
Expand Down Expand Up @@ -222,7 +228,7 @@ public void CreateOperationForOverloadEdmFunctionReturnsCorrectOperationId(bool

if (enableOperationId)
{
Assert.Equal("Customers.MyFunction-28ae", operation.OperationId);
Assert.Equal("Customers.Customer.MyFunction-28ae", operation.OperationId);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@
"Documents.Actions"
],
"summary": "Invoke action Upload",
"operationId": "Documents.Upload",
"operationId": "Documents.DocumentDto.Upload",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -2381,7 +2381,7 @@
"Tasks.Actions"
],
"summary": "Invoke action Upload",
"operationId": "Tasks.Upload",
"operationId": "Tasks.DocumentDto.Upload",
"produces": [
"application/json"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ paths:
tags:
- Documents.Actions
summary: Invoke action Upload
operationId: Documents.Upload
operationId: Documents.DocumentDto.Upload
produces:
- application/json
parameters:
Expand Down Expand Up @@ -1720,7 +1720,7 @@ paths:
tags:
- Tasks.Actions
summary: Invoke action Upload
operationId: Tasks.Upload
operationId: Tasks.DocumentDto.Upload
produces:
- application/json
parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@
"Documents.Actions"
],
"summary": "Invoke action Upload",
"operationId": "Documents.Upload",
"operationId": "Documents.DocumentDto.Upload",
"parameters": [
{
"name": "Id",
Expand Down Expand Up @@ -2718,7 +2718,7 @@
"Tasks.Actions"
],
"summary": "Invoke action Upload",
"operationId": "Tasks.Upload",
"operationId": "Tasks.DocumentDto.Upload",
"parameters": [
{
"name": "Id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ paths:
tags:
- Documents.Actions
summary: Invoke action Upload
operationId: Documents.Upload
operationId: Documents.DocumentDto.Upload
parameters:
- name: Id
in: path
Expand Down Expand Up @@ -1935,7 +1935,7 @@ paths:
tags:
- Tasks.Actions
summary: Invoke action Upload
operationId: Tasks.Upload
operationId: Tasks.DocumentDto.Upload
parameters:
- name: Id
in: path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@
"Me.Functions"
],
"summary": "Invoke function GetInvolvedPeople",
"operationId": "Me.Trips.GetInvolvedPeople",
"operationId": "Me.Trips.Trip.GetInvolvedPeople",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -2598,7 +2598,7 @@
"NewComePeople.Functions"
],
"summary": "Invoke function GetFavoriteAirline",
"operationId": "NewComePeople.GetFavoriteAirline",
"operationId": "NewComePeople.Person.GetFavoriteAirline",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -2632,7 +2632,7 @@
"NewComePeople.Functions"
],
"summary": "Invoke function GetFriendsTrips",
"operationId": "NewComePeople.GetFriendsTrips",
"operationId": "NewComePeople.Person.GetFriendsTrips",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -2676,7 +2676,7 @@
"NewComePeople.Actions"
],
"summary": "Invoke action GetPeersForTrip",
"operationId": "NewComePeople.GetPeersForTrip",
"operationId": "NewComePeople.Person.GetPeersForTrip",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -2736,7 +2736,7 @@
"NewComePeople.Actions"
],
"summary": "Invoke action ShareTrip",
"operationId": "NewComePeople.ShareTrip",
"operationId": "NewComePeople.Person.ShareTrip",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -2787,7 +2787,7 @@
"NewComePeople.Functions"
],
"summary": "Invoke function UpdatePersonLastName",
"operationId": "NewComePeople.UpdatePersonLastName",
"operationId": "NewComePeople.Person.UpdatePersonLastName",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -3161,7 +3161,7 @@
"NewComePeople.Functions"
],
"summary": "Invoke function GetInvolvedPeople",
"operationId": "NewComePeople.Trips.GetInvolvedPeople",
"operationId": "NewComePeople.Person.Trips.Trip.GetInvolvedPeople",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -4227,7 +4227,7 @@
"People.Functions"
],
"summary": "Invoke function GetFavoriteAirline",
"operationId": "People.GetFavoriteAirline",
"operationId": "People.Person.GetFavoriteAirline",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -4261,7 +4261,7 @@
"People.Functions"
],
"summary": "Invoke function GetFriendsTrips",
"operationId": "People.GetFriendsTrips",
"operationId": "People.Person.GetFriendsTrips",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -4305,7 +4305,7 @@
"People.Actions"
],
"summary": "Invoke action GetPeersForTrip",
"operationId": "People.GetPeersForTrip",
"operationId": "People.Person.GetPeersForTrip",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -4365,7 +4365,7 @@
"People.Actions"
],
"summary": "Invoke action ShareTrip",
"operationId": "People.ShareTrip",
"operationId": "People.Person.ShareTrip",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -4416,7 +4416,7 @@
"People.Functions"
],
"summary": "Invoke function UpdatePersonLastName",
"operationId": "People.UpdatePersonLastName",
"operationId": "People.Person.UpdatePersonLastName",
"produces": [
"application/json"
],
Expand Down Expand Up @@ -4790,7 +4790,7 @@
"People.Functions"
],
"summary": "Invoke function GetInvolvedPeople",
"operationId": "People.Trips.GetInvolvedPeople",
"operationId": "People.Person.Trips.Trip.GetInvolvedPeople",
"produces": [
"application/json"
],
Expand Down
Loading