Skip to content

v0.25.0: $select into complex values

Latest

Choose a tag to compare

@jaravan jaravan released this 14 Nov 10:21

What's new

$select goes into a complex value

Selecting a field of a complex property was a 400 that gave the wrong advice, as if Location were a navigation:

GET /odata/v4/TripPin/Airports?$select=IcaoCode,Location/City/Name

{"error":{"code":"BadRequest","message":"$select can't go through Location: for a navigation, write $expand=Location($select=City/Name)"}}

V4 now serves it, with only the fields the path names, and the context URL lists the path:

{
  "@odata.context": "/odata/v4/TripPin/$metadata#Airports(IcaoCode,Location/City/Name)",
  "value": [{ "IcaoCode": "1", "Location": { "City": { "Name": "Paris" } } }]
}
  • At any depth (Place/Addr/City), and in each item of a collection (AddressInfo/City). Several paths into one value are merged.
  • On a collection, a single entity, inside $expand(...;$select=...), and with an $apply whose rows are still entities: identity, filter, orderby, concat.
  • A complex value selected whole as well ($select=Addr,Addr/City) is whole.
  • A path that leads nowhere is a 400 that says why: Nope is not a property of Addr, City isn't a complex property, so a path can't go into it. A path through a navigation still says to write $expand=Nav($select=...). A type cast in the path (Place/NS.Place2/Addr) is a 501.
  • V2 has no such path: $select=Addr/City stays a 400 there. Select Addr.

A generated row's names and emails belong to one person

A generated person had someone else's email addresses:

{ "FirstName": "Hugo", "LastName": "Silva", "Emails": ["grace.garcia@example.com", "david.schmidt@example.com"] }

A row now has one person, and its first and last name, contact name (ContactName, ContactPerson) and email addresses are theirs. A collection of addresses gets one per domain:

{ "FirstName": "Hugo", "LastName": "Silva", "Emails": ["hugo.silva@example.com", "hugo.silva@example.org"] }

CreatedBy, ChangedBy, Owner and Manager still get someone else: the person who changed an order isn't its contact.

A plain Name is what its type says

A property called just Name was its type's name and a number, so a city in France was called City 1:

"City": { "CountryRegion": "France", "Name": "City 1", "Region": "Île-de-France" }

It now follows the type it's in, and agrees with the rest of the row:

"City": { "CountryRegion": "France", "Name": "Paris", "Region": "Île-de-France" }
  • A City or Town gets the row's city, a Country or Region its country or region, a Product or Material the row's product, a Person, Employee or Contact the row's person, and a Company, Supplier, Vendor, Customer, Partner, Manufacturer or Shipper a company's name.
  • --explain no longer lists these as filler. A Name its type says nothing about, as an Airline's, is still Airline 1, and --explain still says so.

An entity without its key says which it is

With a $select that leaves out the key, nothing in the response said which entity a row was:

GET /odata/v4/PurchaseOrderSrv/PurchaseOrderSet?$select=Supplier

{"Supplier":"Hooli Electronics"}

That made a changed entity in a delta useless: {"Status":"Completed"}, but which order? Such an entity now carries its @odata.id, as OData 4.01 requires:

{ "@odata.id": "/odata/v4/PurchaseOrderSrv/PurchaseOrderSet('4500000001')", "Supplier": "Hooli Electronics" }

The same goes for an entity in an $expand, in a delta and in an $apply result. UI5 always selects the key, so a UI5 app sees no change.

Context URLs list expanded navigations

An $expand without its own $select was left out of the context URL, or listed as empty while it expanded more:

$expand=Items                                                  → $metadata#PurchaseOrderSet
$select=FirstName&$expand=Friends($expand=Friends($select=UserName)) → $metadata#People(FirstName,Friends())

The select-list now has every expanded navigation, with what it selects or expands, or () when it does neither (OData 4.01 Part 1, 10.9 and 10.10):

$metadata#PurchaseOrderSet(Items())
$metadata#People(FirstName,Friends(Friends(UserName)))

Grouping by a complex path is a 501 that says so

$apply doesn't follow a path into a complex value, but it said the complex property wasn't a navigation:

GET /odata/v4/TripPin/Airports?$apply=groupby((Location/City/Region))

{"error":{"code":"BadRequest","message":"$apply: Location in Location/City/Region is not a navigation of Airport"}}

It's now a 501, like the other parts of $apply the server doesn't do:

{"error":{"code":"NotImplemented","message":"$apply: Location/City/Region goes into the complex property Location, which is not supported"}}

$filter and $orderby do follow it: $filter=Location/City/Region eq 'Zurich'.

Docs

  • Supported OData features no longer says that $filter and $orderby can't go into a complex value. They can, since v0.24.0.
  • Its list of what's a 501 is one list again.

Upgrading

  • Generated rows change in every model, data files aside. Names, emails and a plain Name change as above, and other values in the same rows move too, as the generator draws its numbers in a different order. A test that expects a generated value needs the new one.
  • A V4 entity whose $select leaves out any of its key properties now has @odata.id. A test that compares such an entity whole needs it, or the key in its $select.
  • A V4 context URL with an $expand now has a select-list: PurchaseOrderSet(Items()), not PurchaseOrderSet.
  • V4's $select=Addr/City is a 200, not a 400.
  • $apply grouping or aggregating by a path into a complex value is a 501, not a 400.

Install

npx odata-prova@0.25.0 ./MySrv
docker run -p 3000:3000 -v "$PWD/MySrv:/models/MySrv:ro" ghcr.io/jaravan/odata-prova:0.25.0

Details

Query options and Aggregation in Supported OData features, Not supported, and Mock data.