2021-10-30 15:40:27 +13:00
|
|
|
defmodule AshJsonApiWrapper.Field do
|
2023-10-22 15:43:34 +13:00
|
|
|
@moduledoc "Represents a field mapped in the target api."
|
2021-11-05 18:13:33 +13:00
|
|
|
defstruct [:name, :path, :write_path, :filter_handler]
|
2021-10-30 15:40:27 +13:00
|
|
|
|
|
|
|
@type t :: %__MODULE__{}
|
|
|
|
|
|
|
|
def schema do
|
|
|
|
[
|
|
|
|
name: [
|
|
|
|
type: :atom,
|
|
|
|
required: true,
|
|
|
|
doc: "The attribute this field is configuring"
|
|
|
|
],
|
|
|
|
path: [
|
|
|
|
type: :string,
|
|
|
|
doc: "The path of the value for this field, relative to the entity's path"
|
|
|
|
],
|
|
|
|
write_path: [
|
|
|
|
type: {:list, :string},
|
|
|
|
doc: "The list path of the value for this field when writing."
|
2021-11-05 18:13:33 +13:00
|
|
|
],
|
|
|
|
filter_handler: [
|
|
|
|
type: :any,
|
|
|
|
doc: """
|
|
|
|
Specification for how the field is handled when used in filters. This is relatively limited at the moment.
|
|
|
|
|
|
|
|
Supports the following:
|
2023-01-15 19:07:41 +13:00
|
|
|
* `:simple` - Sets the value directly into the query params.
|
|
|
|
* `{:simple, "key" | ["path", "to", "key"]}` - Sets the value directly into the query params using the provided key.
|
2021-11-05 18:13:33 +13:00
|
|
|
* `{:place_in_list, ["path", "to", "list"]}` - Supports `or equals` and `in` filters over the given field, by placing their values in the provided list.
|
2023-09-26 03:16:47 +13:00
|
|
|
* `{:place_in_csv_list, ["path", "to", "list"]}` - Supports `or equals` and `in` filters over the given field, by placing their values in the provided list.
|
2021-11-05 18:13:33 +13:00
|
|
|
"""
|
2021-10-30 15:40:27 +13:00
|
|
|
]
|
|
|
|
]
|
|
|
|
end
|
|
|
|
end
|