OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
686 stars 349 forks source link

$root literal #2794

Open mata007 opened 1 year ago

mata007 commented 1 year ago

Hello, I wanted to use Microsoft.OData.UriParser.ODataUriParser to parse a URL in which the $root literal was used.

The OData 4.01 specification states the following:

5.1.1.14.5 [$root](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_root)
The $root literal can be used in expressions to refer to resources of the same service. It can be used as a single-valued expression or within [complex or collection literals](https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_ComplexandCollectionLiterals).

Example 108: all employees with the same last name as employee A1235
http://host/service/Employees?$filter=LastName eq $root/Employees('A1245')/LastName

Example 109: products ordered by a set of customers, where the set of customers is passed as a JSON array containing the resource paths from $root to each customer.
http://host/service/ProductsOrderedBy(Customers=@c)?@c=[$root/Customers('ALFKI'),$root/Customers('BLAUS')]

However, if I used the parser on the example from the specification ( http://host/service/Employees?$filter=LastName eq $root/Employees('A1245')/LastName ), the parser would return the error "Could not find a property named '$root' on type 'Employees'."

I don't know if I'm doing something wrong, or if this literal is not implemented. And if it's not implemented, I'd like to ask if that's in the plans. Alternatively, if it is possible to solve it somehow at the moment.

ElizabethOkerio commented 12 months ago

@mata007 we currently do not support $root. We welcome a contribution.