Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ODataApplicationModelProvider ignores controllers with only specific methods marked with ODataAttributeRoutingAttribute #1118

Open
1 task done
jberezanski-mdg opened this issue Jan 14, 2025 · 0 comments
Assignees

Comments

@jberezanski-mdg
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In the application I'm working on there are several controllers which need OData to be enabled on specific actions only.
ASP.NET OData provides two ways of defining this:

  1. marking the controller type with [ODataAttributeRouting] (or inheriting from ODataController) and marking methods which should be excluded from OData with [ODataIgnored],
  2. marking only certain methods of the controller with [ODataAttributeRouting].

Most of Asp.Versioning looks for ODataAttributeRoutingAttribute at both controller and action level. Unfortunately, ODataApplicationModelProvider checks the presence of this attribute at controller level only, by calling the static method ODataControllerSpecification.IsSatisfiedBy(ICommonModel model). This prevents method 2 above from working correctly, because the ODataApiVersionCollectionProvider.ApiVersions collection does not get populated, ODataMultiModelApplicationModelProvider does not get any models from VersionedODataModelBuilder and ultimately ODataRoutingMetadata is not set in the action endpoint metadata.

Expected Behavior

ODataApplicationModelProvider should consider all controller actions for which either 1) the controller is decorated with [ODataAttributeRouting] and the action is not decorated with [ODataIgnored], or 2) the action is decorated with [ODataAttributeRouting].

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

.NET 8.0.11, Microsoft.AspNetCore.OData 8.2.7, Asp.Versioning 8.1.0

Anything else?

The issue is not very critical for my team, because we can mark the entire controllers with ODataAttributeRouting as a workaround. However, it was surprising, cost us some debugging time and the behavior is in conflict with the Microsoft documentation, so I wanted to leave at least a description of it here.

Thank you a lot for creating and maintaining this project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants