JSV.Ref (jsv v0.10.1)

View Source

Representation of a JSON Schema reference ($ref or $dynamicRef).

Summary

Functions

Encodes the given string as a JSON representation of a JSON pointer, that is with ~ as ~0 and / as ~1.

Creates a new reference from an URL, relative to the given namespace.

Raising version of the parse/2 function.

Like parse/2 but flags the reference as dynamic.

Creates a new pointer reference from a list of path segments.

Creates a new pointer reference from a list of path segments.

Types

ns()

@type ns() :: binary() | :root

t()

@type t() :: %JSV.Ref{arg: term(), dynamic?: term(), kind: term(), ns: term()}

Functions

escape_json_pointer(str)

@spec escape_json_pointer(binary() | iodata()) :: binary()

Encodes the given string as a JSON representation of a JSON pointer, that is with ~ as ~0 and / as ~1.

parse(url, current_ns)

@spec parse(binary(), ns()) :: {:ok, t()} | {:error, term()}

Creates a new reference from an URL, relative to the given namespace.

If the URL is absolute and its namespace is different from the given namespace, returns an absolute URL.

parse!(url, current_ns)

@spec parse!(binary(), ns()) :: t()

Raising version of the parse/2 function.

parse_dynamic(url, current_ns)

@spec parse_dynamic(binary(), ns()) :: {:ok, t()} | {:error, term()}

Like parse/2 but flags the reference as dynamic.

pointer(segments, ns)

@spec pointer([binary() | integer()], ns()) :: {:ok, t()}

Creates a new pointer reference from a list of path segments.

The segments can be strings or integers, representing the path components of a JSON pointer.

Examples

iex> JSV.Ref.pointer(["properties", "name"], :root)
{:ok, %JSV.Ref{ns: :root, kind: :pointer, arg: ["properties", "name"], dynamic?: false}}

iex> JSV.Ref.pointer(["items", 0], :root)
{:ok, %JSV.Ref{ns: :root, kind: :pointer, arg: ["items", 0], dynamic?: false}}

pointer!(segments, ns)

@spec pointer!([binary() | integer()], ns()) :: t()

Creates a new pointer reference from a list of path segments.

Raising version of the pointer/2 function.