Skip to content

Latest commit

 

History

History
697 lines (459 loc) · 49.3 KB

File metadata and controls

697 lines (459 loc) · 49.3 KB

AshJsonApi.Resource

The entrypoint for adding JSON:API behavior to a resource"

json_api

Configure the resource's behavior in the JSON:API

Nested DSLs

  • routes
    • get
    • index
    • post
    • patch
    • delete
    • related
    • relationship
    • post_to_relationship
    • patch_relationship
    • delete_from_relationship
    • route
  • primary_key

Examples

json_api do
  type "post"
  includes [
    friends: [
      :comments
    ],
    comments: []
  ]

  routes do
    base "/posts"

    get :read
    get :me, route: "/me"
    index :read
    post :confirm_name, route: "/confirm_name"
    patch :update
    related :comments, :read
    relationship :comments, :read
    post_to_relationship :comments
    patch_relationship :comments
    delete_from_relationship :comments
  end
end

Options

Name Type Default Docs
type{: #json_api-type } String.t The resource identifier type of this resource in JSON:API
always_include_linkage{: #json_api-always_include_linkage } list(atom) [] A list of relationships that should always have their linkage included in the resource
includes{: #json_api-includes } any | list(any) [] A keyword list of all paths that are includable from this resource
paginated_includes{: #json_api-paginated_includes } list(atom | list(atom)) [] A list of relationship paths that can be paginated when included via the included_page query parameter. Each entry can be either an atom (for top-level relationships) or a list of atoms (for nested paths).
include_nil_values?{: #json_api-include_nil_values? } any Whether or not to include properties for values that are nil in the JSON output
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
derive_sort?{: #json_api-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
relationship_meta_in{: #json_api-relationship_meta_in } keyword [] Configures how incoming JSON:API meta keys on relationship resource identifiers map to join resource attributes for many_to_many relationship writes. Use together with relationship_meta_out for reads. Each relationship you want to support must declare both mappings explicitly.
relationship_meta_out{: #json_api-relationship_meta_out } keyword [] Configures how join resource attributes map to outgoing JSON:API meta keys on relationship resource identifiers for many_to_many relationship reads. Use together with relationship_meta_in for writes. Each relationship you want to support must declare both mappings explicitly.
field_names{: #json_api-field_names } :camelize | :dasherize | keyword | (any -> any) Renames fields (attributes, relationships, calculations, and aggregates) in the JSON:API output and input. Can be one of the atoms :camelize or :dasherize for automatic conversion, 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). elixir field_names :camelize # first_name → firstName field_names :dasherize # first_name → first-name Or with a keyword list: elixir field_names [ first_name: :firstName, last_name: :lastName ] Or with a function for custom logic: elixir field_names fn name -> camelized = name |> to_string() |> Macro.camelize() {first, rest} = String.split_at(camelized, 1) String.downcase(first) <> rest end Names are applied consistently across serialization, request parsing, sort/filter parameters, field selection, error source pointers, relationship keys, and schema generation.
argument_names{: #json_api-argument_names } :camelize | :dasherize | keyword | (any, any -> any) Renames action arguments in the JSON:API request body and schema. Can be one of the atoms :camelize or :dasherize for automatic conversion, 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 :camelize # publish_at → publishAt argument_names :dasherize # publish_at → publish-at Or with a keyword list: elixir argument_names [ create: [my_arg: :myArg], update: [my_arg: :myArg] ] Or with a function: elixir argument_names fn _action, name -> camelized = name |> to_string() |> Macro.camelize() {first, rest} = String.split_at(camelized, 1) String.downcase(first) <> rest end
calculation_argument_names{: #json_api-calculation_argument_names } :camelize | :dasherize | keyword | (any, any -> any) Renames calculation arguments in the JSON:API request and schema. Works the same way as argument_names but applies to calculation arguments instead of action arguments. The 2-arity function receives (calculation_name, argument_name). Can be one of the atoms :camelize or :dasherize for automatic conversion, a nested keyword list of [calc_name: [ash_name: :json_api_name]] mappings, or a 2-arity function that receives (calculation_name, argument_name) atoms and returns the desired JSON:API name (atom or string). elixir calculation_argument_names :camelize # publish_at → publishAt calculation_argument_names :dasherize # publish_at → publish-at Or with a keyword list: elixir calculation_argument_names [ full_name: [separator: :sep] ] Or with a function: elixir calculation_argument_names fn _calc, name -> camelized = name |> to_string() |> Macro.camelize() {first, rest} = String.split_at(camelized, 1) String.downcase(first) <> rest end

json_api.routes

Configure the routes that will be exposed via the JSON:API

Nested DSLs

Examples

routes do
  base "/posts"

  get :read
  get :me, route: "/me"
  index :read
  post :confirm_name, route: "/confirm_name"
  patch :update
  related :comments, :read
  relationship :comments, :read
  post_to_relationship :comments
  patch_relationship :comments
  delete_from_relationship :comments
end

Options

Name Type Default Docs
base{: #json_api-routes-base } String.t A base route for the resource, e.g "/users"

json_api.routes.get

get action

A GET route to retrieve a single record

Examples

get :read
get :read, path_param_is_composite_key: :id

Arguments

Name Type Default Docs
action{: #json_api-routes-get-action .spark-required} atom The action to call when this route is hit

Options

Name Type Default Docs
route{: #json_api-routes-get-route } String.t "/:id" The path of the route
default_fields{: #json_api-routes-get-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-get-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-get-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-get-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
action_names_in_schema{: #json_api-routes-get-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-get-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-get-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-get-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-get-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-get-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.

Introspection

Target: AshJsonApi.Resource.Route

json_api.routes.index

index action

A GET route to retrieve a list of records

Examples

index :read

Arguments

Name Type Default Docs
action{: #json_api-routes-index-action .spark-required} atom The action to call when this route is hit

Options

Name Type Default Docs
paginate?{: #json_api-routes-index-paginate? } boolean true
route{: #json_api-routes-index-route } String.t "/" The path of the route
default_fields{: #json_api-routes-index-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-index-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-index-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-index-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
action_names_in_schema{: #json_api-routes-index-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-index-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-index-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-index-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-index-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-index-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.

Introspection

Target: AshJsonApi.Resource.Route

json_api.routes.post

post action

A POST route to create a record

Examples

post :create

Arguments

Name Type Default Docs
action{: #json_api-routes-post-action .spark-required} atom The action to call when this route is hit

Options

Name Type Default Docs
route{: #json_api-routes-post-route } String.t "/" The path of the route
default_fields{: #json_api-routes-post-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-post-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-post-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-post-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
query_params{: #json_api-routes-post-query_params } list(atom) [] A list of action inputs to accept as query parameters.
action_names_in_schema{: #json_api-routes-post-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-post-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-post-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-post-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-post-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-post-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.
relationship_arguments{: #json_api-routes-post-relationship_arguments } list(atom | {:id, atom}) [] Arguments to be used to edit relationships. See the relationships guide for more.
upsert?{: #json_api-routes-post-upsert? } boolean false Whether or not to use the upsert?: true option when calling Ash.create/2.
upsert_identity{: #json_api-routes-post-upsert_identity } atom false Which identity to use for the upsert

Introspection

Target: AshJsonApi.Resource.Route

json_api.routes.patch

patch action

A PATCH route to update a record

Examples

patch :update
patch :update, path_param_is_composite_key: :id

Arguments

Name Type Default Docs
action{: #json_api-routes-patch-action .spark-required} atom The action to call when this route is hit

Options

Name Type Default Docs
relationship_arguments{: #json_api-routes-patch-relationship_arguments } any [] Arguments to be used to edit relationships. See the relationships guide for more.
read_action{: #json_api-routes-patch-read_action } atom The read action to use to look the record up before updating
route{: #json_api-routes-patch-route } String.t "/:id" The path of the route
default_fields{: #json_api-routes-patch-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-patch-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-patch-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-patch-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
query_params{: #json_api-routes-patch-query_params } list(atom) [] A list of action inputs to accept as query parameters.
action_names_in_schema{: #json_api-routes-patch-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-patch-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-patch-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-patch-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-patch-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-patch-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.

Introspection

Target: AshJsonApi.Resource.Route

json_api.routes.delete

delete action

A DELETE route to destroy a record

Examples

delete :destroy
delete :destroy, path_param_is_composite_key: :id

Arguments

Name Type Default Docs
action{: #json_api-routes-delete-action .spark-required} atom The action to call when this route is hit

Options

Name Type Default Docs
read_action{: #json_api-routes-delete-read_action } atom The read action to use to look the record up before updating
route{: #json_api-routes-delete-route } String.t "/:id" The path of the route
default_fields{: #json_api-routes-delete-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-delete-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-delete-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-delete-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
query_params{: #json_api-routes-delete-query_params } list(atom) [] A list of action inputs to accept as query parameters.
action_names_in_schema{: #json_api-routes-delete-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-delete-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-delete-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-delete-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-delete-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-delete-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.

Introspection

Target: AshJsonApi.Resource.Route

json_api.routes.related

related relationship, action

A GET route to read the related resources of a relationship

Examples

related :comments, :read

Arguments

Name Type Default Docs
relationship{: #json_api-routes-related-relationship .spark-required} atom
action{: #json_api-routes-related-action .spark-required} atom The action to call when this route is hit

Options

Name Type Default Docs
route{: #json_api-routes-related-route } String.t The path of the route - Defaults to /:id/[relationship_name]
default_fields{: #json_api-routes-related-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-related-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-related-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-related-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
query_params{: #json_api-routes-related-query_params } list(atom) [] A list of action inputs to accept as query parameters.
action_names_in_schema{: #json_api-routes-related-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-related-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-related-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-related-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-related-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-related-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.

Introspection

Target: AshJsonApi.Resource.Route

json_api.routes.relationship

relationship relationship, action

A READ route to read the relationship, returns resource identifiers.

Examples

relationship :comments, :read

Arguments

Name Type Default Docs
relationship{: #json_api-routes-relationship-relationship .spark-required} atom
action{: #json_api-routes-relationship-action .spark-required} atom The action to call when this route is hit

Options

Name Type Default Docs
route{: #json_api-routes-relationship-route } String.t The path of the route - Defaults to /:id/relationships/[relationship_name]
default_fields{: #json_api-routes-relationship-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-relationship-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-relationship-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-relationship-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
query_params{: #json_api-routes-relationship-query_params } list(atom) [] A list of action inputs to accept as query parameters.
action_names_in_schema{: #json_api-routes-relationship-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-relationship-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-relationship-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-relationship-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-relationship-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-relationship-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.

Introspection

Target: AshJsonApi.Resource.Route

json_api.routes.post_to_relationship

post_to_relationship relationship

A POST route to create related entities using resource identifiers

Examples

post_to_relationship :comments

Arguments

Name Type Default Docs
relationship{: #json_api-routes-post_to_relationship-relationship .spark-required} atom

Options

Name Type Default Docs
route{: #json_api-routes-post_to_relationship-route } String.t The path of the route - Defaults to /:id/relationships/[relationship_name]
default_fields{: #json_api-routes-post_to_relationship-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-post_to_relationship-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-post_to_relationship-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-post_to_relationship-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
query_params{: #json_api-routes-post_to_relationship-query_params } list(atom) [] A list of action inputs to accept as query parameters.
action_names_in_schema{: #json_api-routes-post_to_relationship-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-post_to_relationship-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-post_to_relationship-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-post_to_relationship-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-post_to_relationship-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-post_to_relationship-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.

Introspection

Target: AshJsonApi.Resource.Route

json_api.routes.patch_relationship

patch_relationship relationship

A PATCH route to update a relationship using resource identifiers

Examples

patch_relationship :comments

Arguments

Name Type Default Docs
relationship{: #json_api-routes-patch_relationship-relationship .spark-required} atom

Options

Name Type Default Docs
route{: #json_api-routes-patch_relationship-route } String.t The path of the route - Defaults to /:id/relationships/[relationship_name]
default_fields{: #json_api-routes-patch_relationship-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-patch_relationship-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-patch_relationship-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-patch_relationship-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
query_params{: #json_api-routes-patch_relationship-query_params } list(atom) [] A list of action inputs to accept as query parameters.
action_names_in_schema{: #json_api-routes-patch_relationship-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-patch_relationship-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-patch_relationship-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-patch_relationship-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-patch_relationship-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-patch_relationship-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.

Introspection

Target: AshJsonApi.Resource.Route

json_api.routes.delete_from_relationship

delete_from_relationship relationship

A DELETE route to remove related entities using resource identifiers

Examples

delete_from_relationship :comments

Arguments

Name Type Default Docs
relationship{: #json_api-routes-delete_from_relationship-relationship .spark-required} atom

Options

Name Type Default Docs
route{: #json_api-routes-delete_from_relationship-route } String.t The path of the route - Defaults to /:id/relationships/[relationship_name]
default_fields{: #json_api-routes-delete_from_relationship-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-delete_from_relationship-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-delete_from_relationship-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-delete_from_relationship-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
query_params{: #json_api-routes-delete_from_relationship-query_params } list(atom) [] A list of action inputs to accept as query parameters.
action_names_in_schema{: #json_api-routes-delete_from_relationship-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-delete_from_relationship-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-delete_from_relationship-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-delete_from_relationship-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-delete_from_relationship-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-delete_from_relationship-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.

Introspection

Target: AshJsonApi.Resource.Route

json_api.routes.route

route method, route, action

A route for a generic action.

Examples

route :get, "say_hi/:name", :say_hello

Arguments

Name Type Default Docs
method{: #json_api-routes-route-method .spark-required} atom The HTTP method for the route, e.g :get, or :post
route{: #json_api-routes-route-route .spark-required} String.t The path of the route
action{: #json_api-routes-route-action .spark-required} atom The action to call when this route is hit

Options

Name Type Default Docs
wrap_in_result?{: #json_api-routes-route-wrap_in_result? } boolean false Whether or not the action result should be wrapped in {result: <result>}
default_fields{: #json_api-routes-route-default_fields } list(atom) A list of fields to be shown in the attributes of the called route
primary?{: #json_api-routes-route-primary? } boolean false Whether or not this is the route that should be linked to by default when rendering links to this type of route
metadata{: #json_api-routes-route-metadata } (any, any, any -> any) A function to generate arbitrary top-level metadata for the JSON:API response
modify_conn{: #json_api-routes-route-modify_conn } (any, any, any, any -> any) A function to modify the conn before responding. Used for things like setting headers based on the response. Takes conn, subject, result, request. See the modify_conn guide for more details and examples.
query_params{: #json_api-routes-route-query_params } list(atom) [] A list of action inputs to accept as query parameters.
action_names_in_schema{: #json_api-routes-route-action_names_in_schema } keyword A mapping of action names to how they should appear in the OpenAPI schema. You only need to set this if you see a warning during schema generation.
name{: #json_api-routes-route-name } String.t A globally unique name for this route, to be used when generating docs and open api specifications
description{: #json_api-routes-route-description } String.t A human-friendly description of this specific route to use in generated documentation and OpenAPI. If provided, this overrides the action description.
derive_sort?{: #json_api-routes-route-derive_sort? } boolean true Whether or not to derive a sort parameter based on the sortable fields of the resource
derive_filter?{: #json_api-routes-route-derive_filter? } boolean true Whether or not to derive a filter parameter based on the sortable fields of the resource
path_param_is_composite_key{: #json_api-routes-route-path_param_is_composite_key } atom The path parameter that should be parsed as a composite primary key. When specified (e.g., :id), the parameter will be split using the resource's primary key delimiter and mapped to individual primary key fields. This is required for resources with composite primary keys to work correctly with GET, PATCH, and DELETE operations. See the composite primary keys documentation for more details.

Introspection

Target: AshJsonApi.Resource.Route

json_api.primary_key

Encode the id of the JSON API response from selected attributes of a resource

Examples

primary_key do
  keys [:first_name, :last_name]
  delimiter "~"
end

Options

Name Type Default Docs
keys{: #json_api-primary_key-keys .spark-required} atom | list(atom) the list of attributes to encode JSON API primary key
delimiter{: #json_api-primary_key-delimiter } String.t "-" The delimiter to concatenate the primary key values. Default to be '-'
<style type="text/css">.spark-required::after { content: "*"; color: red !important; }</style>