プラグインで配列オブジェクトを設定するには?json_schema の type: objects を使う?

プラグイン内で配列オブジェクトをどのように設定すればよいでしょうか。json_schema を試してみましたが、オブジェクトのプロパティ設定では category のようなセレクターは使用できず、テキスト入力のみ可能です。また、type: objects はプラグイン設定では全く機能しません。

json_schema の設定

  quectel_online_customer_category_customers:
    default: "[]"
    client: true
    json_schema: QuectelOnlineCustomer::SiteSettings::CategoryCustomersJsonSchema

plugins/quectel-online-customer/lib/quectel_online_customer/site_settings/category_customers_json_schema.rb

# frozen_string_literal: true

module QuectelOnlineCustomer
  module SiteSettings
    class CategoryCustomersJsonSchema
      def self.schema
        @schema ||= begin
          {
            type: "array",
            uniqueItems: true,
            default: [],
            items: {
              type: "object",
              title: "カテゴリカスタマー設定",
              additionalProperties: false, # 未定義フィールドの送信を禁止
              required: %w[category customers], # 2 つのフィールドが必須
              properties: {
                category: {
                  type: "category",
                  description: "紐付けるフォーラムカテゴリ",
                  label: "カテゴリ"
                },
                customers: {
                  type: "usernames", # 単一ユーザー名 username の代わりに複数ユーザー選択
                  description: "このカテゴリに割り当てるカスタマーアカウント。複数選択可能",
                  label: "カスタマーユーザー"
                }
              }
            }
          }
        end
      end
    end
  end
end

type:objects はプラグインでも機能するはずです!例えばこちらで実際に使用しています

https://github.com/discourse/discourse/blob/eba9a3b69cf637fccba1a00978f2269b4fccf9d4/plugins/discourse-openid-connect/config/settings.yml#L59-L71

はい、可能です。ただし、type:objects 内では type:category もサポートされていません。私の要件は、カテゴリとグループを選択することです。

ああ、なるほど。オブジェクトの設定は直接 settings.yml に追加されるんですね。以下のようにフォーマットする必要があります:

oauth2_category_example:
    type: objects
    default: []
    area: "oauth2"
    schema:
      name: category_rule
      identifier: name
      properties:
        name:
          type: string
          required: true
          label: ルール名
          description: このルールのラベル
        category:
          type: categories
          required: true
          label: カテゴリ
          description: このルールが適用されるカテゴリ
          validations:
            max: 1
        groups:
          type: groups
          label: グループ
          description: このカテゴリに関連付けられたグループ

これにより、以下のようなカテゴリのドロップダウンが生成されます。

type:category のラジオボタンはサポートされていませんか?

この設定に従って

quectel_online_customer_category_customer_group:
    type: objects
    default: []
    schema:
      name: 「カテゴリカスタマーグループ」
      identifier: name
      properties:
        name:
          type: string
          required: true
          label: 名称
          description: 名称
        category:
          type: categories
          required: true
          label: 「カテゴリ」
          description: 「カテゴリ名は、<a href="/categories" target="_blank">すべてのカテゴリ</a> ページでご確認ください」
        group_name:
          type: groups
          required: true
          label: 「カスタマーグループ名」
          description: 「カスタマーグループ名(英字のみ)。<a href="/admin/groups" target="_blank">カスタマーグループ</a> ページでご確認ください」

以下のエラーが発生しました:

エラーが発生しました:

- レンダリング中:
  {{outlet}} for -top-level
    -top-level
      {{outlet}} for application
        application
          DiscourseRoot
            {{outlet}} for admin
              admin
                {{outlet}} for admin.schema
                  schema
                    SchemaSettingNewEditor
                      SchemaSettingField
                        SchemaSettingTypeCategories
                          CategorySelector

section-link.gjs:149
 レンダリング中に取り返しのつかないエラーが発生したため、再レンダリングを試みましたが失敗しました。エラーの原因を修正した後、アプリケーションを再読み込みしてください。
categories.gjs:13
 未捕捉の (promise 内) TypeError: this.args.value?.map is not a function
    at SchemaSettingTypeCategories.<anonymous> (categories.gjs:13:9)

これは私のバージョンに関係していますか?

Discourse v2026.1.4 — Commits · discourse/discourse · GitHub — Ember v6.6.0

設定に古い構成が保存されていませんか?もし「リセット」ボタンが表示される場合は、それを押してデフォルトに戻してみてください。

リセットボタンが見当たりません。ページはスクリーンショットの通りの状態で、カテゴリの下に何も表示されません。

うーん、何が間違っているのかよくわからないな…オブジェクト型の「カテゴリ」オプションはテスト済みなので、機能することを確認しており、あなたのバージョンでは問題ないはずです。どこかで状態が不良のまま固まっている可能性はありますか?テスト用に、新しい名前の別の設定を試してみてください。それはGitHubやどこかで公開されていますか?確認させてください。

type:categories は問題ありませんが、type:category は使用できません。

ただし、以下の設定は単一の選択の場合にも正しく機能するため、type:category は不要です。

category:
  type: categories
  required: true
  label: "カテゴリ"
  description: "カテゴリ名"
  validations:
	max: 1