Skip to content

Commit ce6a9df

Browse files
author
Clemens Vasters
committed
Allow $extends to accept an array of JSON Pointers for multiple inheritance
- Updated $extends value to accept either a single JSON Pointer or an array - Added rule for collision resolution: first-wins (properties from earlier types in the array take precedence) - Added example demonstrating multiple inheritance with BaseHeader and Metadata This enables composition patterns common in other schema languages like CDDL. Fixes #18
1 parent b2db20e commit ce6a9df

File tree

1 file changed

+55
-19
lines changed

1 file changed

+55
-19
lines changed

draft-vasters-json-structure-core.md

Lines changed: 55 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,25 +1670,61 @@ is always `true`).
16701670
value is implicitly `true`).
16711671
- Abstract types MAY extend other abstract types via `$extends`.
16721672

1673-
### The `$extends` Keyword {#extends-keyword}
1674-
1675-
The `$extends` keyword merges all properties from an abstract base type into the
1676-
extending type.
1677-
1678-
If the type using `$extends` is marked as `abstract` and referenced via
1679-
`$addins`, the composite type _replaces_ the base type in the type model of the
1680-
document.
1681-
1682-
- **Value**: A JSON Pointer to an abstract type.
1683-
- **Rules**:
1684-
- The `$extends` keyword MUST only be used in schemas of type `object` and
1685-
`tuple`.
1686-
- The value of `$extends` MUST be a valid JSON Pointer that points to an
1687-
abstract type within the same document.
1688-
- The extending type MUST merge the abstract type’s properties and constraints
1689-
and MUST NOT redefine any inherited property.
1690-
1691-
### The `$offers` Keyword {#offers-keyword}
1673+
### The `$extends` Keyword {#extends-keyword}
1674+
1675+
The `$extends` keyword merges all properties from one or more abstract base
1676+
types into the extending type.
1677+
1678+
If the type using `$extends` is marked as `abstract` and referenced via
1679+
`$addins`, the composite type _replaces_ the base type in the type model of the
1680+
document.
1681+
1682+
- **Value**: A JSON Pointer to an abstract type, or an array of JSON Pointers to
1683+
abstract types.
1684+
- **Rules**:
1685+
- The `$extends` keyword MUST only be used in schemas of type `object` and
1686+
`tuple`.
1687+
- The value of `$extends` MUST be a valid JSON Pointer or an array of valid
1688+
JSON Pointers that point to abstract types within the same document.
1689+
- The extending type MUST merge the abstract type's properties and constraints
1690+
and MUST NOT redefine any inherited property.
1691+
- When multiple base types are specified, properties are merged in array
1692+
order. If multiple base types define a property with the same name, the
1693+
property from the first base type in the array takes precedence.
1694+
1695+
**Example**:
1696+
1697+
~~~ json
1698+
{
1699+
"definitions": {
1700+
"BaseHeader": {
1701+
"type": "object",
1702+
"abstract": true,
1703+
"properties": {
1704+
"version": { "type": "uint32" },
1705+
"timestamp": { "type": "uint64" }
1706+
}
1707+
},
1708+
"Metadata": {
1709+
"type": "object",
1710+
"abstract": true,
1711+
"properties": {
1712+
"created": { "type": "uint64" },
1713+
"modified": { "type": "uint64" }
1714+
}
1715+
},
1716+
"FullRecord": {
1717+
"type": "object",
1718+
"$extends": ["#/definitions/BaseHeader", "#/definitions/Metadata"],
1719+
"properties": {
1720+
"data": { "type": "binary" }
1721+
}
1722+
}
1723+
}
1724+
}
1725+
~~~
1726+
1727+
### The `$offers` Keyword {#offers-keyword}### The `$offers` Keyword {#offers-keyword}
16921728

16931729
The `$offers` keyword is used to advertise add-in types that are available for
16941730
use in a schema document. The `$offers` keyword is a map of add-in names to

0 commit comments

Comments
 (0)