Currently, I am in the process of formatting the HTTP PATCH document structure. I vaguely remember seeing conditional Typescript properties based on another prop value, but I cannot confirm. There might be a solution involving union types as well...
This is the schema:
[
{ "op": "test", "path": "/a/b/c", "value": "foo" },
{ "op": "remove", "path": "/a/b/c" },
{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] },
{ "op": "replace", "path": "/a/b/c", "value": 42 },
{ "op": "move",, "from"": "/a/b/c", "path": "/a/b/d" },
{ "op": "copy", "from": "/a/b/d", "path": "/a/b/e" }
]
It's worth noting that there is an op
property with possible values being
"test" | "remove" | "add" | "replace" | "move" | "copy"
. The move
and copy
operations include a from<code> property without a <code>value
property like the others (except for remove
) have.
While making from
and value
optional is a simple solution, it sacrifices validation. Therefore, I am exploring if defining types conforming to the schema is feasible, even if not straightforward.