Skip to main content

Mixins

Mixins allow you to use the same data structures in multiple places. You define a mixin once and reference it using the $ref keyword.

Introduction
Link copied!

You can reference any part of any schema by providing a combination of the schema id and a pointer that indicates the path to the structure. In the example below we are referencing the image structure which is included in the definitions section of https://schema-examples.com/media.

{
"inline_Content": {
"type": "object",
"allOf": [
{
"$ref": "https://schema-examples.com/media#/definitions/image"
}
]
}
}

The content is loaded and displayed inline in the content form.

Partials
Link copied!

Partials are a type of mixin schema that contain just a definitions section. These definitions can be referenced in multiple schemas, particularly useful if you have some complex properties that you want to store and refer to in one place. You can also share definitions within the same schema.

Partials can be created in the schema editor and stored on a hub or stored externally on a hosting service or a source control system such as GitHub. Partials cannot be registered as content types and are included as part of the schema that references them. When you make a change to a partial, you should ensure that each schema that uses it is synced so that the changes are applied.

Example partial
Link copied!

The following shows an example partial that just includes a single definition for a person object. The object contains name, address and city properties.

{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://example.com/simpledefinitions.json",

"definitions": {
"person": {
"title": "person",
"description": "Use this to enter a person's details",
"type": "object",
"properties": {
"name": {
"title": "name",
"description": "Person's name",
"type": "string",
"minLength": 0,
"maxLength": 255
},
"addressline1": {
"title": "addressline1",
"description": "Address Line 1",
"type": "string",
"minLength": 0,
"maxLength": 300
},
"addressline2": {
"title": "addressline2",
"description": "Address Line 2",
"type": "string",
"minLength": 0,
"maxLength": 300
},
"city": {
"title": "City",
"description": "City",
"type": "string",
"minLength": 0,
"maxLength": 100
}
},
"propertyOrder": []
}
}
}

Including a property defined in a partial
Link copied!

To include the person object in another schema use the following syntax:

"person":{
"allOf": [
{ "$ref": "http://example.com/simpledefinitions.json#/definitions/person" }
]
}

A partial can contain multiple definition and you just reference each property by name.

To refer to a property defined in the definitions section of the same schema, you can use the following syntax. The difference from the previous example is just that you don't need to include the full URL because the definition is in the same file.

"person":{
"allOf": [
{ "$ref": "#/definitions/person" }
]
}

See the partials example for a more detailed partial.