Skip to content

Commit 0f070d9

Browse files
authored
fix: include generic GET action arguments as query parameters in JSON schema (#368)
1 parent 71af4bc commit 0f070d9

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/ash_json_api/json_schema/json_schema.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ defmodule AshJsonApi.JsonSchema do
675675
}
676676
}
677677

678-
if route.type in [:get, :related] do
678+
if route.type in [:get, :related] or (route.type == :route and route.method == :get) do
679679
props
680680
|> add_route_properties(resource, properties)
681681
|> add_read_arguments(route, resource)

test/acceptance/generic_action_index_test.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,21 @@ defmodule Test.Acceptance.GenericActionIndexTest do
141141
assert String.contains?(source_pointer, "query"),
142142
"Expected source pointer '#{source_pointer}' to contain field name 'query'"
143143
end
144+
145+
test "generic GET actions include arguments as query parameters in JSON schema" do
146+
schema = AshJsonApi.JsonSchema.generate([Domain])
147+
148+
assert %{
149+
"method" => "GET",
150+
"rel" => "route",
151+
"hrefSchema" => %{
152+
"properties" => properties,
153+
"required" => required
154+
}
155+
} = Enum.find(schema["links"], &(&1["method"] == "GET" and &1["rel"] == "route"))
156+
157+
assert Map.has_key?(properties, "query")
158+
assert Map.has_key?(properties, "category")
159+
assert "query" in required
160+
end
144161
end

0 commit comments

Comments
 (0)