View Source JSV.ErrorFormatter (jsv v0.3.0)

Error formatting loosely following the guidelines described at https://json-schema.org/blog/posts/fixing-json-schema-output

Errors are grouped by similar instance location (the bit of data that was invalidated) and schema location (the part of the schema that invalidated it).

Summary

Functions

Returns a JSON-able version of the errors contained in the ValidationError.

Returns an output unit with valid: true for the given JSV.Validator. This can be substitued to an Error struct in the nested details of an error. Mostly used to show multiple validated schemas with :oneOf.

Types

annotation()

@type annotation() :: %{
  :valid => boolean(),
  :instanceLocation => binary(),
  :evaluationPath => binary(),
  :schemaLocation => binary(),
  optional(:errors) => [collected_error()],
  optional(:detail) => [annotation()]
}

collected_error()

@type collected_error() :: %{
  :kind => atom(),
  :message => String.t(),
  optional(:detail) => [annotation()]
}

raw_path()

@type raw_path() :: [raw_path()] | binary() | integer() | atom()

Functions

format_data_path(rev_data_path)

@spec format_data_path(raw_path()) :: String.t()

normalize_error(e)

@spec normalize_error(JSV.ValidationError.t()) :: map()

Returns a JSON-able version of the errors contained in the ValidationError.

This is generatlly useful to generate HTTP API responses or message broker responses.

valid_unit(vctx)

@spec valid_unit(JSV.Validator.context()) :: annotation()

Returns an output unit with valid: true for the given JSV.Validator. This can be substitued to an Error struct in the nested details of an error. Mostly used to show multiple validated schemas with :oneOf.