Xema.JsonSchema (xema v0.13.6) View Source
Converts a JSON Schema to Xema source.
Link to this section Summary
Functions
This function converts a JSON Schema in Xema schema source. The argument
json_schema
is expected as a decoded JSON Schema.
Link to this section Types
Link to this section Functions
Specs
to_xema(json_schema(), opts()) :: atom() | tuple()
This function converts a JSON Schema in Xema schema source. 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.:atom
creates atoms for unknown atoms when set to:force
. This is just needed for additional JSON Schema keywords.
Examples
iex> Xema.JsonSchema.to_xema(%{"type" => "integer", "minimum" => 5})
{:integer, [minimum: 5]}
iex> schema = %{
...> "type" => "object",
...> "properties" => %{"foo" => %{"type" => "integer"}}
...> }
iex> Xema.JsonSchema.to_xema(schema)
{:map, [properties: %{"foo" => :integer}]}
iex> Xema.JsonSchema.to_xema(%{"type" => "integer", "foo" => "bar"}, atom: :force)
{:integer, [foo: "bar"]}