Jido.Signal.Serialization.Schema (Jido Signal v2.2.2)

View Source

Schema validation for Jido Signals using Zoi.

Provides CloudEvents-compliant schema validation with structured error messages.

Summary

Functions

Returns the Zoi schema for validating Signal structures.

Generates a JSON Schema representation of the Signal schema.

Validates a map against the Signal schema.

Functions

signal_schema()

@spec signal_schema() :: term()

Returns the Zoi schema for validating Signal structures.

The schema enforces CloudEvents required fields and validates common optional fields. CloudEvents extensions (additional fields) are allowed by default.

to_json_schema()

@spec to_json_schema() :: map()

Generates a JSON Schema representation of the Signal schema.

Useful for API documentation and OpenAPI specifications.

Examples

iex> json_schema = Schema.to_json_schema()
iex> json_schema["type"]
:object

validate_signal(map)

@spec validate_signal(map()) :: {:ok, map()} | {:error, map()}

Validates a map against the Signal schema.

Returns {:ok, valid_map} if valid, or {:error, errors} with structured error details.

Examples

iex> Schema.validate_signal(%{"type" => "test", "source" => "/test"})
{:ok, %{"type" => "test", "source" => "/test"}}

iex> Schema.validate_signal(%{"type" => "", "source" => "/test"})
{:error, %{"type" => ["type cannot be empty"]}}