Xema.from_json_schema
You're seeing just the function
from_json_schema
, go back to Xema module for more information.
Specs
Creates a Xema
from a JSON Schema. The argument json_schema
is expected
as a decoded JSON Schema.
All keys that are not standard JSON Schema keywords have to be known atoms. If
the schema has additional keys that are unknown atoms the option
atom: :force
is needed. In this case the atoms will be created. This is not
needed for keys expected by JSON Schema (e.g. in properties)
Options:
:draft
specifies the draft to check the given JSON Schema. Possible values are"draft4"
,"draft6"
, and"draft7"
, default is"draft7"
. If:draft
not set and the schema contains$schema
then the value for$schema
is used for this option.:atoms
creates atoms for unknown atoms when set to:force
. This is just needed for additional JSON Schema keywords.
Examples
iex> Xema.from_json_schema(%{"type" => "integer", "minimum" => 5})
%Xema{schema: %Xema.Schema{minimum: 5, type: :integer}}
iex> schema = %{
...> "type" => "object",
...> "properties" => %{"foo" => %{"type" => "integer"}}
...> }
iex> Xema.from_json_schema(schema)
%Xema{schema:
%Xema.Schema{
properties: %{"foo" => %Xema.Schema{type: :integer}},
type: :map
}
}
iex> Xema.from_json_schema(%{"type" => "integer", "foo" => "bar"}, atom: :force)
%Xema{schema: %Xema.Schema{data: %{foo: "bar"}, type: :integer}}
iex> Xema.from_json_schema(%{"exclusiveMaximum" => 5}, draft: "draft7")
%Xema{schema: %Xema.Schema{exclusive_maximum: 5}}
iex> Xema.from_json_schema(%{"exclusiveMaximum" => 5}, draft: "draft4")
** (Xema.SchemaError) Can't build schema:
Dependencies for "exclusiveMaximum" failed. Missing required key "maximum".