@@ -65,6 +65,67 @@ defmodule Test.Acceptance.GenericActionIndexTest do
6565 end
6666 end
6767
68+ defmodule SearchResultImplicitQueryParams do
69+ use Ash.Resource ,
70+ domain: Test.Acceptance.GenericActionIndexTest.Domain ,
71+ extensions: [ AshJsonApi.Resource ]
72+
73+ resource do
74+ require_primary_key? ( false )
75+ end
76+
77+ json_api do
78+ type ( "search_result_implicit" )
79+
80+ routes do
81+ base ( "/search_implicit" )
82+ # Intentionally no query_params: [...]
83+ route ( :get , "/" , :search )
84+ end
85+ end
86+
87+ actions do
88+ action :search , { :array , :struct } do
89+ constraints ( items: [ instance_of: __MODULE__ ] )
90+ argument ( :query , :string , allow_nil?: false )
91+ argument ( :category , :string , allow_nil?: true )
92+
93+ run ( fn input , _ ->
94+ query = input . arguments . query
95+ category = Map . get ( input . arguments , :category )
96+
97+ results =
98+ case category do
99+ nil ->
100+ [
101+ % __MODULE__ { title: "Result 1 for #{ query } " , content: "Content 1" } ,
102+ % __MODULE__ { title: "Result 2 for #{ query } " , content: "Content 2" }
103+ ]
104+
105+ category ->
106+ [
107+ % __MODULE__ {
108+ title: "#{ category } Result 1 for #{ query } " ,
109+ content: "Category content 1"
110+ } ,
111+ % __MODULE__ {
112+ title: "#{ category } Result 2 for #{ query } " ,
113+ content: "Category content 2"
114+ }
115+ ]
116+ end
117+
118+ { :ok , results }
119+ end )
120+ end
121+ end
122+
123+ attributes do
124+ attribute ( :title , :string , public?: true )
125+ attribute ( :content , :string , public?: true )
126+ end
127+ end
128+
68129 defmodule Domain do
69130 use Ash.Domain ,
70131 otp_app: :ash_json_api ,
@@ -78,6 +139,7 @@ defmodule Test.Acceptance.GenericActionIndexTest do
78139
79140 resources do
80141 resource ( SearchResult )
142+ resource ( SearchResultImplicitQueryParams )
81143 end
82144 end
83145
@@ -151,6 +213,23 @@ defmodule Test.Acceptance.GenericActionIndexTest do
151213 "Expected source pointer '#{ source_pointer } ' to be /query"
152214 end
153215
216+ test "generic action index route accepts optional argument without query_params configured" do
217+ response =
218+ Domain
219+ |> get ( "/search_implicit?query=elixir&category=tutorial" , status: 200 )
220+
221+ assert response . resp_body == [
222+ % {
223+ "title" => "tutorial Result 1 for elixir" ,
224+ "content" => "Category content 1"
225+ } ,
226+ % {
227+ "title" => "tutorial Result 2 for elixir" ,
228+ "content" => "Category content 2"
229+ }
230+ ]
231+ end
232+
154233 test "generic GET actions include arguments as query parameters in JSON schema" do
155234 schema = AshJsonApi.JsonSchema . generate ( [ Domain ] )
156235
0 commit comments