JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

After creation a resource is not rendered if its id is nil

Open
#1,025 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

In 0.8.3, I could 'create' a PORO object, and let the id of the object be nil, and everything would render well, i.e.:

class Poro
  def id
    nil
  end

  def save
    # some logic
  end
end

class PoroResource < JSONAPI::Resource; end
# POST /poros
{ "data": { "attributes": {}, "type": "poros" } }

# Response
{ "data": { "attributes": {}, "type": "poros", "id": null, "..etc..": "..etc.." } }

However, in 0.9.0, the data is just null:

# POST /poros
{ "data": { "attributes": {}, "type": "poros" } }

# Response
{ "data": null }

This is due to https://github.com/cerebris/jsonapi-resources/blob/release-0-9/lib/jsonapi/resource_serializer.rb#L69

Maybe a short line in the docs somewhere would let people know this happens.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the behavior described for POST /poros and inspect jsonapi/resource_serializer.rb at the referenced line in the release-0-9 branch. Confirm how a nil resource id affects serialization, then document the observed behavior so users know what to expect.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.