oasis-tcs / odata-specs

OASIS OData TC: Markdown sources for OData specification drafts. https://github.com/oasis-tcs/odata-specs
https://oasis-tcs.github.io/odata-specs/
Other
6 stars 2 forks source link

How to create an entity with self-reference? #2010

Open HeikoTheissen opened 4 weeks ago

HeikoTheissen commented 4 weeks ago

How to create an entity with server-generated entity ID that contains at the same time a self-reference? Can this be done with a JSON batch request?

{"requests": [{
  "id": "1",
  "method": "post",
  "url": "Employees",
  "body": {...}
}, {
  "id": "2",
  "dependsOn": ["1"],
  "method": "put",
  "url": "$1/Manager",
  "body": {
    "@context": "$metadata#$ref",
    "@id": "$1"
  }
}]}

Can the $1 reference appear in the body in this position? The JSON batch specification contains only examples with $1 in url or headers.

ralfhandl commented 3 weeks ago

Not possible yet, would need some templating mechanism for constructing request bodies.

Any template media types out there that we can reuse?

HeikoTheissen commented 3 weeks ago

Introducing a new variant of the OData bind operation may be simpler than introducing a templating mechanism (although the latter could be useful elsewhere). The proposed @bindurl accepts the same values as the request URL, so you can write:

{
  "id": "2",
  "dependsOn": ["1"],
  "method": "patch",
  "url": "$1",
  "body": {
    "Manager@bindurl": "$1"
  }
}

This would not only allow self-references, but also batch requests that create two entities with a reference between them.