mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
feat: descriptions for actions and relationships (#116)
This commit is contained in:
parent
ca66133777
commit
2efcf12818
10 changed files with 117 additions and 83 deletions
|
@ -1,31 +1,30 @@
|
|||
defmodule Ash.Resource.Actions.Create do
|
||||
@moduledoc "Represents a create action on a resource."
|
||||
defstruct [:name, :primary?, :accept, :changes, type: :create]
|
||||
defstruct [:name, :primary?, :accept, :changes, :description, type: :create]
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
type: :create,
|
||||
name: atom,
|
||||
accept: [atom],
|
||||
primary?: boolean
|
||||
primary?: boolean,
|
||||
description: String.t()
|
||||
}
|
||||
|
||||
@opt_schema [
|
||||
name: [
|
||||
type: :atom,
|
||||
required: true,
|
||||
doc: "The name of the action"
|
||||
],
|
||||
import Ash.Resource.Actions.SharedOptions
|
||||
|
||||
@global_opts shared_options()
|
||||
|
||||
@opt_schema Ash.OptionsHelpers.merge_schemas(
|
||||
[
|
||||
accept: [
|
||||
type: {:custom, Ash.OptionsHelpers, :list_of_atoms, []},
|
||||
doc:
|
||||
"The list of attributes and relationships to accept. Defaults to all attributes on the resource"
|
||||
]
|
||||
],
|
||||
primary?: [
|
||||
type: :boolean,
|
||||
default: false,
|
||||
doc: "Whether or not this action should be used when no action is specified by the caller."
|
||||
]
|
||||
]
|
||||
@global_opts,
|
||||
"Action Options"
|
||||
)
|
||||
|
||||
@doc false
|
||||
def opt_schema, do: @opt_schema
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
defmodule Ash.Resource.Actions.Destroy do
|
||||
@moduledoc "Represents a destroy action on a resource."
|
||||
|
||||
defstruct [:name, :primary?, :changes, :accept, :soft?, type: :destroy]
|
||||
defstruct [:name, :primary?, :changes, :accept, :soft?, :description, type: :destroy]
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
type: :destroy,
|
||||
name: atom,
|
||||
primary?: boolean
|
||||
primary?: boolean,
|
||||
description: String.t()
|
||||
}
|
||||
import Ash.Resource.Actions.SharedOptions
|
||||
|
||||
@opt_schema [
|
||||
name: [
|
||||
type: :atom,
|
||||
doc: "The name of the action"
|
||||
],
|
||||
primary?: [
|
||||
type: :boolean,
|
||||
default: false,
|
||||
doc: "Whether or not this action should be used when no action is specified by the caller."
|
||||
],
|
||||
@global_opts shared_options()
|
||||
|
||||
@opt_schema Ash.OptionsHelpers.merge_schemas(
|
||||
[
|
||||
accept: [
|
||||
type: {:custom, Ash.OptionsHelpers, :list_of_atoms, []},
|
||||
doc:
|
||||
|
@ -29,7 +25,10 @@ defmodule Ash.Resource.Actions.Destroy do
|
|||
doc:
|
||||
"If specified, the destroy action calls the datalayer's update function with any specified changes."
|
||||
]
|
||||
]
|
||||
],
|
||||
@global_opts,
|
||||
"Action Options"
|
||||
)
|
||||
|
||||
@doc false
|
||||
def opt_schema, do: @opt_schema
|
||||
|
|
|
@ -1,30 +1,30 @@
|
|||
defmodule Ash.Resource.Actions.Read do
|
||||
@moduledoc "Represents a read action on a resource."
|
||||
|
||||
defstruct [:name, :primary?, :filter, type: :read]
|
||||
defstruct [:name, :primary?, :filter, :description, type: :read]
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
type: :read,
|
||||
name: atom,
|
||||
primary?: boolean
|
||||
primary?: boolean,
|
||||
description: String.t()
|
||||
}
|
||||
|
||||
@opt_schema [
|
||||
name: [
|
||||
type: :atom,
|
||||
doc: "The name of the action"
|
||||
],
|
||||
import Ash.Resource.Actions.SharedOptions
|
||||
|
||||
@global_opts shared_options()
|
||||
|
||||
@opt_schema Ash.OptionsHelpers.merge_schemas(
|
||||
[
|
||||
filter: [
|
||||
type: :any,
|
||||
doc:
|
||||
"A filter template, that may contain actor references. See `Ash.Filter` for more on templates"
|
||||
]
|
||||
],
|
||||
primary?: [
|
||||
type: :boolean,
|
||||
default: false,
|
||||
doc: "Whether or not this action should be used when no action is specified by the caller."
|
||||
]
|
||||
]
|
||||
@global_opts,
|
||||
"Action Options"
|
||||
)
|
||||
|
||||
@doc false
|
||||
def opt_schema, do: @opt_schema
|
||||
|
|
24
lib/ash/resource/actions/shared_options.ex
Normal file
24
lib/ash/resource/actions/shared_options.ex
Normal file
|
@ -0,0 +1,24 @@
|
|||
defmodule Ash.Resource.Actions.SharedOptions do
|
||||
@moduledoc false
|
||||
|
||||
@shared_options [
|
||||
name: [
|
||||
type: :atom,
|
||||
required: true,
|
||||
doc: "The name of the action"
|
||||
],
|
||||
primary?: [
|
||||
type: :boolean,
|
||||
default: false,
|
||||
doc: "Whether or not this action should be used when no action is specified by the caller."
|
||||
],
|
||||
description: [
|
||||
type: :string,
|
||||
doc: "An optional description for the action"
|
||||
]
|
||||
]
|
||||
|
||||
def shared_options do
|
||||
@shared_options
|
||||
end
|
||||
end
|
|
@ -1,31 +1,31 @@
|
|||
defmodule Ash.Resource.Actions.Update do
|
||||
@moduledoc "Represents a update action on a resource."
|
||||
|
||||
defstruct [:name, :primary?, :accept, :changes, type: :update]
|
||||
defstruct [:name, :primary?, :accept, :changes, :description, type: :update]
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
type: :update,
|
||||
name: atom,
|
||||
accept: [atom],
|
||||
primary?: boolean
|
||||
primary?: boolean,
|
||||
description: String.t()
|
||||
}
|
||||
|
||||
@opt_schema [
|
||||
name: [
|
||||
type: :atom,
|
||||
doc: "The name of the action"
|
||||
],
|
||||
import Ash.Resource.Actions.SharedOptions
|
||||
|
||||
@global_opts shared_options()
|
||||
|
||||
@opt_schema Ash.OptionsHelpers.merge_schemas(
|
||||
[
|
||||
accept: [
|
||||
type: {:custom, Ash.OptionsHelpers, :list_of_atoms, []},
|
||||
doc:
|
||||
"The list of attributes and relationships to accept. Defaults to all attributes on the resource"
|
||||
]
|
||||
],
|
||||
primary?: [
|
||||
type: :boolean,
|
||||
default: false,
|
||||
doc: "Whether or not this action should be used when no action is specified by the caller."
|
||||
]
|
||||
]
|
||||
@global_opts,
|
||||
"Action Options"
|
||||
)
|
||||
|
||||
@doc false
|
||||
def opt_schema, do: @opt_schema
|
||||
|
|
|
@ -12,6 +12,7 @@ defmodule Ash.Resource.Relationships.BelongsTo do
|
|||
:source,
|
||||
:required?,
|
||||
:writable?,
|
||||
:description,
|
||||
cardinality: :one,
|
||||
type: :belongs_to
|
||||
]
|
||||
|
@ -28,10 +29,11 @@ defmodule Ash.Resource.Relationships.BelongsTo do
|
|||
define_field?: boolean,
|
||||
field_type: Ash.Type.t(),
|
||||
destination_field: atom,
|
||||
source_field: atom | nil
|
||||
source_field: atom | nil,
|
||||
description: String.t()
|
||||
}
|
||||
|
||||
import Ash.Resource.Relationships.SharedOptions, only: [shared_options: 0]
|
||||
import Ash.Resource.Relationships.SharedOptions
|
||||
|
||||
alias Ash.OptionsHelpers
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ defmodule Ash.Resource.Relationships.HasMany do
|
|||
:source_field,
|
||||
:source,
|
||||
:writable?,
|
||||
:description,
|
||||
cardinality: :many,
|
||||
type: :has_many
|
||||
]
|
||||
|
@ -20,7 +21,8 @@ defmodule Ash.Resource.Relationships.HasMany do
|
|||
type: Ash.Type.t(),
|
||||
destination: Ash.resource(),
|
||||
destination_field: atom,
|
||||
source_field: atom
|
||||
source_field: atom,
|
||||
description: String.t()
|
||||
}
|
||||
|
||||
import Ash.Resource.Relationships.SharedOptions
|
||||
|
|
|
@ -9,6 +9,7 @@ defmodule Ash.Resource.Relationships.HasOne do
|
|||
:source_field,
|
||||
:allow_orphans?,
|
||||
:writable?,
|
||||
:description,
|
||||
cardinality: :one,
|
||||
type: :has_one
|
||||
]
|
||||
|
@ -23,7 +24,8 @@ defmodule Ash.Resource.Relationships.HasOne do
|
|||
destination: Ash.resource(),
|
||||
destination_field: atom,
|
||||
source_field: atom,
|
||||
allow_orphans?: boolean
|
||||
allow_orphans?: boolean,
|
||||
description: String.t()
|
||||
}
|
||||
|
||||
alias Ash.OptionsHelpers
|
||||
|
|
|
@ -12,6 +12,7 @@ defmodule Ash.Resource.Relationships.ManyToMany do
|
|||
:join_relationship,
|
||||
:join_attributes,
|
||||
:writable?,
|
||||
:description,
|
||||
cardinality: :many,
|
||||
type: :many_to_many
|
||||
]
|
||||
|
@ -29,7 +30,8 @@ defmodule Ash.Resource.Relationships.ManyToMany do
|
|||
source_field: atom,
|
||||
destination_field: atom,
|
||||
source_field_on_join_table: atom,
|
||||
destination_field_on_join_table: atom
|
||||
destination_field_on_join_table: atom,
|
||||
description: String.t()
|
||||
}
|
||||
|
||||
import Ash.Resource.Relationships.SharedOptions
|
||||
|
|
|
@ -24,6 +24,10 @@ defmodule Ash.Resource.Relationships.SharedOptions do
|
|||
type: :boolean,
|
||||
doc: "Whether or not the relationship may be edited.",
|
||||
default: true
|
||||
],
|
||||
description: [
|
||||
type: :string,
|
||||
doc: "An optional description for the relationship"
|
||||
]
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in a new issue