View Source JSV.RNS (jsv v0.3.0)

A "namespace" for a schema ID or reference. In the JSV library, a namespace for a schema represents the document the schema belongs to. When it is an URL, it is the scheme, host and path, ignoring the query string and the fragment.

That is basically a URI but with extra support for URNs (urn:isbn:1234 is represented as urn://isbn/1234).

Summary

Functions

Returns a new string namespace by appending a relative child path to a parent namespace. If the child is absolute or :root, returns the child.

Parses the given URL or URN and returns an internal representation of its namespace.

Returns the string value of the namespace, or :root.

Types

t()

@type t() :: %JSV.RNS{uri: :root | URI.t(), urn?: boolean()}

Functions

derive(parent, child)

@spec derive(binary() | :root, binary() | :root) ::
  {:ok, binary() | :roo} | {:error, term()}

Returns a new string namespace by appending a relative child path to a parent namespace. If the child is absolute or :root, returns the child.

parse(uri_or_urn)

@spec parse(binary() | :root) :: t()

Parses the given URL or URN and returns an internal representation of its namespace.

Also accepts :root for root schemas without $id.

to_ns(map)

@spec to_ns(t()) :: binary() | :root

Returns the string value of the namespace, or :root.