Subject: [Asdf] sdfRef and Merge-Patch

From: Carsten Bormann <[email-masked]>
Date: Mon, 22 Nov 2021 18:34:22 +0100

Buried in the current SDF draft, we say [1] about sdfRef:

	• The JSON Merge Patch algorithm [RFC7396] is applied to patch the contents of "original" with the contents of "patch".

I think we need a couple of examples to illustrate what that actually means.

So, for instance, if we look at figure 4:

      "sdfEvent": {
        "overTemperatureEvent": {
          "sdfOutputData": {
            "type": "object",
            "properties": {
              "alarmType": {
                "sdfRef": "cap:#/sdfData/alarmTypes/quantityAlarms",
                "const": "OverTemperatureAlarm"
              },
              "temperature": {
                "sdfRef": "#/sdfObject/temperatureWithAlarm/sdfData/temperatureData"
              }
            }
          }
        }
      }

This means that we could define another event:

      "sdfEvent": {
        "timedOverTemperatureEvent": {
          "sdfRef": "…/sdfEvent/overTemperatureEvent",
          "sdfOutputData": {
            "properties": {
              "when": { "type": "number", "sdfType": "unix-time" }
            }
          }
        }
      }

Which would resolve to (leaving in unrelated sdfRefs):

      "sdfEvent": {
        "timedOverTemperatureEvent": {
          "sdfOutputData": {
            "type": "object",
            "properties": {
              "alarmType": {
                "sdfRef": "cap:#/sdfData/alarmTypes/quantityAlarms",
                "const": "OverTemperatureAlarm"
              },
              "temperature": {
                "sdfRef": "#/sdfObject/temperatureWithAlarm/sdfData/temperatureData"
              },
              "when": { "type": "number", "sdfType": "unix-time" }
            }
          }
        }
      }

We can do this because merge-patch recurses for any JSON objects, so we can add members to an existing JSON object (such as the ones that are the values of the qualities "sdfOutputData" and "properties") that is inside the structure that we sdfRef to (and we also can remove them by setting their value to null).

Is there any desirable kind of derivation that is not covered by this?
(Yes, this approach can be criticized as a mostly syntactic kind of derivation, but I think that the patterns in which we are using this will evolve and can be recognized.)

Grüße, Carsten

[1]: https://www.ietf.org/archive/id/draft-ietf-asdf-sdf-09.html#section-4.4-6.4