Alembic v2.1.0 Alembic.Source
The source
of an error.
Summary
Types
t :: %Alembic.Source{parameter: String.t, pointer: Api.json_pointer}
An object containing references to the source of the error, optionally including any of the following members:
pointer
- JSON Pointer (RFC6901) to the associated entity in the request document (e.g."/data"
for a primary data object, or"/data/attributes/title"
for a specific attribute).parameter
- URL query parameter caused the error.
Functions
Descends pointer
to child
of current pointer
iex> Alembic.Source.descend(
...> %Alembic.Source{
...> pointer: "/data"
...> },
...> 1
...> )
%Alembic.Source{
pointer: "/data/1"
}
Specs
from_json(%{String.t => String.t}, Alembic.Error.t) :: Alembic.FromJson.error
Converts JSON object to t
.
Valid Input
A parameter can be the source of an error
iex> Alembic.Source.from_json(
...> %{
...> "parameter" => "q",
...> },
...> %Alembic.Error{
...> source: %Alembic.Source{
...> pointer: "/errors/0/source"
...> }
...> }
...> )
{
:ok,
%Alembic.Source{
parameter: "q"
}
}
A member of a JSON object can be the source of an error, in which case a pointer to the location in the object will be given
iex> Alembic.Source.from_json(
...> %{
...> "pointer" => "/data"
...> },
...> %Alembic.Error{
...> source: %Alembic.Source{
...> pointer: "/errors/0/source"
...> }
...> }
...> )
{
:ok,
%Alembic.Source{
pointer: "/data"
}
}
Invalid Input
It is assumed that only "parameter"
or "pointer"
can be set in a single error source (although that’s not
explicit in the JSON API specification), so setting both is an error
iex> Alembic.Source.from_json(
...> %{
...> "parameter" => "q",
...> "pointer" => "/data"
...> },
...> %Alembic.Error{
...> source: %Alembic.Source{
...> pointer: "/errors/0/source"
...> }
...> }
...> )
{
:error,
%Alembic.Document{
errors: [
%Alembic.Error{
detail: "The following members conflict with each other (only one can be present):\nparameter\npointer",
meta: %{
"children" => [
"parameter",
"pointer"
]
},
source: %Alembic.Source{
pointer: "/errors/0/source"
},
status: "422",
title: "Children conflicting"
}
]
}
}
A parameter MUST be a string
iex> Alembic.Source.from_json(
...> %{
...> "parameter" => true,
...> },
...> %Alembic.Error{
...> source: %Alembic.Source{
...> pointer: "/errors/0/source"
...> }
...> }
...> )
{
:error,
%Alembic.Document{
errors: [
%Alembic.Error{
detail: "`/errors/0/source/parameter` type is not string",
meta: %{
"type" => "string"
},
source: %Alembic.Source{
pointer: "/errors/0/source/parameter"
},
status: "422",
title: "Type is wrong"
}
]
}
}
A pointer MUST be a string
iex> Alembic.Source.from_json(
...> %{
...> "pointer" => ["data"],
...> },
...> %Alembic.Error{
...> source: %Alembic.Source{
...> pointer: "/errors/0/source"
...> }
...> }
...> )
{
:error,
%Alembic.Document{
errors: [
%Alembic.Error{
detail: "`/errors/0/source/pointer` type is not string",
meta: %{
"type" => "string"
},
source: %Alembic.Source{
pointer: "/errors/0/source/pointer"
},
status: "422",
title: "Type is wrong"
}
]
}
}