Dashboard toolsEvent schema validation

Event schema validation

Define the shape of your events server-side so a typo in a publisher doesn’t silently corrupt your subscribers. When a payload doesn’t match the schema, Mawjly records a warning that shows up immediately in the live debug console — and optionally rejects the publish.

Dashboard → your app → Schemas

Schema shape

A schema is a tiny JSON object — no JSON-Schema knowledge required:

{
  "required": ["user", "amount"],
  "types": {
    "user": "string",
    "amount": "number",
    "metadata": "object"
  }
}
FieldTypeMeaning
requiredstring[]Top-level keys that MUST be present.
typesRecord<string, type>Per-key type constraints. Optional.

Supported types: string, number, integer, boolean, object, array, null.

Channel + event matching

Schemas attach to a (channel_pattern, event_name) pair. Patterns are glob-style:

PatternMatches
ordersexactly the orders channel
chat-*chat-room, chat-1, but NOT chat-room.private
chat-**every channel that starts with chat-, no exceptions
*any single-segment channel (no dots)
**every channel

Modes

Each schema can be warning (default) or blocking:

ModeBad payload behavior
warningEvent is published normally; the warning is recorded on usage_events.schema_warnings and streamed to the debug console.
blockingThe publish is rejected with 422. Only use this once you trust the schema.

Example

Define a schema for orders / new:

curl -X POST 'https://api.mawjly.com/apps/{appId}/schemas' \
  -H 'Content-Type: application/json' -H 'X-CSRF-TOKEN: ...' \
  --data '{
    "channel_pattern": "orders",
    "event_name": "new",
    "schema": {
      "required": ["id", "total", "currency"],
      "types": { "id": "integer", "total": "number", "currency": "string" }
    },
    "blocking": false
  }'

Now publish a bad payload:

pusher.trigger('orders', 'new', { id: 42, total: '199.00' });
//                                          ^^^^^^^^ string instead of number

The event is still delivered (warning mode), but the debug console immediately shows:

⚠ orders.new schema warning
   types.total: expected number, got string

Why this matters

  • Catches publisher bugs that silently break subscribers.
  • Documents your event contract in one place — your team can read the schemas.
  • Foundation for typed client codegen (planned).

API

GET    /api/apps/{app}/schemas
POST   /api/apps/{app}/schemas
DELETE /api/apps/{app}/schemas/{id}

POST is upsert — re-posting the same (channel_pattern, event_name) updates the existing schema.