A2UICore.Validation.Payload (A2UICore v0.1.1)

Copy Markdown View Source

Validates component, function-call and theme payloads against a catalog.

All three return :ok / {:ok, value} or {:error, %A2UICore.Error{category: :validation}} whose details list every violation as %{code, path, message}. Codes follow the reference: missing_field, extra_field, type_mismatch, invalid_value, unrecognized_component, unrecognized_function, too_many_arguments, invalid_identifier, invalid_reference, invalid_function_call. Paths are components.<id>.<property path> and functions.<name>.<argument path>; the error message joins path: message lines.

A component property that fails its schema is reported as missing_field (required), extra_field (surplus) or invalid_value (anything else — wrong type, value outside an enum, pattern…), which is what the shared conformance suites expect. An unknown component type carries an invalid_value detail at its component property next to unrecognized_component.

With allow_unknown_elements (the relaxed configuration) unknown component types, unknown functions and unknown properties are tolerated.

A component is validated against its resolved schema (A2UICore.Catalog.resolved_component_schema/2) with the validation schema's $defs. The function calls nested in it are checked on their own: a call that runs in this catalog (it names it, or names no catalogId in a component that names none either) is fully checked; a call into another catalog only for well-formed identifiers, since the processor checks it against the catalog it resolves to. From v1.0 a call to a system function (@index) belongs to no catalog. Errors of a nested call are reported at the call's location (components.<id>.<property>.args.<argument>).

Summary

Functions

The most arguments one function call may carry.

Moves the details of a function call's error from functions.<name>… to the call's location in a component (location, such as components.t1.text): functions.<name> becomes location and functions.<name>.<argument>… becomes location.args.<argument>…. An error without details gets one with code. Returns [] for a successful result.

Validates one component payload against catalog.

Validates the arguments of a call to name against the catalog's declaration, returning them with schema defaults filled in.

Validates a call to a system function (@index from v1.0) of version, which belongs to no catalog.

Validates a theme object against the catalog's theme schema. A catalog without one accepts any object.

Functions

max_function_call_args()

(since 0.1.0)
@spec max_function_call_args() :: pos_integer()

The most arguments one function call may carry.

rebase(result, name, location, code \\ "invalid_function_call")

(since 0.1.0)
@spec rebase(
  :ok | {:ok, term()} | {:error, A2UICore.Error.t()},
  String.t(),
  String.t(),
  String.t()
) ::
  [A2UICore.Error.Detail.t()]

Moves the details of a function call's error from functions.<name>… to the call's location in a component (location, such as components.t1.text): functions.<name> becomes location and functions.<name>.<argument>… becomes location.args.<argument>…. An error without details gets one with code. Returns [] for a successful result.

validate_component(catalog, component, config \\ Config.strict())

(since 0.1.0)
@spec validate_component(A2UICore.Catalog.t(), term(), A2UICore.Validation.Config.t()) ::
  :ok | {:error, A2UICore.Error.t()}

Validates one component payload against catalog.

validate_function(catalog, name, args, config \\ Config.strict())

(since 0.1.0)
@spec validate_function(
  A2UICore.Catalog.t(),
  String.t(),
  term(),
  A2UICore.Validation.Config.t()
) ::
  {:ok, map()} | {:error, A2UICore.Error.t()}

Validates the arguments of a call to name against the catalog's declaration, returning them with schema defaults filled in.

validate_system_function(name, args, version, config \\ Config.strict())

(since 0.1.0)
@spec validate_system_function(
  String.t(),
  term(),
  String.t(),
  A2UICore.Validation.Config.t()
) ::
  {:ok, map()} | {:error, A2UICore.Error.t()}

Validates a call to a system function (@index from v1.0) of version, which belongs to no catalog.

validate_theme(catalog, theme)

(since 0.1.0)
@spec validate_theme(A2UICore.Catalog.t(), term()) ::
  :ok | {:error, A2UICore.Error.t()}

Validates a theme object against the catalog's theme schema. A catalog without one accepts any object.