Skip to content

Metaclasses #8

@simontaurus

Description

@simontaurus

While it is technically feasible to use e.g. a JSON-SCHEMA meta schema to build JSON-SCHEMAs, this approach does not play well with human actionees since there's limited guidances how the schema could be shaped while the actionee is exposed to many additional keyword options that may lie beyond his understanding.

Instead, classes could be fitted with a JSON data slot, described by a metaclass JSON-SCHEMA, modelling the class as instance of a metaclass. Metaclasses are fitted with a template slot that (pre)populates the JSON-SCHEMA slot of the class from it JSON data slot (candidate template language due to availability in most programming languages: handlebars).
(see also OWL Metamodelling and Punning)

%%{init: {'theme':'neutral'}}%%
flowchart LR
    subgraph MetaClass
        meta_schema["`
            #Slot *schema*
        `"]
        meta_template["`
            #Slot *template*
        `"]
    end
    subgraph Class
        class_schema["`
            #Slot *schema*
        `"]
        class_data["`
            #Slot *data*
        `"]
    end
    subgraph Instance
        instance_data["`
            #Slot *data*
        `"]
    end
    meta_schema --> class_data
    class_data --> meta_template
    meta_template --> class_schema
    class_schema --> instance_data

Loading

Inheritance can still be applied:

%%{init: {'theme':'neutral'}}%%
flowchart LR

    subgraph ParentMetaClass
        meta0_schema["`
            #Slot *schema*
        `"]
        meta0_template["`
            #Slot *template*
        `"]
    end
    
    subgraph MetaClass
        meta_schema["`
            #Slot *schema*
        `"]
        meta_template["`
            #Slot *template*
        `"]
    end
    subgraph ParentClass
        class0_schema["`
            #Slot *schema*
        `"]
        class0_data["`
            #Slot *data*
        `"]
    end
    subgraph Class
        class_schema["`
            #Slot *schema*
        `"]
        class_data["`
            #Slot *data*
        `"]
    end
    subgraph Instance
        instance_data["`
            #Slot *data*
        `"]
    end

    meta0_schema -. allOf .- meta_schema
    class0_schema -. allOf .- class_schema

    meta0_schema --> class0_data
    class0_data --> meta0_template
    meta0_template --> class0_schema

    meta_schema --> class_data
    class_data --> meta_template
    meta_template --> class_schema
    class_schema --> instance_data

Loading

This is especially useful for creating properties objects as instances of a (Object)Property class and autogenerate the corresponding JSON-SCHEMA to include it per $ref in any schema that wants to make use of this property.

SomePropery.data.json

{
  "$schema": "Property",
  "label": "Some property",
  "datatype": "string"
}

Propery.template

{
  "title": {{label}},
  "type": {{datatype}}
}

SomePropery.schema.json

{
  "title": "Some property",
  "type": "string"
}

SomeClass.schema.json

{
  "properties": {
    "some_property": {
      "$ref": "SomePropery.schema.json"
    }
  }
}

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