Backplane. Schema. Parser
(backplane_schema v1.10.60)
Copy Markdown
The Backplane.Schema.Parser module is responsible for managing the state during schema validation.
It centralizes functions to handle updating data, adding errors, and managing the path within
the data structure being validated.
Struct
The Backplane.Schema.Parser struct has the following fields:
:data- The current state of the data being validated.:errors- A list of errors encountered during validation.:path- The current path within the data structure being validated.
Summary
Functions
Adds an error to the parser state's list of errors.
Increments the ref-resolution depth counter. Used by {:ref, _}
directive resolution to bound recursion on cyclic data.
Creates a new parser for a list element, preserving the root data.
Initializes a new Backplane.Schema.Parser struct with the given data.
Updates the data in the parser state at the given key with the specified value.
Functions
Adds an error to the parser state's list of errors.
Parameters
state- The currentBackplane.Schema.Parserstate.err- The%Backplane.Schema.Error{}struct representing the error to add.
Examples
iex> state = Backplane.Schema.Parser.new(%{name: "Alice"})
iex> error = %Backplane.Schema.Error{path: [:name], message: "is required", content: []}
iex> Backplane.Schema.Parser.add_error(state, error)
%Backplane.Schema.Parser{data: %{name: "Alice"}, errors: [%Backplane.Schema.Error{path: [:name], message: "is required", content: []}], path: []}
Increments the ref-resolution depth counter. Used by {:ref, _}
directive resolution to bound recursion on cyclic data.
Creates a new parser for a list element, preserving the root data.
Parameters
element_data- The data for the current list element.parent_parser- The parent parser containing root data and path information.index- The index of the element in the list.
Examples
iex> parent = Backplane.Schema.Parser.new(%{items: [1, 2, 3]}, root_data: %{items: [1, 2, 3]})
iex> Backplane.Schema.Parser.for_list_element(1, parent, 0)
%Backplane.Schema.Parser{data: 1, current_data: 1, root_data: %{items: [1, 2, 3]}, errors: [], path: [0]}
Initializes a new Backplane.Schema.Parser struct with the given data.
Parameters
data- The initial data to be validated.
Examples
iex> Backplane.Schema.Parser.new(%{name: "Alice"})
%Backplane.Schema.Parser{data: %{name: "Alice"}, errors: [], path: []}
Updates the data in the parser state at the given key with the specified value.
Parameters
state- The currentBackplane.Schema.Parserstate.key- The key to update in the data.val- The value to set at the specified key.
Examples
iex> state = Backplane.Schema.Parser.new(%{name: "Alice"})
iex> Backplane.Schema.Parser.update_data(state, :age, 30)
%Backplane.Schema.Parser{data: %{name: "Alice", age: 30}, errors: [], path: []}