Xema.JsonSchema (hl7 v1.0.2)
Converts a JSON Schema to Xema source.
Summary
Functions
This function converts a JSON Schema in Xema schema source. The argument
json_schema is expected as a decoded JSON Schema.
Types
Link to this type
json_schema()
@type json_schema() :: true | false | map()
Link to this type
opts()
@type opts() :: [{:draft, String.t()}]
Functions
Link to this function
keywordsDefault(key, value, opts)
Link to this function
to_xema(json_schema, opts \\ [])
@spec 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:
:draftspecifies the draft to check the given JSON Schema. Possible values are"draft4","draft6", and"draft7", default is"draft7". If:draftnot set and the schema contains$schemathen the value for$schemais used for this option.:atomcreates 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, [keys: :strings, properties: %{"foo" => :integer}]}
iex> Xema.JsonSchema.to_xema(%{"type" => "integer", "foo" => "bar"}, atom: :force)
{:integer, [foo: "bar"]}