Partials example

Partials are schemas 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.

On this page we'll walk you through creating a simple partial using the schema editor.

Creating a partial

To create a partial, choose "Content type schemas" from the "Development" menu and click the "Create schema" button. Give the schema a valid URL and click "Save and open schema" to open the schema editor.

Creating a partial
Creating a partial

The schema editor opens with a definitions section included. Add properties to this section in the same way as you would add properties to content types.

If you click the preview icon and then select the "Definitions" section, a preview of the definitions will be displayed. In this example we are added a simple "person" object with text properties for name and address.

Previewing the definition
Previewing the definition

When you've finished adding the properties you want to add to the definition, click the "Save" button.

Using the partial

The simple definitions schema is shown below.

{
    "$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": []
        }


    }
}

You can refer to the "Person" definition from another schema as follows:

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

Here's how the "person" property is previewed in the content form preview when included in another schema.

Previewing the person property
Previewing the person property

Using definitions in the same schema

You can also use definitions within the same schema. In the example below a definitions section has been added to include the "person" object. You can preview a schema's definitions by clicking the preview icon and choosing "Definitions".

Previewing the person object from this schema's definitions
Previewing the person object from this schema's definitions

To refer to the person object you'd just use:

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

as shown in the image below.

Previewing the content type schema including the person definition
Previewing the content type schema including the person definition

Note that partials are not registered as content types.

results matching ""

    No results matching ""