Using Jason.encode with Ash Resources

I want to be able to use the public attributes of a resource for @derive {Jason.Encoder, only: [:foo]}.

  1. Is this possible without manually listing the atoms of the attributes? I’ve been able to get a list of the attributes programmatically by using Ash.Resource.Info(__MODULE__) |> &Enum.map(&1, :name) but unable to use that with @derive (I’m guessing due to compilation order.)
  2. Can it be done using a macro to avoid having to add it to every resource I want to use it with?

There is not a reasonable way to use the public attributes like that for the exact reason you guessed. There was a discussion in the forum recently about this topic where I offered some advice. If you don’t want to go the route I proposed there, you would need to write an extension. Extensions can introspect the DSL and then provide code to be evaluated in the module.

I believe this is the discussion @zachdaniel is referring to.