jddf v0.1.1 JDDF.Schema View Source
Represents a JSON Data Definition Format schema.
You can construct instances of this type yourself, or you can parse it from
JSON-like data using from_json/1
or from_json!/1
.
Not all invariants that JDDF schemas must adhere to are checked by
from_json/1
or from_json!/1
. To fully verify the correctness of a schema,
use verify/1
or verify!/1
.
Link to this section Summary
Functions
Construct a JDDF schema from parsed JSON data.
Construct a JDDF schema from parsed JSON data.
Ensure that the invariants of a JDDF schema are adhered to.
Ensure that the invariants of a JDDF schema are adhered to.
Link to this section Types
type()
View Sourcetype() :: :boolean | :float32 | :float64 | :int8 | :uint8 | :int16 | :uint16 | :int32 | :uint32 | :string | :timestamp
Link to this section Functions
from_json(json)
View Sourcefrom_json(json :: String.t()) :: {:ok, Schema.t()} | {:error, JDDF.Schema.InvalidSchemaError.t()}
Construct a JDDF schema from parsed JSON data.
json
should be an Elixir representation of JSON data. You should first parse
the JSON before passing it into from_json/1
. You can construct this data
manually, or parse it using:
Most JSON implementations for Elixir are compatible with this function.
iex> JDDF.Schema.from_json(%{"type" => "uint32"})
{:ok, %JDDF.Schema{definitions: nil, form: {:type, :uint32}}}
iex> JDDF.Schema.from_json(%{"type" => "nonsense"})
{:error, %JDDF.Schema.InvalidSchemaError{message: "invalid type"}}
Construct a JDDF schema from parsed JSON data.
Similar to from_json/1
, except it will unwrap the result and will raise in
case of errors.
iex> JDDF.Schema.from_json!(%{"type" => "uint32"})
%JDDF.Schema{definitions: nil, form: {:type, :uint32}}
iex> JDDF.Schema.from_json!(%{"type" => "nonsense"})
** (JDDF.Schema.InvalidSchemaError) invalid type
verify(schema)
View Sourceverify(schema :: JDDF.Schema.t()) :: {:ok, nil} | {:error, JDDF.Schema.InvalidSchemaError.t()}
Ensure that the invariants of a JDDF schema are adhered to.
iex> JDDF.Schema.verify(JDDF.Schema.from_json!(%{}))
{:ok, nil}
iex> schema = JDDF.Schema.from_json!(%{
...> "properties" => %{ "a" => %{}},
...> "optionalProperties" => %{ "a" => %{}},
...> })
iex> JDDF.Schema.verify(schema)
{:error, %JDDF.Schema.InvalidSchemaError{message: "properties and optionalProperties share key"}}
Ensure that the invariants of a JDDF schema are adhered to.
Similar to verify/1
, except it will unwrap the result and will raise in case
of errors.
iex> JDDF.Schema.verify!(JDDF.Schema.from_json!(%{}))
nil
iex> schema = JDDF.Schema.from_json!(%{
...> "properties" => %{ "a" => %{}},
...> "optionalProperties" => %{ "a" => %{}},
...> })
iex> JDDF.Schema.verify!(schema)
** (JDDF.Schema.InvalidSchemaError) properties and optionalProperties share key