JSV.Resolver.Httpc (jsv v0.10.0)

View Source

A JSV.Resolver implementation that will fetch the schemas from the web with the help of the :httpc module.

This resolver requires a list of allowed URL prefixes to download from. It also needs a proper JSON library to decode fetched schemas:

  • From Elixir 1.18, the JSON module is automatically available in the standard library.
  • JSV can use Jason if listed in your dependencies with the "~> 1.0" requirement.
  • JSV also supports Poison with the "~> 6.0 or ~> 5.0" requirement.

Schemas known by the JSV.Resolver.Embedded will be fetched from that module instead of being fetched from the web. Allowed prefixes are not needed for those schemas.

Options

This resolver supports the following options:

  • :allowed_prefixes - This option is mandatory and contains the allowed prefixes to download from. For security reasons, the prefixes should contain at leath the first / of the URI path, like https://example.com/ instead of https://example.com.
  • :cache_dir - The path of a directory to cache downloaded resources. The default value can be retrieved with default_cache_dir/0 and is based on System.tmp_dir!/0. The option also accepts false to disable that cache. Note that there is no cache expiration mechanism.

Example

resolver_opts = [allowed_prefixes: ["https://my-company.org/schemas"], cache_dir: "_build/custom/dir"]
JSV.build(schema, resolver: {JSV.Resolver.BuiltIn, resolver_opts})

Summary

Functions

Returns the default directory used by the disk-based cache.

Functions

default_cache_dir()

@spec default_cache_dir() :: binary()

Returns the default directory used by the disk-based cache.