Default keyword

The properties in this schema example demonstrate how to make use of the default keyword. The default keyword allows you to set the default value of an item and can be used with strings, numbers, booleans and lists, as well as content and image links. The example schema includes each of these property types.

Pre-requisites

None. This is a self contained schema.

How to use

You can use the defaults demonstrated in this schema for your own properties.

To use the example-image-link and example-content-link properties you will need to update these properties to use an image and a content item from your own hub.

In the example-image-link property, the default value includes all the properties returned by an image-link object, including the id, name, endpoint and default host. The easiest way to find all these values is to publish a content item containing the image and view the item in JSON format from a link in the "Content delivery" section of the content form. See content item properties for more details.

For the example-content-link property you can also find the contentType and id fields from the content item properties window and use these values to define a default content-link.

Defaults example

{
   "$schema":"http://json-schema.org/draft-07/schema#",
   "$id":"https://schema-examples.com/default",
   "title":"Default keyword",
   "description":"Examples of using the default keyword",
   "$comment": "Docs: https://amplience.com/docs/development/schema-examples/coreconcepts/default.html",

   "allOf":[
      {
         "$ref":"http://bigcontent.io/cms/schema/v1/core#/definitions/content"
      }
   ],
   "type":"object",
   "properties":{
      "numberValue":{
         "title":"Number value",
         "description":"A number value between 0 and 100 with a default set",
         "type":"number",
         "minimum":0,
         "maximum":100,
         "default":90
      },
      "stringProperty":{
         "title":"A string with a default value",
         "type":"string",
         "minLength":0,
         "maxLength":20,
         "default":"Some example text"
      },
      "rich-text-item":{
         "title":"Rich text",
         "type":"string",
         "format":"markdown",
         "default":"Lorem ipsum dolor sit amet…"
      },
      "example-enum":{
         "type":"string",
         "enum":[
            "chair",
            "sofa",
            "bed",
            "table",
            "lamp"
         ],
         "default":"sofa"
      },
      "string-Array":{
         "title":"String array",
         "description":"An array of strings with default values",
         "type":"array",
         "items":{
            "type":"string"
         },
         "default":[
            "string",
            "string1",
            "string2"
         ]
      },
      "color":{
         "title":"Color",
         "format":"color",
         "type":"string",
         "default":"rgb(255, 102, 102)"
      },
      "example-boolean":{
         "title":"Example boolean",
         "type":"boolean",
         "default":true
      },
      "example-image-link":{
         "allOf":[
            {
               "$ref":"http://bigcontent.io/cms/schema/v1/core#/definitions/image-link"
            }
         ],
         "default":{
            "_meta":{
               "schema":"http://bigcontent.io/cms/schema/v1/core#/definitions/image-link"
            },
            "id":"286e4760-1812-4e3a-81ab-d2e3bf32b9b5",
            "name":"blue-tie",
            "endpoint":"ampproduct",
            "defaultHost":"cdn.media.amplience.net"
         }
      },
      "example-content-link":{
         "allOf":[
            {
               "$ref":"http://bigcontent.io/cms/schema/v1/core#/definitions/content-link"
            },
            {
               "properties":{
                  "contentType":{
                     "enum":[
                        "http://docexample.com/tutorialbanner.json"
                     ]
                  }
               }
            }
         ],
         "default":{
            "_meta":{
               "schema":"http://bigcontent.io/cms/schema/v1/core#/definitions/content-link"
            },
            "contentType":"http://docexample.com/tutorialbanner.json",
            "id":"12058184-97de-42e7-93b5-29b8705a871d"
         }
      }
   },
   "propertyOrder":[

   ]
}

Content form preview

An example of creating a content item using a content type registered from the defaults example schema is shown in the image below.

A content item created from the default keyword content type
A content item created from the default keyword content type

Default keyword

results matching ""

    No results matching ""