Skip to content

Commit b12b77e

Browse files
committed
fix: properly include source pointers for generic actions
closes #191
1 parent 7293d08 commit b12b77e

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/ash_json_api/controllers/helpers.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ defmodule AshJsonApi.Controllers.Helpers do
128128
Request.assign(request, :result, result)
129129

130130
{:error, error} ->
131-
Request.add_error(request, error, :read)
131+
Request.add_error(request, error, :action)
132132
end
133133
end)
134134
end

test/acceptance/route_test.exs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,33 @@ defmodule Test.Acceptance.RouteTest do
103103
)
104104
|> Map.get(:resp_body)
105105
end
106+
107+
test "generic actions with missing required arguments should include field name in source pointer" do
108+
response =
109+
Domain
110+
|> post(
111+
"/required_say_hello/fred",
112+
%{
113+
data: %{
114+
from: ""
115+
}
116+
},
117+
status: 400
118+
)
119+
120+
assert %{"errors" => errors} = response.resp_body
121+
assert is_list(errors)
122+
assert length(errors) > 0
123+
124+
# Find the "required" error for the missing "from" argument
125+
required_error = Enum.find(errors, &(&1["code"] == "required"))
126+
assert required_error, "Expected to find a 'required' error"
127+
128+
# The source pointer should include the field name that's missing
129+
source_pointer = get_in(required_error, ["source", "pointer"])
130+
assert source_pointer, "Expected source pointer to be present"
131+
132+
assert String.contains?(source_pointer, "from"),
133+
"Expected source pointer '#{source_pointer}' to contain field name 'from'"
134+
end
106135
end

0 commit comments

Comments
 (0)