{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://www.rubyschema.org/rails/cable.json",
  "title": "Rails Action Cable Configuration",
  "markdownDescription": "Configures Action Cable subscription adapters for WebSocket connections in Rails applications. Each top-level key represents an environment (development, test, production, etc.) that specifies how Action Cable handles real-time pub/sub messaging.\n\nSee the [Rails Guide](https://guides.rubyonrails.org/action_cable_overview.html#configuration) for more information.",
  "type": "object",
  "definitions": {
    "environment": {
      "title": "Environment",
      "markdownDescription": "Action Cable environment configuration. Specifies the adapter and connection details for pub/sub messaging.",
      "anyOf": [
        { "$ref": "#/definitions/redis" },
        { "$ref": "#/definitions/async" },
        { "$ref": "#/definitions/test" },
        { "$ref": "#/definitions/postgresql" },
        { "$ref": "#/definitions/solid_cable" },
        {
          "type": "object",
          "properties": {
            "adapter": {
              "type": "string",
              "not": {
                "enum": ["redis", "async", "test", "postgresql", "solid_cable"]
              }
            }
          },
          "additionalProperties": true
        }
      ]
    },
    "redis": {
      "type": "object",
      "markdownDescription": "Redis adapter for Action Cable. Requires a Redis server for pub/sub messaging across multiple server instances. Supports SSL/TLS connections.\n\nAll options other than `adapter` and `channel_prefix` are passed directly to `Redis.new`, so any [redis-rb client option](https://github.com/redis/redis-rb#getting-started) (e.g. `host`, `port`, `db`, `password`, `driver`, `sentinels`) may be used.",
      "properties": {
        "adapter": {
          "const": "redis",
          "markdownDescription": "Adapter type for Redis-backed pub/sub messaging."
        },
        "url": {
          "type": "string",
          "markdownDescription": "Connection URL for the Redis server. Use `redis://` for standard connections or `rediss://` for SSL/TLS connections.\n\nExamples:\n- `redis://localhost:6379`\n- `rediss://10.10.3.153:6380` (SSL/TLS)",
          "examples": ["redis://localhost:6379", "rediss://10.10.3.153:6380"]
        },
        "channel_prefix": {
          "type": "string",
          "markdownDescription": "Optional prefix for channel names to avoid collisions when multiple applications share the same Redis server.\n\nExample: `appname_production` results in channels like `appname_production:chat_room_1`",
          "examples": ["appname_production", "myapp_staging"]
        },
        "id": {
          "type": "string",
          "markdownDescription": "Identifier used as the Redis client name for Action Cable connections.\n\nDefault: `ActionCable-PID-<pid>`"
        },
        "reconnect_attempts": {
          "markdownDescription": "Number of reconnection attempts for the subscription connection, or an array of delays (in seconds) to wait between each attempt. Also passed to the Redis client.\n\nDefault: `1`",
          "oneOf": [
            { "type": "integer", "minimum": 0 },
            { "type": "array", "items": { "type": "number", "minimum": 0 } }
          ],
          "default": 1,
          "examples": [3, [0, 0.25, 0.75]]
        },
        "ssl_params": {
          "markdownDescription": "SSL/TLS parameters for secure Redis connections. Parameters are passed directly to [`OpenSSL::SSL::SSLContext#set_params`](https://docs.ruby-lang.org/en/master/OpenSSL/SSL/SSLContext.html#method-i-set_params).\n\nCommon parameters include `ca_file`, `cert`, `key`, and `verify_mode`. Use `verify_mode: <%= OpenSSL::SSL::VERIFY_NONE %>` to skip certificate verification (not recommended for production).",
          "type": "object",
          "properties": {
            "ciphers": {},
            "ciphersuites": {},
            "ecdh_curves": {},
            "max_version": {},
            "min_version": {},
            "security_level": {},
            "session_cache_mode": {},
            "session_cache_size": {},
            "ssl_version": {},
            "tmp_dh": {}
          },
          "additionalProperties": true
        }
      },
      "required": ["adapter"],
      "additionalProperties": true
    },
    "postgresql": {
      "type": "object",
      "markdownDescription": "PostgreSQL adapter for Action Cable. Uses PostgreSQL's `LISTEN`/`NOTIFY` for pub/sub messaging over the Active Record connection pool, so it requires the application's primary database to be PostgreSQL.\n\nNote that `NOTIFY` payloads are limited to 8000 bytes.",
      "properties": {
        "adapter": {
          "const": "postgresql",
          "markdownDescription": "Adapter type for PostgreSQL `LISTEN`/`NOTIFY` pub/sub messaging."
        },
        "channel_prefix": {
          "type": "string",
          "markdownDescription": "Optional prefix for channel names to avoid collisions when multiple applications share the same database.\n\nExample: `appname_production` results in channels like `appname_production:chat_room_1`",
          "examples": ["appname_production", "myapp_staging"]
        },
        "id": {
          "type": "string",
          "markdownDescription": "Identifier used as the PostgreSQL `application_name` for the Action Cable listener connection.\n\nDefault: `ActionCable-PID-<pid>`"
        }
      },
      "required": ["adapter"],
      "additionalProperties": false
    },
    "async": {
      "type": "object",
      "markdownDescription": "Async adapter for Action Cable. Intended for development and testing only. Runs pub/sub messaging within the same process, so it only works with a single server instance.\n\n**Not suitable for production use.**",
      "properties": {
        "adapter": {
          "const": "async",
          "markdownDescription": "Adapter type for in-process async pub/sub messaging. Development and testing only."
        }
      },
      "additionalProperties": false
    },
    "test": {
      "type": "object",
      "markdownDescription": "Test adapter for Action Cable. Used during automated testing to capture and assert on Action Cable broadcasts without requiring an external service.",
      "properties": {
        "adapter": {
          "const": "test",
          "markdownDescription": "Adapter type for test environment. Captures broadcasts for testing assertions."
        }
      },
      "additionalProperties": false
    },
    "solid_cable": {
      "type": "object",
      "markdownDescription": "Solid Cable adapter for Action Cable. A database-backed solution using Active Record for pub/sub messaging. Supports MySQL, PostgreSQL, and SQLite.\n\nRun `bin/rails solid_cable:install` to set up. See [Solid Cable](https://github.com/rails/solid_cable) for more information.",
      "properties": {
        "adapter": {
          "const": "solid_cable",
          "markdownDescription": "Adapter type for database-backed pub/sub messaging using Solid Cable."
        },
        "channel_prefix": {
          "type": "string",
          "markdownDescription": "Optional prefix for channel names to avoid collisions when multiple applications share the same database.",
          "examples": ["appname_production", "myapp_staging"]
        },
        "connects_to": {
          "type": "object",
          "markdownDescription": "Database connection configuration for Solid Cable. Specifies which database to use for storing messages. Accepts the same options as Active Record's `connects_to`.",
          "examples": [{ "database": { "writing": "cable" } }]
        },
        "polling_interval": {
          "type": "string",
          "markdownDescription": "How frequently to poll the database for new messages. Accepts a duration in `<amount>.<unit>` format (e.g. `0.1.seconds`).\n\nDefault: `0.1.seconds`",
          "default": "0.1.seconds",
          "examples": ["0.1.seconds", "0.5.seconds", "1.second"]
        },
        "message_retention": {
          "type": "string",
          "markdownDescription": "How long to retain messages in the database before they're eligible for deletion. Accepts a duration in `<amount>.<unit>` format (e.g. `1.day`).\n\nDefault: `1.day`",
          "default": "1.day",
          "examples": ["1.day", "12.hours", "7.days"]
        },
        "autotrim": {
          "type": "boolean",
          "markdownDescription": "Automatically trim old messages from the database based on `message_retention` setting.\n\nDefault: `true`",
          "default": true
        },
        "silence_polling": {
          "type": "boolean",
          "markdownDescription": "Suppress logging of database polling queries to reduce log noise.\n\nDefault: `true`",
          "default": true
        },
        "use_skip_locked": {
          "type": "boolean",
          "markdownDescription": "Use `FOR UPDATE SKIP LOCKED` when trimming messages. Set to `false` if your database doesn't support it (MySQL < 8.0, PostgreSQL < 9.5). Has no effect on SQLite.\n\nDefault: `true`",
          "default": true
        },
        "trim_batch_size": {
          "type": "integer",
          "markdownDescription": "Number of old messages to delete in a single batch during autotrim.\n\nDefault: `100`",
          "default": 100,
          "examples": [100, 500, 1000]
        },
        "reconnect_attempts": {
          "markdownDescription": "Number of reconnection attempts when the listener's database connection fails, or an array of delays (in seconds) to wait between each attempt.\n\nDefault: `1`",
          "oneOf": [
            { "type": "integer", "minimum": 0 },
            { "type": "array", "items": { "type": "number", "minimum": 0 } }
          ],
          "default": 1,
          "examples": [3, [0, 0.25, 0.75]]
        },
        "writer_batch_size": {
          "type": "integer",
          "minimum": 1,
          "markdownDescription": "Maximum number of broadcasts written to the database in a single batch insert.\n\nDefault: `4`",
          "default": 4
        },
        "writer_batch_delay": {
          "type": "string",
          "markdownDescription": "How long the broadcaster waits to collect messages into a batch before writing them. Accepts a duration in `<amount>.<unit>` format (e.g. `0.001.seconds`).\n\nDefault: `0.001.seconds`",
          "default": "0.001.seconds",
          "examples": ["0.001.seconds", "0.01.seconds"]
        },
        "encrypt": {
          "type": "boolean",
          "markdownDescription": "Encrypt stored message payloads with [Active Record Encryption](https://guides.rubyonrails.org/active_record_encryption.html#setup). Requires the `msgpack` gem.\n\nDefault: `false`",
          "default": false
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": {
    "$ref": "#/definitions/environment"
  }
}
