Skip to content

Commit 228bfcb

Browse files
authored
fix: add leading slash to JSON pointer in schema errors (#199)
Be compliant with the JSON:API spec
1 parent 9414cc8 commit 228bfcb

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

lib/ash_json_api/error/schema_errors.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ defmodule AshJsonApi.Error.SchemaErrors do
1919
defp format_path_name(:parameter, []), do: ""
2020

2121
defp format_path_name(:json_pointer, path) do
22-
Enum.join(path, "/")
22+
"/" <> Enum.join(path, "/")
2323
end
2424

2525
defp error_messages(reason, path, acc \\ [])

test/acceptance/patch_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ defmodule Test.Acceptance.PatchTest do
372372

373373
assert %{"errors" => [error]} = response.resp_body
374374
assert error["code"] == "invalid_body"
375+
assert error["source"] == %{"pointer" => "/data/attributes/hidden"}
375376

376377
assert error["detail"] ==
377378
"Expected only defined properties, got key [\"data\", \"attributes\", \"hidden\"]."

test/acceptance/post_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ defmodule Test.Acceptance.PostTest do
416416
# response is a Plug.
417417
assert %{"errors" => [error]} = response.resp_body
418418
assert error["code"] == "invalid_body"
419+
assert error["source"] == %{"pointer" => "/data/attributes/email"}
419420

420421
assert error["detail"] ==
421422
"Expected only defined properties, got key [\"data\", \"attributes\", \"email\"]."
@@ -486,6 +487,7 @@ defmodule Test.Acceptance.PostTest do
486487
# response is a Plug.
487488
assert %{"errors" => [error]} = response.resp_body
488489
assert error["code"] == "invalid_body"
490+
assert error["source"] == %{"pointer" => "/data/attributes/email"}
489491

490492
assert error["detail"] ==
491493
"Expected only defined properties, got key [\"data\", \"attributes\", \"email\"]."

0 commit comments

Comments
 (0)