Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Actions and functions with the same name are not supported. #964

Answered by commonsensesoftware
zelins asked this question in Q&A
Discussion options

Hello,

I think my colleagues have found a defect in API versioning library, but I am not sure about it. So I hope the community can help me understand it and if it is a bug, it will be fixed in the next versions.
In our API our developers have defined two OData endpoints - action and function with the same name but different signature. Let's assume that these endpoints look like this:

// Function
GET odata/dosomestuff(param1={param1}) returns string

// Action
POST odata/dosomestuff(param1={param1}, param2={param2}) returns string

Defining such endpoints causes the startup failure of our application. Here is a part of the stack trace of the corresponding exception:

Unhandled Exception: System.InvalidOperationException: Sequence contains more than one element at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source)
at Asp.Versioning.Routing.ODataRouteBuilderContext.ResolveOperation(IEdmEntityContainer container, HttpActionDescriptor action) in //src/AspNet/OData/src/Asp.Versioning.WebApi.OData.ApiExplorer/Routing/ODataRouteBuilderContext.cs:line 393
at Asp.Versioning.Routing.ODataRouteBuilderContext..ctor(HttpConfiguration configuration, ApiVersion apiVersion, ODataRoute route, HttpActionDescriptor actionDescriptor, IList1 parameterDescriptions, IModelTypeBuilder modelTypeBuilder, ODataApiExplorerOptions options) in /_/src/AspNet/OData/src/Asp.Versioning.WebApi.OData.ApiExplorer/Routing/ODataRouteBuilderContext.cs:line 67 at Asp.Versioning.ApiExplorer.ODataApiExplorer.ExploreRouteActions(IHttpRoute route, HttpControllerDescriptor controllerDescriptor, IHttpActionSelector actionSelector, Collection1 apiDescriptions, ApiVersion apiVersion) in /
/src/AspNet/OData/src/Asp.Versioning.WebApi.OData.ApiExplorer/ApiExplorer/ODataApiExplorer.cs:line 336
at Asp.Versioning.ApiExplorer.ODataApiExplorer.ExploreRouteControllers(IDictionary2 controllerMappings, IHttpRoute route, ApiVersion apiVersion) in /_/src/AspNet/OData/src/Asp.Versioning.WebApi.OData.ApiExplorer/ApiExplorer/ODataApiExplorer.cs:line 212 at Asp.Versioning.ApiExplorer.VersionedApiExplorer.InitializeApiDescriptions() in /_/src/AspNet/WebApi/src/Asp.Versioning.WebApi.ApiExplorer/ApiExplorer/VersionedApiExplorer.cs:line 242

So it is unclear to me, should the OData protocol support actions and functions with the same name?

Thanks in advance

Best regards!

Dmytro

You must be logged in to vote

There are multiple things going on here. The signature for an OData Function and OData Action are quite different. An OData Action with parameters defined in the EDM are always in the body, which would look like:

POST odata/dosomestuff HTTP/2
Host: localhost
Content-Type: application/json
Content-Length: 42
{"param1": "Unit", "param2": "Test"}

The stack trace for the error you are showing is related to the API Explorer, which suggests you are trying to integrate this configuration with OpenAPI. There might be an issue there, but I'm not 100% sure - yet. It might be irrelevant though.

It wasn't clear if it's a supported scenario so I removed the API Versioning bits to take it out of the e...

Replies: 1 comment 1 reply

Comment options

There are multiple things going on here. The signature for an OData Function and OData Action are quite different. An OData Action with parameters defined in the EDM are always in the body, which would look like:

POST odata/dosomestuff HTTP/2
Host: localhost
Content-Type: application/json
Content-Length: 42
{"param1": "Unit", "param2": "Test"}

The stack trace for the error you are showing is related to the API Explorer, which suggests you are trying to integrate this configuration with OpenAPI. There might be an issue there, but I'm not 100% sure - yet. It might be irrelevant though.

It wasn't clear if it's a supported scenario so I removed the API Versioning bits to take it out of the equation. In the 7.5.14 version, the EDM didn't have a problem with the configuration, but the endpoints always return 404. Renaming one of the operations allows them to both work. In the event that it could be an OData bug, I updated to 7.6.4. In that version, the EDM performs validation that one of the route templates is valid.

Having an OData Function and OData Action with the same name seems strange to me. I cross-referenced the spec against the implementation and it does appear that using the same name for both is not allowed.

Both specifications state:

"The operation’s name is a simple identifier that MUST be unique within its schema."

Based on that information, I don't believe you make your configuration work. I recommend changing one the names or refactoring some other way. If you still have issues integrating with OpenAPI after that, I'm happy to have a look.

You must be logged in to vote
1 reply
Comment options

I made a mistake about action - we define it with body parameters as you showed.
According to your answer, it seems that we have to rename our methods.
Thank you for such a quick reply and for clarifying how odata should treat action/function names!

Answer selected by zelins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /