ash_json_api_wrapper/lib/endpoint.ex

56 lines
1.3 KiB
Elixir
Raw Normal View History

2021-10-30 15:40:27 +13:00
defmodule AshJsonApiWrapper.Endpoint do
defstruct [:action, :path, :entity_path, :fields, :fields_in, :write_entity_path, :get_for]
2021-10-30 15:40:27 +13:00
@type t :: %__MODULE__{}
def schema do
[
action: [
type: :atom,
required: true,
doc: "The action this path is for"
],
path: [
type: :string,
default: "/",
doc: "The path of the endpoint relative to the base, or an absolute path"
],
fields_in: [
type: {:in, [:body, :params]},
default: :body,
doc: "Where to place the fields when writing them."
],
write_entity_path: [
type: {:list, :string},
doc:
"The list path at which the entity should be placed in the body when creating/updating."
],
entity_path: [
type: :string,
doc: "A json path at which the entities can be read back from the response"
]
]
end
2021-11-04 11:53:51 +13:00
def get_schema do
Keyword.merge(
schema(),
get_for: [
type: :atom,
doc: """
Signifies that this endpoint is a get endpoint for a given field.
See the docs of `get_endpoint` for more.
"""
]
)
end
2021-10-30 15:40:27 +13:00
def default(path) do
%__MODULE__{
path: path,
fields_in: :body
}
end
end