-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Summary
Currently, the $extends keyword only accepts a single JSON Pointer to an abstract type (Section 3.10.2):
Value: A JSON Pointer to an abstract type.
This proposal suggests extending $extends to also accept an array of JSON Pointers, enabling multiple inheritance from several abstract base types.
Motivation
When converting from other schema languages (e.g., CDDL with its unwrap operator ~), it's common to compose types from multiple base groups:
base-header = (
version: uint,
timestamp: uint
)
metadata = (
created: uint,
modified: uint
)
full-record = {
~base-header,
~metadata,
data: bstr
}
Currently, JSON Structure cannot directly represent this pattern. The converter must either:
- Only use the first base type and lose information
- Inline all properties from additional base types (losing the inheritance relationship)
Proposed Change
Allow $extends to accept either:
- A single JSON Pointer (current behavior):
"$extends": "#/definitions/BaseType" - An array of JSON Pointers:
"$extends": ["#/definitions/BaseType1", "#/definitions/BaseType2"]
Example:
{
"type": "object",
"name": "FullRecord",
"$extends": ["#/definitions/BaseHeader", "#/definitions/Metadata"],
"properties": {
"data": { "type": "binary" }
}
}Collision Resolution
When multiple base types define properties with the same name, a resolution rule is needed. Suggested approach:
- First-wins: Properties from earlier types in the array take precedence (simple, predictable)
- Last-wins: Properties from later types override earlier ones (similar to many OOP languages)
- Error: Require explicit redefinition in the extending type to resolve conflicts
Recommendation: First-wins for simplicity and consistency with the existing union type matching rule ("the first matching type").
Compatibility
This is a backward-compatible extension:
- Existing schemas with single
$extendsvalues continue to work unchanged - Only schemas explicitly using array syntax would leverage the new behavior
Related
This issue was identified while implementing CDDL-to-JSON-Structure conversion in avrotize.