Skip to content

Allow \ to accept an array of JSON Pointers for multiple inheritance #18

@clemensv

Description

@clemensv

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:

  1. Only use the first base type and lose information
  2. 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:

  1. First-wins: Properties from earlier types in the array take precedence (simple, predictable)
  2. Last-wins: Properties from later types override earlier ones (similar to many OOP languages)
  3. 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 $extends values 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions