Index
Edit

Schema Types

The schema describes the types of documents editors may author in the content studio. This is the reference documentation. We also have a human-friendly tutorial covering the basics.

Properties

typestring

Required. Name of any valid schema type. This will be the type of the value in the data record.

titlestring

Human readable label for the field.

namestring

Required. The field name. This will be the key in the data record.

hiddenboolean

If set to true, this field will be hidden in the Content Studio.

readOnlyboolean

If set to true, this field will not be editable in the content studio.

descriptionstring

Short description to editors how the field is to be used.

Note: The above properties are those which are common for all data types. For a more thorough description on how to use them, have look at the Object Type.

By default the studio loads the schema from the file schemas/schema.js in your studio project. Sanity expects this file to provide a ready to use compiled schema. This is an example of a minimal schema.js file:

import createSchema from 'part:@sanity/base/schema-creator'
import schemaTypes from 'all:part:@sanity/base/schema-type'

export default createSchema({
  name: 'default',
  types: schemaTypes.concat([
    // Add your own types here
    {
      title: "My Example Document Type",
      name: "exampleDocumentType",
      type: "document",
      fields: [
        {
          title: "Greeting",
          name: "greeting",
          type: "string"
        }
      ]
    }
  ])
})

The studio loads the schema by importing the part named part:@sanity/base/schema. You can relocate the schema according to your needs by changing the part definition in you content studio sanity.json file:

{
  // ... other config ...
  "parts": [
    {
      "name": "part:@sanity/base/schema",
"path": "./schemas/schema.js"
} ] }

A plug-in may also provide types in the schema by providing its uncompiled types as part:@sanity/base/schema-type.

// In deweyClassification.js
{
  title: "Dewey Classification",
  name: "deweyClassification",
  type: "string"
}

// In the sanity.json-file of the plug-in
{
  parts: [
{
"implements": "part:@sanity/base/schema-type",
"path": "./deweyClassification.js"
},
// Implement the part again if you need to provide more types: // { // "implements": "part:@sanity/base/schema-type", // "path": "./anotherType.js" // }, ] }

Previous: ReferenceNext: Document