Describe the bug
A read action will not work with JSON API if that action uses an aggregate.
To Reproduce
I have a resource that has this aggregate:
aggregates do
first :last_bid_price, :bids, :price do
sort inserted_at: :desc
end
end
If I add json api for that resource like this:
json_api do
type "property"
routes do
base "/property"
index :read
end
end
If I try to get that resource with curl 'localhost:4000/api/markets/property' I will get this error:
[error] #PID<0.811.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.810.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /api/markets/property
** (exit) an exception was raised:
** (MatchError) no match of right hand side value: {:error, "Must provide field type for first"}
(ash_json_api 0.31.1) lib/ash_json_api/json_schema/json_schema.ex:506: anonymous fn/2 in AshJsonApi.JsonSchema.filter_props/1
...
Which happens in the json_schema.ex:505 file.
This is what the agg variable has at the time the error happens:
Describe the bug A read action will not work with JSON API if that action uses an aggregate.
To Reproduce
I have a resource that has this aggregate:
If I add json api for that resource like this:
If I try to get that resource with
curl 'localhost:4000/api/markets/property'
I will get this error:Which happens in the
json_schema.ex:505
file.This is what the
agg
variable has at the time the error happens:This means that the function is called with:
Aggregate.kind_to_type(:first, nil)
Expected behavior The JSON API should work fine with aggregates
** Runtime