ash-project / ash_json_api

The JSON:API extension for the Ash Framework
https://hexdocs.pm/ash_json_api
MIT License
55 stars 41 forks source link

Missing Field Name in Error Response When Setting Up AshJsonApi with Generic Actions #191

Open diogo-felix-martins opened 1 month ago

diogo-felix-martins commented 1 month ago

Describe the bug When I try to setup AshJsonApi with a generic action, if there are required arguments it returns an error but without the field name:

image

To Reproduce With a simple Ash.Resource and a route like this:

defmodule App.Core.Test do
  use Ash.Resource,
    domain: App.Core,
    extensions: [
      AshJsonApi.Resource,
    ]

  json_api do
    type "test"

    routes do
      base("/test")

      route(:get, "/:id/data", :read_data)
    end
  end

  resource do
    require_primary_key? false
  end

  attributes do
    attribute :name, :string, public?: true
  end

  actions do
    action :read_data, :struct do
      argument :id, :uuid, allow_nil?: false
      argument :name, :string, allow_nil?: false

      run fn input, context ->
        input.arguments.name
      end
    end
  end
end

Expected behavior The field seems to be missing because the error structure is like this:

[(ash_json_api 1.3.1) lib/ash_json_api/error/error.ex:279: AshJsonApi.ToJsonApiError.Ash.Error.Changes.Required.to_json_api_error/1]
error #=> %Ash.Error.Changes.Required{
  field: :campaign_id,
  type: :argument,
  resource: Calleebree.Core.Widget,
  splode: Ash.Error,
  bread_crumbs: [],
  vars: [],
  path: [],
  stacktrace: #Splode.Stacktrace<>,
  class: :invalid
}

but the implementation for the error is looking for error.vars and not error.field

image