Validation keywords

Validation keywords are used to specify constraints on the content of a particular type and to ensure that it is valid. For example, strings will generally have a minimum and maximum length, as will numbers, and arrays will also have a minimum and maximum number of items. These limits will be specified in the content type and enforced by the user interface in the Content Editing window.

Summary

  • Validation keywords provide a way of constraining content to ensure that it is valid
  • We support most of the keywords defined in the JSON Schema standard with a few exceptions
  • enum is a particularly useful keyword for use in content types so we have included some examples of its use. Examples of other validations can be found on the property types and strings pages.

Property types also provide validation, including the format of string items. Specifying a uri format string constrains the format to a standard uri, while the email format ensures that the string entered is a valid format email address.

We support a subset of the validation keywords defined in the JSON Schema Validation specification and these are listed on this page, together with the unsupported keywords.

Supported validation keywords

Expand the list below to see the supported validation keywords, together with the types they apply to.

Validation keywords for number and integer

multipleOf

maximum

exclusiveMaximum

minimum

exclusiveMinimum

Validation keywords for strings

maxLength

minLength

pattern

Validation keywords for arrays

items

maxItems

minItems

required

uniqueItems

Validation keywords for any instance type

enum

Validation keywords for combining schemas

Each of these keywords must be set to an array, where each item is a schema.

allOf: Must be valid against all of the subschemas

anyOf: Must be valid against any of the subschemas

Examples of the use of allOf can be found in the tutorial banner and carousel content types.

Unsupported validation keywords

The following validation keywords are currently not supported. The platform will not reject these keywords where they are included in content types, but developers should not expect these keywords to be interpreted by the user interface when users are adding content.

Expand the section below to see the list of unsupported validation keywords.

additionalItems

maxProperties

minProperties

patternProperties

dependencies

oneOf

Example: enums

enum is a very useful keyword, both for constraining the contents of an array and for providing a list of items for the user to choose from. In the partial snippet shown below, the slides property is an array of content types, constrained by the enum. We could just add another content type to the enum to allow it to be added.

"properties": { "slides": { "type": "array", "items": { "allOf": [ { "$ref": "http://bigcontent.io/cms/schema/v1/core#/definitions/content-link" }, { "properties": { "contentType": { "title": "Carousel Slides", "enum": [ "https://s3-eu-west-1.amazonaws.com/amp-product/tutorials/dynamiccontenttutorials/carouselslide.json" ] } } } ] ...........


The example below shows how to use an enum to define a list of items from which the user can choose. In this example it's just to choose left or right alignment of some text:

"properties": { "alignment": { "title": "alignment", "description": "alignleftorright", "type": "string", "enum": [ "left", "right" ] } }


This is how the enum will be displayed by the user interface.

enum field in the content editing form
enum field in the content editing form

The user clicks in the field in the Content Editing window and chooses the value they want. Note that none is an option.

Choosing from list of items defined in an enum
Choosing from list of items defined in an enum

results matching ""

    No results matching ""