Skip to content

Adding support for case insensitive action names - #519

Merged
xuzhg merged 2 commits into
OData:mainfrom
giulianob:case-insensitive-action
Mar 16, 2022
Merged

Adding support for case insensitive action names#519
xuzhg merged 2 commits into
OData:mainfrom
giulianob:case-insensitive-action

Conversation

@giulianob

Copy link
Copy Markdown
Contributor

I am working with an API which uses camel case OData action names but these are not found because the routing is case sensitive. For example, the following will not work:

// sample/ODataCustomizedSample/Models/EnumsEdmModel.cs:75
- var actionConfiguration = employee.Action("AddSkill");
+ var actionConfiguration = employee.Action("addSkill");

This fails because OperationRoutingConvension is case sensitive. Changing the following makes it work.

// src/Microsoft.AspNetCore.OData/Routing/Conventions/OperationRoutingConvention.cs:91
- IEnumerable<IEdmOperation> candidates = context.Model.SchemaElements.OfType<IEdmOperation>().Where(f => f.IsBound && f.Name == operationName);
+ IEnumerable<IEdmOperation> candidates = context.Model.SchemaElements.OfType<IEdmOperation>().Where(f => f.IsBound && string.Equals(f.Name, operationName, StringComparison.InvariantCultureIgnoreCase));

I have introduced the property EnableActionNameCaseInsensitive to optionally enable case insensitive action names.

@corranrogue9

Copy link
Copy Markdown
Contributor

@giulianob , thanks for the contribution! Did you file an issue for this? I'm pretty happy with the change, but it looks like the update to the API is causing a test failure. Can you take a look at that?

@giulianob
giulianob force-pushed the case-insensitive-action branch from e19646f to 3c481de Compare March 11, 2022 18:55
OData action naming convention can differ from the controller action convention by changing EnableActionNameCaseInsensitive
@giulianob
giulianob force-pushed the case-insensitive-action branch from 3c481de to 112de85 Compare March 11, 2022 19:13
@giulianob

Copy link
Copy Markdown
Contributor Author

@corranrogue9 Updated the API definitions. Do you want me to create an issue? I ran into the issue and created the PR.

Comment thread src/Microsoft.AspNetCore.OData/Routing/Conventions/OperationRoutingConvention.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Routing/Conventions/OperationRoutingConvention.cs Outdated

@xuzhg xuzhg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🕐

- Modified EntityRoutingConvention, EntitySetRoutingConvention, and SingletonRoutingConvention
- Added tests for all conventions
@giulianob
giulianob requested a review from xuzhg March 14, 2022 21:53
@giulianob

Copy link
Copy Markdown
Contributor Author

@xuzhg I resolved all of your comments. Thanks for the review.

@xuzhg
xuzhg merged commit f3fa98f into OData:main Mar 16, 2022
kakone pushed a commit to kakone/AspNetCoreOData that referenced this pull request Apr 3, 2022
* Adding support for case insensitive action names

OData action naming convention can differ from the controller action convention by changing EnableActionNameCaseInsensitive

* Adding case insensitive support to all conventions

- Modified EntityRoutingConvention, EntitySetRoutingConvention, and SingletonRoutingConvention
- Added tests for all conventions

Co-authored-by: Giuliano Barberi <gbarberi@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants