Skip to content

PATCH action requires all required attributes to be provided #286

@smt116

Description

@smt116

Describe the bug

λ curl -XPATCH -H 'Content-Type: application/vnd.api+json' -d '{"data": {"attributes": {"first_name": "Johny"}}}' -H "Authorization: Basic ..." "http://localhost:4000/api/customers/0194db1f-2294-7459-84e1-45215ffc76ca"  | jq

{
  "errors": [
    {
      "code": "invalid_body",
      "id": "4e9ef680-e3d6-40a5-8bb7-46682a36d0ac",
      "meta": {},
      "status": "400",
      "title": "InvalidBody",
      "source": {
        "pointer": "/data/attributes"
      },
      "detail": "Required properties are missing: [\"email\", \"last_name\"], at [\"data\", \"attributes\"]."
    }
  ],
  "jsonapi": {
    "version": "1.0"
  }
}

The domain exposes patch(:update) JSON API on the resource. The action itself is defined via defaults. It lists attributes that are allow_nil? false.

According to the specification, it should allow this request by updating only included attribute(s) (see https://jsonapi.org/format/#crud-updating-resource-attributes)

To Reproduce
See above.

Expected behavior
The action should allow partial updates via PATCH.

** Runtime

Dependency              Current  Latest   Status
ash                     3.4.62   3.4.62   Up-to-date
ash_json_api            1.4.18   1.4.18   Up-to-date
ash_paper_trail         0.5.0    0.5.0    Up-to-date
ash_phoenix             2.1.17   2.1.17   Up-to-date
ash_postgres            2.5.1    2.5.1    Up-to-date
bandit                  1.6.7    1.6.7    Up-to-date
bcrypt_elixir           3.2.0    3.2.1    Update possible
comeonin                5.5.1    5.5.1    Up-to-date
credo                   1.7.11   1.7.11   Up-to-date
dialyxir                1.4.5    1.4.5    Up-to-date
dns_cluster             0.1.3    0.1.3    Up-to-date
ecto_sql                3.12.1   3.12.1   Up-to-date
esbuild                 0.8.2    0.8.2    Up-to-date
finch                   0.19.0   0.19.0   Up-to-date
floki                   0.37.0   0.37.0   Up-to-date
gettext                 0.26.2   0.26.2   Up-to-date
igniter                 0.5.21   0.5.21   Up-to-date
jason                   1.4.4    1.4.4    Up-to-date
mix_audit               2.1.4    2.1.4    Up-to-date
open_api_spex           3.21.2   3.21.2   Up-to-date
phoenix                 1.7.19   1.7.19   Up-to-date
phoenix_ecto            4.6.3    4.6.3    Up-to-date
phoenix_html            4.2.0    4.2.0    Up-to-date
phoenix_live_dashboard  0.8.6    0.8.6    Up-to-date
phoenix_live_reload     1.5.3    1.5.3    Up-to-date
phoenix_live_view       1.0.4    1.0.4    Up-to-date
postgrex                0.20.0   0.20.0   Up-to-date
sobelow                 0.13.0   0.13.0   Up-to-date
sourceror               1.7.1    1.7.1    Up-to-date
stream_data             1.1.2    1.1.2    Up-to-date
swoosh                  1.17.9   1.17.10  Update possible
tailwind                0.2.4    0.2.4    Up-to-date
telemetry_metrics       1.1.0    1.1.0    Up-to-date
telemetry_poller        1.1.0    1.1.0    Up-to-date

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions