References

A reference is a special layout that can be used to avoid directly embedding a value by instead embedding only an identifier to the value.

A reference layout can be built using the & character, followed by the type of reference.

&Type

For instance, we define here the Person type where each parent will be referenced in its default layout using the &Person layout.

type Person {
	name: required xs:string,
	parent: multiple &Person
}

Export

A reference layout is exported into any type that can store both an IRI or blank node identifier. In most languages, it will be a string.

For instance, the above layout will be exported into the following JSON Schema:

{
	"type": "object",
	"properties": {
		"name": {
			"type": "string"
		},
		"parent": {
			"type": "array",
			"item": {
				"type": "string"
			}
		}
	},
	"required": [
		"name"
	]
}

When the language permits it, a more precise type will be used. For instance in Rust, the Id type of the treeldr-rust-prelude will be used by default, which is defined as follows:

use iref::IriBuf;
use rdf_types::BlankIdBuf;

pub enum Id {
	Blank(BlankIdBuf),
	Iri(IriBuf)
}

As a consequence, the following Rust type definition is generated for Person:

pub enum Person {
	name: String,
	parent: BTreeSet<Id>
}

Last updated