Skip to content

fix: include generic GET action arguments as query parameters in JSON schema #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ash_json_api/json_schema/json_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ defmodule AshJsonApi.JsonSchema do
}
}

if route.type in [:get, :related] do
if route.type in [:get, :related] or (route.type == :route and route.method == :get) do
props
|> add_route_properties(resource, properties)
|> add_read_arguments(route, resource)
Expand Down
17 changes: 17 additions & 0 deletions test/acceptance/generic_action_index_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
]
end

test "generic action index route with missing required argument returns error" do

Check failure on line 126 in test/acceptance/generic_action_index_test.exs

View workflow job for this annotation

GitHub Actions / ash-ci / mix test

test generic action index route with missing required argument returns error (Test.Acceptance.GenericActionIndexTest)
response =
Domain
|> get("/search", status: 400)
Expand All @@ -141,4 +141,21 @@
assert String.contains?(source_pointer, "query"),
"Expected source pointer '#{source_pointer}' to contain field name 'query'"
end

test "generic GET actions include arguments as query parameters in JSON schema" do
schema = AshJsonApi.JsonSchema.generate([Domain])

assert %{
"method" => "GET",
"rel" => "route",
"hrefSchema" => %{
"properties" => properties,
"required" => required
}
} = Enum.find(schema["links"], &(&1["method"] == "GET" and &1["rel"] == "route"))

assert Map.has_key?(properties, "query")
assert Map.has_key?(properties, "category")
assert "query" in required
end
end
Loading