Snodo.Schema.Validator behaviour (snodo v0.4.1)

Copy Markdown View Source

Pluggable JSON Schema validation boundary.

Validators receive the untouched schema map registered by the application. Returning {:error, reason} marks an instance invalid; validators must not mutate either the instance or schema.

Snodo.Schema.Validator.Basic is the dependency-free common-subset implementation. Snodo.Schema.Validator.Passthrough remains the runtime default so selecting validation is an explicit application policy.

Validators may implement compile/1 and validate_compiled/2. A server runtime prepares its registered tool schemas once and retains the compiled results for that runtime's lifetime. Build errors are returned at validation time as server errors, as they are for a validator that only implements validate/2. The error reason may be any term and is kept in the server's internal error cause, not sent to the client.

Summary

Callbacks

compile(schema)

(optional)
@callback compile(schema :: map()) :: {:ok, term()} | {:error, term()}

validate(instance, schema)

@callback validate(instance :: term(), schema :: map()) :: :ok | {:error, term()}

validate_compiled(instance, compiled)

(optional)
@callback validate_compiled(instance :: term(), compiled :: term()) ::
  :ok | {:error, term()}