Absent collections default to empty, and an update touches only what it sends
An update is partial. What a caller does not send, it does not change, which is what lets an editor save one part of a workflow without holding the whole of it.
The rule
- On create,
nodesandedgesMUST default to an empty array when absent, andmetadataMUST default to empty. - A workflow that declares no
interfacedeclares no ports. - An update is sent with
PUTon theworkflow_updateroute (API-9) and has these member-wise semantics rather than replacing the stored workflow whole. - On update, a key the request omits MUST be left as stored.
- A key the request sends as
nullMUST be cleared: the workflow MUST then read as if that key had been omitted on create. nameis the exception to both, and MUST be present and non-null on update as on create (STORE-2).- An
interfacepresent on update MUST replace the stored interface as a whole, so a side it omits, or sends as an empty array, MUST be stored with no ports. - The
metadatapublished on read MAY differ from themetadataas stored. - An implementation MAY fold envelope fields such as
formatandschemaVersioninto it on read.
What it means
An update is sent with PUT, yet it does not replace the stored workflow whole;
it works member by member. It is partial by default: a key the request does not send is left as
stored, which is what lets a caller save one part of a workflow without
holding the whole of it in hand. A key sent as null is the way to clear
it: the workflow then reads as though the key had never been sent on create.
That is the same reading JSON Merge Patch gives a partial update.
interface is replaced as a whole rather than merged: sending it at all
rewrites both the inputs and the outputs it describes, even if only one of
them is included. A side left out of a present interface is not "left as
stored", because what is stored is being replaced; it is a side the new
interface does not declare, so it has no ports.
The metadata a caller reads back is not necessarily the metadata it
would get by reading the stored document directly: an implementation is
free to fold housekeeping fields such as a format marker or a schema version into
what it publishes on read, without those fields having been part of what was
stored.
Example
Four requests to the same endpoint, each reading a different state of a key.
POST /api/flowdrop/workflows
{"id": "bare_wf", "name": "Bare"}PUT /api/flowdrop/workflows/{workflow_id}
{"name": "Partial renamed", "nodes": [ … ]}PUT /api/flowdrop/workflows/{workflow_id}
{"name": "Clear", "interface": []}PUT /api/flowdrop/workflows/{workflow_id}
{"name": "Reset", "metadata": null}The first leaves nodes and edges as empty arrays and metadata empty — nothing
was sent for them, so there is nothing to default from but empty. The second
leaves the edges and metadata a prior request had set untouched, because
this request never mentions them. The third is the one that reads like the
second but is not: interface was sent, so both its sides are rewritten, and
an empty array on either side clears it rather than leaving it as it was.
The fourth clears metadata: it reads back empty, as on a create that never
sent it.
Why
References
Further reading
- RFC 7396JSON Merge PatchThe same reading of a partial update: an absent member leaves the target alone, and a null member removes it.
Fixtures
Test cases whose outcome this rule decides. A case compares absent, null and empty members exactly; the fixtures README defines each operation. Where a case and the rule disagree, the rule is right.
An update sending an empty list stores the empty list update-workflow
{ "given": { "stored": { "name": "Flow", "nodes": [ { "id": "n1" } ], "edges": [] }, "request": { "name": "Flow", "nodes": [] } }, "expect": { "workflow": { "name": "Flow", "nodes": [], "edges": [] } } }An update keeps what it omits and clears what it sends as null update-workflow
edgessent as null reads as if omitted on create, where it defaults to the empty array.{ "given": { "stored": { "name": "Flow", "nodes": [ { "id": "n1" } ], "edges": [ { "source": "n1", "target": "n1" } ] }, "request": { "name": "Flow", "edges": null } }, "expect": { "workflow": { "name": "Flow", "nodes": [ { "id": "n1" } ], "edges": [] } } }fixtures/presence/store-update-omitted-kept-null-cleared.json