Skip to main content

Macro (compound)

Macros are named field definitions that can be used multiple times within an API.

{
"application": "Tutorial",
"label": "Verwendung von Macros",
"project": "inSynergie CMS",
"tags": [],
"hideId": true,
"extensions": {
"compounds": {
"string": {
"cms": {
"column": true,
"sortable": true
},
"type": "string",
"empty": false
},
"name": {
"cms": {
"column": true
},
"type": "object",
"strict": true,
"properties": {
"first": {
"cms": {
"label": "Vorname"
},
"type": "compound",
"compound": "string",
"localizable": true,
"optional": true
},
"last": {
"cms": {
"label": "Nachname"
},
"type": "compound",
"compound": "string"
}
}
}
}
},
"fields": {
"name": {
"cms": {
"column": true,
"sortable": true,
"label": "Wer"
},
"empty": false,
"type": "string"
},
"spouse": {
"type": "compound",
"compound": "name",
"optional": true
},
"children": {
"type": "array",
"optional": true,
"items": {
"type": "compound",
"compound": "name"
}
}
}
}

The API has the fields name, spouse and children, the last two of which use the type compound. spouse and children refer to the macro name, which is defined under extensions.compounds. spouse is additionally made optional ("optional": true).

The macro name in turn uses the macro string and makes it localizable in the field first ("localizable": true).

Using macros

Rules​

  • A macro field has "type": "compound" and names the macro in compound. In addition, optional, localizable and cms are allowed. They supplement or override the settings of the macro.
  • Macros can use other macros as long as no cycles arise.
  • Macros apply only within one API, not across APIs.

Macros do not add new possibilities to the description: the named definition is merely inserted at the point of use, in several levels if needed. They do, however, make it easier to describe complex structures, unlike in this deliberately simple example.