Introspection helpers for the AshPhoenixGenApi.Domain DSL extension.
Use this module to query the PhoenixGenApi configuration of an Ash domain at runtime or during compilation.
Generated Functions
Using Spark.InfoGenerator automatically generates accessor functions for
all options in the gen_api section:
gen_api_service/1- Returns the service namegen_api_nodes/1- Returns the default nodes configurationgen_api_choose_node_mode/1- Returns the default node selection strategygen_api_timeout/1- Returns the default timeoutgen_api_response_type/1- Returns the default response typegen_api_request_info/1- Returns the default request_info settinggen_api_check_permission/1- Returns the default permission check modegen_api_permission_callback/1- Returns the default permission callback MFAgen_api_version/1- Returns the default version stringgen_api_retry/1- Returns the default retry configurationgen_api_supporter_module/1- Returns the supporter module namegen_api_define_supporter?/1- Returns whether to auto-generate the supporter
Additional Helpers
This module also provides convenience functions:
has_gen_api?/1- Check if a domain has gen_api configuredfun_configs/1- Get aggregated FunConfigs from all resources in the domainresources_with_gen_api/1- Get all resources that have gen_api configuredall_request_types/1- Get all request types across all resourcessupporter_module/1- Get the supporter module name
Usage
# Get the service name for a domain
AshPhoenixGenApi.Domain.Info.gen_api_service(MyApp.Chat)
#=> "chat"
# Get the supporter module name
AshPhoenixGenApi.Domain.Info.supporter_module(MyApp.Chat)
#=> MyApp.Chat.GenApiSupporter
# Get all FunConfigs aggregated from domain resources
AshPhoenixGenApi.Domain.Info.fun_configs(MyApp.Chat)
#=> [%PhoenixGenApi.Structs.FunConfig{...}, ...]
# Get all resources that have gen_api configured
AshPhoenixGenApi.Domain.Info.resources_with_gen_api(MyApp.Chat)
#=> [MyApp.Chat.DirectMessage, MyApp.Chat.GroupMessage]
Summary
Functions
Gets all request_type strings from all resources in the domain.
Gets the effective default check_permission for the domain.
Gets the effective default choose_node_mode for the domain.
Checks whether the supporter module should be auto-generated.
Gets a specific FunConfig by request_type from the domain's aggregated configs.
Gets all FunConfig structs aggregated from all resources in the domain
that have the AshPhoenixGenApi.Resource extension.
Default permission check mode for all resources in this domain.
Default permission check mode for all resources in this domain.
Default node selection strategy for all resources in this domain.
Default node selection strategy for all resources in this domain.
Whether to auto-generate the supporter module. Set to false if you
want to define the supporter module manually.
Default target nodes for all resources in this domain.
Default target nodes for all resources in this domain.
gen_api DSL options
Default permission callback MFA for all resources in this domain. When set,
takes precedence over check_permission.
Default permission callback MFA for all resources in this domain. When set,
takes precedence over check_permission.
Target gateway nodes to push config to.
Target gateway nodes to push config to.
Whether to automatically push config to the configured push_nodes
on application startup.
Whether to automatically push config to the configured push_nodes
on application startup.
Default for whether to pass request info (user_id, device_id, request_id) as the last argument to the MFA function for all resources in this domain.
Default for whether to pass request info (user_id, device_id, request_id) as the last argument to the MFA function for all resources in this domain.
Default response mode for all resources in this domain.
Default response mode for all resources in this domain.
Default result encoding mode for all resources in this domain.
Default result encoding mode for all resources in this domain.
Default retry configuration for all resources in this domain.
Default retry configuration for all resources in this domain.
The service name for this domain's API endpoints. This serves as the default for all resources in the domain.
The service name for this domain's API endpoints. This serves as the default for all resources in the domain.
The name of the module to generate that will serve as the PhoenixGenApi supporter for this domain.
The name of the module to generate that will serve as the PhoenixGenApi supporter for this domain.
Default timeout in milliseconds for all resources in this domain. Individual resources and actions can override this.
Default timeout in milliseconds for all resources in this domain. Individual resources and actions can override this.
Default version string for all resources in this domain. Used for PhoenixGenApi API versioning.
Default version string for all resources in this domain. Used for PhoenixGenApi API versioning.
Checks if a domain has the gen_api extension configured.
Gets the effective default nodes for the domain.
Gets the default permission callback MFA for the domain.
Gets the push_nodes configuration for the domain.
Checks whether push_on_startup is enabled for the domain.
Gets the effective default request_info for the domain.
Gets all resources in the domain that have the AshPhoenixGenApi.Resource
extension configured.
Gets the effective default response_type for the domain.
Gets the default result_encoder for this domain.
Gets the effective default retry for the domain.
Gets the service name for the domain.
Gets a summary of the domain's PhoenixGenApi configuration.
Gets the supporter module name for the domain.
Gets the effective default timeout for the domain.
Gets the version string for the domain.
Functions
Gets all request_type strings from all resources in the domain.
Returns a flat list of all request types across all resources that have gen_api configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.all_request_types(MyApp.Chat)
["send_direct_message", "get_conversation", "send_group_message", ...]
@spec check_permission(module()) :: false | :any_authenticated | {:arg, String.t()} | {:role, [String.t()]}
Gets the effective default check_permission for the domain.
Returns the check_permission configured in the domain's gen_api section,
or the built-in default of false if not configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.check_permission(MyApp.Chat)
false
Gets the effective default choose_node_mode for the domain.
Returns the choose_node_mode configured in the domain's gen_api section,
or the built-in default of :random if not configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.choose_node_mode(MyApp.Chat)
:random
Checks whether the supporter module should be auto-generated.
Returns true if gen_api define_supporter? is true (the default),
false otherwise.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.define_supporter?(MyApp.Chat)
true
@spec fun_config(module(), String.t()) :: PhoenixGenApi.Structs.FunConfig.t() | nil
Gets a specific FunConfig by request_type from the domain's aggregated configs.
Searches across all resources in the domain for a FunConfig with the
given request_type. Returns the first match, or nil if not found.
Parameters
domain- The Ash domain modulerequest_type- The PhoenixGenApi request type string
Examples
iex> AshPhoenixGenApi.Domain.Info.fun_config(MyApp.Chat, "send_direct_message")
%PhoenixGenApi.Structs.FunConfig{request_type: "send_direct_message", ...}
iex> AshPhoenixGenApi.Domain.Info.fun_config(MyApp.Chat, "nonexistent")
nil
@spec fun_configs(module()) :: [PhoenixGenApi.Structs.FunConfig.t()]
Gets all FunConfig structs aggregated from all resources in the domain
that have the AshPhoenixGenApi.Resource extension.
This function collects the generated FunConfigs from each resource's
__ash_phoenix_gen_api_fun_configs__/0 function and concatenates them
into a single list.
Returns an empty list if no resources have gen_api configured or if the FunConfigs haven't been generated yet.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.fun_configs(MyApp.Chat)
[
%PhoenixGenApi.Structs.FunConfig{request_type: "send_direct_message", ...},
%PhoenixGenApi.Structs.FunConfig{request_type: "get_conversation", ...},
...
]
Default permission check mode for all resources in this domain.
false- No permission check (default):any_authenticated- Requires a valid user_id{:arg, "arg_name"}- The specified argument must match user_id{:role, ["admin"]}- User must have one of the listed roles
Default permission check mode for all resources in this domain.
false- No permission check (default):any_authenticated- Requires a valid user_id{:arg, "arg_name"}- The specified argument must match user_id{:role, ["admin"]}- User must have one of the listed roles
Default node selection strategy for all resources in this domain.
:random- Select a random node (default):hash- Hash-based selection using request_type{:hash, key}- Hash-based selection using the specified argument key:round_robin- Round-robin across nodes
Default node selection strategy for all resources in this domain.
:random- Select a random node (default):hash- Hash-based selection using request_type{:hash, key}- Hash-based selection using the specified argument key:round_robin- Round-robin across nodes
Whether to auto-generate the supporter module. Set to false if you
want to define the supporter module manually.
When false, the extension will still collect FunConfigs from resources
but will not generate the supporter module. You can use
AshPhoenixGenApi.Domain.Info.fun_configs/1 to get the aggregated
FunConfigs and build your own supporter module.
Default target nodes for all resources in this domain.
Can be:
- A list of node atoms:
[:"node1@host", :"node2@host"] - An MFA tuple that returns a node list at runtime:
{ClusterHelper, :get_nodes, [:chat]} :local- Execute on the local node (default)
Default target nodes for all resources in this domain.
Can be:
- A list of node atoms:
[:"node1@host", :"node2@host"] - An MFA tuple that returns a node list at runtime:
{ClusterHelper, :get_nodes, [:chat]} :local- Execute on the local node (default)
gen_api DSL options
Returns a map containing the and any configured or default values.
Default permission callback MFA for all resources in this domain. When set,
takes precedence over check_permission.
Accepts {Module, :function, []} or nil. The callback function receives
request_type (string) and args (map) as arguments and returns true
(continue) or false (permission denied).
The callback function signature:
@callback check_permission(request_type :: String.t(), args :: map()) :: boolean()Example callback:
def check_permission(request_type, args) do
case request_type do
"delete_user" -> args["role"] == "admin"
"update_profile" -> args["user_id"] == args["target_user_id"]
_ -> true
end
endWhen both permission_callback and check_permission are set,
permission_callback takes precedence and is stored in the FunConfig's
permission_callback field.
Defaults to nil.
Default permission callback MFA for all resources in this domain. When set,
takes precedence over check_permission.
Accepts {Module, :function, []} or nil. The callback function receives
request_type (string) and args (map) as arguments and returns true
(continue) or false (permission denied).
The callback function signature:
@callback check_permission(request_type :: String.t(), args :: map()) :: boolean()Example callback:
def check_permission(request_type, args) do
case request_type do
"delete_user" -> args["role"] == "admin"
"update_profile" -> args["user_id"] == args["target_user_id"]
_ -> true
end
endWhen both permission_callback and check_permission are set,
permission_callback takes precedence and is stored in the FunConfig's
permission_callback field.
Defaults to nil.
Target gateway nodes to push config to.
Can be:
- A list of node atoms:
[:"gateway1@host", :"gateway2@host"] - An MFA tuple that returns a node list at runtime:
{ClusterHelper, :get_gateway_nodes, []} nil- No push nodes configured (default)
When set, the generated supporter module will include functions to actively push its configuration to the specified gateway nodes.
Target gateway nodes to push config to.
Can be:
- A list of node atoms:
[:"gateway1@host", :"gateway2@host"] - An MFA tuple that returns a node list at runtime:
{ClusterHelper, :get_gateway_nodes, []} nil- No push nodes configured (default)
When set, the generated supporter module will include functions to actively push its configuration to the specified gateway nodes.
Whether to automatically push config to the configured push_nodes
on application startup.
When true, the supporter module's push_on_startup/2 function can
be called during application startup to push the config to gateway nodes.
Note: you still need to hook this into your application's supervision
tree or startup sequence manually.
Whether to automatically push config to the configured push_nodes
on application startup.
When true, the supporter module's push_on_startup/2 function can
be called during application startup to push the config to gateway nodes.
Note: you still need to hook this into your application's supervision
tree or startup sequence manually.
Default for whether to pass request info (user_id, device_id, request_id) as the last argument to the MFA function for all resources in this domain.
Default for whether to pass request info (user_id, device_id, request_id) as the last argument to the MFA function for all resources in this domain.
Default response mode for all resources in this domain.
:sync- Client waits for the result:async- Client receives an ack, then the result later (default):stream- Client receives streamed chunks:none- Fire and forget
Default response mode for all resources in this domain.
:sync- Client waits for the result:async- Client receives an ack, then the result later (default):stream- Client receives streamed chunks:none- Fire and forget
Default result encoding mode for all resources in this domain.
Determines how the result returned from the action MFA call is encoded before being returned to the caller.
:struct— Return the Ash resource struct as-is (default):map— Convert the Ash resource struct to a map containing only public fields (usingAsh.Resource.Info.public_fields/1to filter; falls back toMap.from_struct/1for non-Ash-resource structs){Module, :function, args}— Custom encoder MFA. The function receives the result as its first argument, followed byargs, and must return the encoded result.
Individual resources and actions can override this with their own
result_encoder option.
For :map encoding, Ash resource structs are converted to maps containing
only their public fields (attributes, calculations, aggregates, relationships).
Lists of structs are mapped accordingly. Non-Ash-resource structs fall back
to Map.from_struct/1.
For custom MFA encoders, the function receives the result and must return
the encoded value.
Defaults to :struct.
Default result encoding mode for all resources in this domain.
Determines how the result returned from the action MFA call is encoded before being returned to the caller.
:struct— Return the Ash resource struct as-is (default):map— Convert the Ash resource struct to a map containing only public fields (usingAsh.Resource.Info.public_fields/1to filter; falls back toMap.from_struct/1for non-Ash-resource structs){Module, :function, args}— Custom encoder MFA. The function receives the result as its first argument, followed byargs, and must return the encoded result.
Individual resources and actions can override this with their own
result_encoder option.
For :map encoding, Ash resource structs are converted to maps containing
only their public fields (attributes, calculations, aggregates, relationships).
Lists of structs are mapped accordingly. Non-Ash-resource structs fall back
to Map.from_struct/1.
For custom MFA encoders, the function receives the result and must return
the encoded value.
Defaults to :struct.
Default retry configuration for all resources in this domain.
nil- No retry (default)- A positive number
n- Equivalent to{:all_nodes, n} {:same_node, n}- Retry on the same node(s){:all_nodes, n}- Retry across all available nodes
Default retry configuration for all resources in this domain.
nil- No retry (default)- A positive number
n- Equivalent to{:all_nodes, n} {:same_node, n}- Retry on the same node(s){:all_nodes, n}- Retry across all available nodes
The service name for this domain's API endpoints. This serves as the default for all resources in the domain.
Accepts a string or atom.
Example: "chat", "user_service", :notification
The service name for this domain's API endpoints. This serves as the default for all resources in the domain.
Accepts a string or atom.
Example: "chat", "user_service", :notification
The name of the module to generate that will serve as the PhoenixGenApi supporter for this domain.
This module will be auto-generated with functions:
get_config/1- Returns{:ok, fun_configs()}for PhoenixGenApi pullget_config_version/1- Returns{:ok, version}for version checkingfun_configs/0- Returns the aggregated list of FunConfig structslist_request_types/0- Returns all available request type stringsget_fun_config/1- Returns a specific FunConfig by request_type
Example: MyApp.Chat.GenApiSupporter
The name of the module to generate that will serve as the PhoenixGenApi supporter for this domain.
This module will be auto-generated with functions:
get_config/1- Returns{:ok, fun_configs()}for PhoenixGenApi pullget_config_version/1- Returns{:ok, version}for version checkingfun_configs/0- Returns the aggregated list of FunConfig structslist_request_types/0- Returns all available request type stringsget_fun_config/1- Returns a specific FunConfig by request_type
Example: MyApp.Chat.GenApiSupporter
Default timeout in milliseconds for all resources in this domain. Individual resources and actions can override this.
Accepts a positive integer or :infinity.
Default timeout in milliseconds for all resources in this domain. Individual resources and actions can override this.
Accepts a positive integer or :infinity.
Default version string for all resources in this domain. Used for PhoenixGenApi API versioning.
Default version string for all resources in this domain. Used for PhoenixGenApi API versioning.
Checks if a domain has the gen_api extension configured.
Returns true if the domain uses the AshPhoenixGenApi.Domain extension
and has a gen_api section configured, false otherwise.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.has_gen_api?(MyApp.Chat)
true
iex> AshPhoenixGenApi.Domain.Info.has_gen_api?(MyApp.SomeOtherDomain)
false
Gets the effective default nodes for the domain.
Returns the nodes configured in the domain's gen_api section,
or the built-in default of :local if not configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.nodes(MyApp.Chat)
{ClusterHelper, :get_nodes, [:chat]}
Gets the default permission callback MFA for the domain.
Returns the permission_callback configured in the domain's gen_api section,
or nil if not configured.
When set, permission_callback takes precedence over check_permission and
is stored in the FunConfig's permission_callback field.
The callback function receives a map with request context (same params as FunConfig)
and returns true (continue) or false (permission denied).
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.permission_callback(MyApp.Chat)
nil
iex> AshPhoenixGenApi.Domain.Info.permission_callback(MyApp.Chat)
{MyApp.Permissions, :check, []}
Gets the push_nodes configuration for the domain.
Returns the push_nodes configured in the domain's gen_api section,
or nil if not configured.
Can be:
- A list of node atoms:
[:"gateway1@host", :"gateway2@host"] - An MFA tuple that returns a node list at runtime:
{ClusterHelper, :get_gateway_nodes, []} nil- No push nodes configured (default)
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.push_nodes(MyApp.Chat)
[:"gateway1@host", :"gateway2@host"]
iex> AshPhoenixGenApi.Domain.Info.push_nodes(MyApp.Chat)
{ClusterHelper, :get_gateway_nodes, []}
Checks whether push_on_startup is enabled for the domain.
Returns true if gen_api push_on_startup is true,
false otherwise (the default).
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.push_on_startup?(MyApp.Chat)
false
Gets the effective default request_info for the domain.
Returns the request_info configured in the domain's gen_api section,
or the built-in default of true if not configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.request_info(MyApp.Chat)
true
Gets all resources in the domain that have the AshPhoenixGenApi.Resource
extension configured.
Returns a list of resource modules that have gen_api configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.resources_with_gen_api(MyApp.Chat)
[MyApp.Chat.DirectMessage, MyApp.Chat.GroupMessage]
@spec response_type(module()) :: :sync | :async | :stream | :none
Gets the effective default response_type for the domain.
Returns the response_type configured in the domain's gen_api section,
or the built-in default of :async if not configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.response_type(MyApp.Chat)
:async
Gets the default result_encoder for this domain.
The result_encoder determines how the result returned from the action
MFA call is encoded before being returned to the caller:
:struct— Return the Ash resource struct as-is (default):map— Convert the Ash resource struct to a map containing only public fields (usingAsh.Resource.Info.public_fields/1to filter; falls back toMap.from_struct/1for non-Ash-resource structs){Module, :function, args}— Custom encoder MFA
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.result_encoder(MyApp.Chat)
:struct
iex> AshPhoenixGenApi.Domain.Info.result_encoder(MyApp.Chat)
:map
@spec retry(module()) :: nil | pos_integer() | {:same_node, pos_integer()} | {:all_nodes, pos_integer()}
Gets the effective default retry for the domain.
Returns the retry configured in the domain's gen_api section,
or nil if not configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.retry(MyApp.Chat)
nil
Gets the service name for the domain.
Returns the service name configured in the domain's gen_api section,
or nil if not configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.service(MyApp.Chat)
"chat"
Gets a summary of the domain's PhoenixGenApi configuration.
Returns a map with the domain's gen_api settings and a list of resources with their request types.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.summary(MyApp.Chat)
%{
service: "chat",
version: "0.0.1",
supporter_module: MyApp.Chat.GenApiSupporter,
total_fun_configs: 5,
resources: [
%{resource: MyApp.Chat.DirectMessage, request_types: ["send_direct_message", ...]},
%{resource: MyApp.Chat.GroupMessage, request_types: ["send_group_message", ...]}
]
}
Gets the supporter module name for the domain.
Returns the module name configured in gen_api supporter_module, or nil
if the domain doesn't have gen_api configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.supporter_module(MyApp.Chat)
MyApp.Chat.GenApiSupporter
@spec timeout(module()) :: pos_integer() | :infinity
Gets the effective default timeout for the domain.
Returns the timeout configured in the domain's gen_api section,
or the built-in default of 5000 if not configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.timeout(MyApp.Chat)
5000
Gets the version string for the domain.
Returns the version configured in the domain's gen_api section,
or the default "0.0.1" if not configured.
Parameters
domain- The Ash domain module
Examples
iex> AshPhoenixGenApi.Domain.Info.version(MyApp.Chat)
"0.0.1"