新しい type: objects を テーマ設定でサポートされているタイプ に導入します。これは、まもなく非推奨となる予定の既存の json_schema タイプを置き換えるために使用できます。
objects タイプのテーマ設定の定義
objects タイプのテーマ設定を作成するには、まず、設定の名前として使用される、他のテーマ設定と同様にトップレベルのキーを定義します。
links: ...
次に、type、default、schema キーワードを設定に追加します。
links:
type: objects
default: []
schema: ...
type: objects は、これが objects タイプのであることが示され、default: [] 注釈は、設定のデフォルト値を空の配列に設定します。デフォルト値はオブジェクトの配列に設定することもできます。これは、schema が定義され次第デモンストレーションします。
スキーマを定義するには、まずスキーマの名前を次のように定義します。
links:
type: objects
default: []
schema:
name: link
次に、properties キーワードをスキーマに追加します。これにより、各オブジェクトがどのように見えるかを定義および検証できるようになります。
links:
type: objects
default: []
schema:
name: link
properties:
name: ...
上記の例では、link オブジェクトに name プロパティがあることを示しています。期待されるデータのタイプを定義するには、各プロパティで type キーワードを定義する必要があります。
links:
type: objects
default: []
schema:
name: link
properties:
name:
type: string
上記のスキーマ定義は、link オブジェクトに string タイプの name プロパティがあることを示しており、プロパティには文字列値のみが受け入れられることを意味します。現在、次のタイプがサポートされています。
string: プロパティの値は文字列として格納されます。integer: プロパティの値は整数として格納されます。float: プロパティの値は浮動小数点数として格納されます。boolean: プロパティの値はtrueまたはfalseです。enum: プロパティの値はchoicesキーワードで定義された値のいずれかである必要があります。links: type: objects default: [] schema: name: link properties: name: type: enum choices: - name 1 - name 2 - name 3categories: プロパティの値は、有効なカテゴリ ID の配列です。groups: プロパティの値は、有効なグループ ID の配列です。tags: プロパティの値は、有効なタグ名の配列です。
スキーマが定義されたら、設定のデフォルト値を次のように配列を定義して設定できます。
links:
type: objects
default:
- name: link 1
title: link 1 title
- name: link 2
title: link 2 title
schema:
name: link
properties:
name:
type: string
title:
type: string
必須プロパティ
定義されているすべてのプロパティは、デフォルトでオプションです。プロパティを必須としてマークするには、プロパティに required: true を注釈付けするだけです。プロパティに required: false を注釈付けすることで、オプションとしてマークすることもできます。
links:
type: objects
default: []
schema:
name: link
properties:
name:
type: string
required: true
title:
type: string
required: false
カスタム検証
特定のプロパティタイプには、validations キーワードをプロパティに注釈付けすることで宣言できるカスタム検証の組み込みサポートがあります。
links:
type: objects
default: []
schema:
name: link
properties:
name:
type: string
required: true
validations:
min: 1
max: 2048
url: true
string タイプ用の検証
min_length: プロパティの最小長。キーワードの値は整数である必要があります。max_length: プロパティの最大長。キーワードの値は整数である必要があります。url: プロパティが有効な URL であることを検証します。キーワードの値はtrue/falseにできます。
integer および float タイプ用の検証
min: プロパティの最小値。キーワードの値は整数である必要があります。max: プロパティの最大値。キーワードの値は整数である必要があります。
tags、groups、および categories タイプ用の検証
min: プロパティの最小レコード数。キーワードの値は整数である必要があります。max: プロパティの最大レコード数。キーワードの値は整数である必要があります。
ネストされたオブジェクト構造
オブジェクトには、オブジェクトの配列を含むプロパティを含めることもできます。ネストされたオブジェクト構造を作成するには、プロパティに type: objects と関連する schema 定義を注釈付けすることもできます。
sections:
type: objects
default:
- name: section 1
links:
- name: link 1
url: /some/url
- name: link 2
url: /some/other/url
schema:
name: section
properties:
name:
type: string
required: true
links:
type: objects
schema:
name: link
properties:
name:
type: string
url:
type: string
設定の説明とローカライズ
en ロケールで設定の説明を追加するには、次のオブジェクトタイプテーマ設定の形式で locales/en.yml ファイルを作成します。
sections:
type: objects
default:
- name: section 1
links:
- name: link 1
url: /some/url
- name: link 2
url: /some/other/url
schema:
name: section
properties:
name:
type: string
required: true
links:
type: objects
schema:
name: link
properties:
name:
type: string
url:
type: string
en:
theme_metadata:
settings:
sections:
description: This is a description for the sections theme setting
schema:
properties:
name:
label: Name
description: The description for the property
links:
name:
label: Name
description: The description for the property
url:
label: URL
description: The description for the property
This document is version controlled - suggest changes on github.



