View Source JsonSchema.Parser.RootParser (json_schema v0.5.0)

Contains logic for verifying the schema version of a JSON schema file.

Link to this section Summary

Functions

Parses the ID of a JSON schema.

Returns :ok if the given JSON schema has a known supported version, and an error tuple otherwise.

Link to this section Functions

Link to this function

parse_schema(root_node, schema_file_path)

View Source
@spec parse_schema_id(JsonSchema.Types.schemaNode()) ::
  {:ok, URI.t()} | {:error, JsonSchema.Parser.ParserError.t()}

Parses the ID of a JSON schema.

examples

Examples

iex> parse_schema_id(%{"id" => "http://www.example.com/my-schema"})
{:ok, URI.parse("http://www.example.com/my-schema")}

iex> parse_schema_id(%{"$id" => "http://www.example.com/my-schema"})
{:ok, URI.parse("http://www.example.com/my-schema")}

iex> {:error, error} = parse_schema_id(%{"id" => "foo bar baz"})
iex> error.error_type
:invalid_uri

iex> {:error, error} = parse_schema_id(%{})
iex> error.error_type
:missing_property
Link to this function

parse_schema_version(arg1)

View Source
@spec parse_schema_version(JsonSchema.Types.schemaNode()) ::
  {:ok, String.t()} | {:error, JsonSchema.Parser.ParserError.t()}

Returns :ok if the given JSON schema has a known supported version, and an error tuple otherwise.

examples

Examples

iex> schema = %{"$schema" => "http://json-schema.org/draft-07/schema#"}
iex> parse_schema_version(schema)
{:ok, "http://json-schema.org/draft-07/schema#"}

iex> schema = %{"$schema" => "http://example.org/my-own-schema"}
iex> {:error, error} = parse_schema_version(schema)
iex> error.error_type
:unsupported_schema_version

iex> {:error, error} = parse_schema_version(%{})
iex> error.error_type
:missing_property