JSONCodec.Schema behaviour (json_codec v0.3.1)

Copy Markdown View Source

Behaviour for modules that provide their own JSON Schema.

Every JSONCodec module implements it. Other modules implement it to give codec fields that reference them a schema:

defmodule Money do
  @behaviour JSONCodec.Schema

  @impl true
  def schema, do: %{"type" => "string", "pattern" => "^\\d+\\.\\d{2}$"}
end

Referenced modules that implement neither get an empty schema.

Summary

Callbacks

Returns a JSON Schema-compatible map describing this module's JSON form.

Callbacks

schema()

@callback schema() :: map()

Returns a JSON Schema-compatible map describing this module's JSON form.