I am having some weird dialyzer errors following the examples in the deocumentation:
defmodule ChangeAvatarRequest do
@moduledoc "Schema for requests to change a user's avatar."
require OpenApiSpex
OpenApiSpex.schema(%{
type: :object,
properties: %{
avatar: %Schema{
type: :string,
format: :binary
}
}
})
end
@doc "Upload a new profile image."
@doc request_body:
{"Image Upload Form", "multipart/form-data", __MODULE__.ChangeAvatarRequest,
required: true},
responses: %{
200 => {"Avatar URL", "application/json", %Schema{type: :string}},
422 => OpenApiSpex.JsonErrorResponse.response()
}
def upload_avatar(conn = %{body_params: %ChangeAvatarRequest{} = request}, _params) do
IO.inspect(request, label: "===========> ")
# FIXME Remove the hardcoded uuid.
user_uuid = "dccc5004-24db-4eec-b0f9-ffe9be0fad8c"
# FIXME This construct is brittle if the user_uuid is invalid
{:ok, pid} = UserDCSP.find_or_start(user_uuid)
upload_info = %{
content_type: request.avatar.content_type,
filename: request.avatar.filename,
path: request.avatar.path
}
case UserDCSP.change_avatar(pid, upload_info) do
{:ok, avatar_url} -> render(conn, "ok.json", response: avatar_url)
{:error, e} -> render(conn, "error.json", reason: e)
end
end
Gives
lib/xsiom_vue/controllers/user_controller.ex:114:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{:body_params => %XsiomVue.UserController.ChangeAvatarRequest{_ => _}, _ => _},
<<101, 114, 114, 111, 114, 46, 106, 115, 111, 110>>,
[{:reason, _}, ...]
)
will never return since the success typing is:
(
%Plug.Conn{
...
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
...
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
...
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
...
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map() | binary() | atom()) ::
Plug.Conn.t()
I can make the error go away by not putting it in the match line but then it fails. The code works but dialyzer is very mad.