ash-project / ash-project/ash_json_api

Client provided `id` handling changes

Open
#276 8 comments 0 reactions 0 assignees View on GitHub
enhancement needs review
Dominant language
Elixir
Stars
94
Forks
80
Avg merge
5h 5m
Merged PRs (30d)
4

Description

**Is your feature request related to a problem? Please describe.**

# Allow `id` field to be set _outside_ the `attributes` object.

In the main API I operate, idempotence on create is handled by just setting the `id` of the resource. It's one of the joys of using UUIDs. Ash currently works with this:

```json
{
"data": {
"attributes": {
"id": "d67fc7b1-24d1-4c3a-9129-97ece194cbc8"
}
}
}
```

But not this:

```json
{
"data": {
"id": "d67fc7b1-24d1-4c3a-9129-97ece194cbc8"
}
```

**Describe the solution you'd like**

Simply accept `id` as a direct child of `data`. (I would say if the client provided it in two spots, an error is returned rather than argue about which has precedence.)

**Express the feature either with a change to resource syntax, or with a change to the resource interface**

Accepting IDs shouldn't require any actual DSL unless you wanted to support returning errors on `id` being a direct child of `data`.

Contributor guide

Open the contributing guide

Research direction

No file or test is named in the issue. Start by locating the JSON:API create-payload handling and the existing path for an id inside attributes; the work is done when a direct data id is accepted and supplying ids in both locations returns an error, with coverage for these cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.