5.7.2. 選択に基づいて異なるフィールドを表示する
依存関係 と allOf を 指定した 列挙型 フィールドを使用して、各オプションごとに異なる設定フィールドを表示します。
この例では、データベースの種類を選択すると、そのエンジンに固有のバージョンドロップダウンが表示されます。
properties:
dbType:
title: Database type
type: string
enum:
- PostgreSQL
- MySQL
dependencies:
dbType:
allOf:
- if:
properties:
dbType:
const: PostgreSQL
then:
properties:
version:
type: number
enum: [13, 14, 15]
title: PostgreSQL version
default: 15
- if:
properties:
dbType:
const: MySQL
then:
properties:
version:
type: string
enum: ['5.7', '8.0']
title: MySQL version
default: '8.0'
allOf 配列内の各 if/then ブロックは、1 つの 列挙 値に対応します。PostgreSQL を選択すると PostgreSQL のバージョンリストが表示され、MySQL を選択すると MySQL のバージョンリストが表示されます。