You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/dsls/DSL-AshJsonApi.Domain.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,6 +61,7 @@ end
61
61
|[`authorize?`](#json_api-authorize?){: #json_api-authorize? } |`boolean`|`true`| Whether or not to perform authorization on requests. |
62
62
|[`log_errors?`](#json_api-log_errors?){: #json_api-log_errors? } |`boolean`|`true`| Whether or not to log any errors produced |
63
63
|[`include_nil_values?`](#json_api-include_nil_values?){: #json_api-include_nil_values? } |`boolean`|`true`| Whether or not to include properties for values that are nil in the JSON output |
64
+
|[`error_handler`](#json_api-error_handler){: #json_api-error_handler } |`mfa`|| Set an MFA to intercept/handle any errors that are generated. The function will be called with a `AshJsonApi.Error` struct and a context map, and should return a modified `AshJsonApi.Error` struct. The context map contains `:domain` and `:resource`. For example: ```elixir defmodule MyApp.ErrorHandler do def handle_error(error, _context) do %{error \| detail: "Something went wrong"} end end ``` And in your domain: ```elixir json_api do error_handler {MyApp.ErrorHandler, :handle_error, []} end ```|
Copy file name to clipboardExpand all lines: documentation/dsls/DSL-AshJsonApi.Resource.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,6 +69,8 @@ end
69
69
|[`default_fields`](#json_api-default_fields){: #json_api-default_fields } |`list(atom)`|| The fields to include in the object if the `fields` query parameter does not specify. Defaults to all public |
70
70
|[`derive_sort?`](#json_api-derive_sort?){: #json_api-derive_sort? } |`boolean`|`true`| Whether or not to derive a sort parameter based on the sortable fields of the resource |
71
71
|[`derive_filter?`](#json_api-derive_filter?){: #json_api-derive_filter? } |`boolean`|`true`| Whether or not to derive a filter parameter based on the sortable fields of the resource |
72
+
|[`attribute_names`](#json_api-attribute_names){: #json_api-attribute_names } |`keyword \| (any -> any)`|| Renames attributes (and calculations/aggregates) in the JSON:API output and input. Can be a keyword list of `[ash_name: :json_api_name]` mappings, or a 1-arity function that receives an atom field name and returns the desired JSON:API name (atom or string). The function form is useful for applying a blanket transformation such as camelCase: ```elixir attribute_names fn name -> name \|> to_string() \|> Macro.camelize() \|> String.downcase_first() end ``` Or with a keyword list: ```elixir attribute_names [ first_name: :firstName, last_name: :lastName ] ``` Names are applied consistently across serialization, request parsing, sort/filter parameters, field selection, error source pointers, and schema generation. |
73
+
|[`argument_names`](#json_api-argument_names){: #json_api-argument_names } |`keyword \| (any, any -> any)`|| Renames action arguments in the JSON:API request body and schema. Can be a nested keyword list of `[action_name: [ash_name: :json_api_name]]` mappings, or a 2-arity function that receives `(action_name, argument_name)` atoms and returns the desired JSON:API name (atom or string). ```elixir argument_names [ create: [my_arg: :myArg], update: [my_arg: :myArg] ] ``` Or with a function: ```elixir argument_names fn _action, name -> name \|> to_string() \|> Macro.camelize() \|> String.downcase_first() end ```|
By default, AshJsonApi uses the Ash resource's attribute, relationship, calculation, and aggregate names directly as JSON:API field names. This means a `:first_name` attribute appears as `"first_name"` in requests and responses. The `field_names` and `argument_names` DSL options let you change this — for example, to expose a camelCase API while keeping snake_case internals.
10
+
11
+
These options affect **every** place a field or argument name appears: serialization output, request body parsing, sort and filter parameters, sparse fieldsets, error source pointers, relationship keys, JSON Schema, and OpenAPI spec generation.
0 commit comments