active_model_serializers

https://github.com/rails-api/active_model_serializers

Ruby

ActiveModel::Serializer implementation and Rails hooks

ActiveModelSerializers::Adapter::JsonApi#relationships_for

{http://jsonapi.org/format/#document-resource-object-relationships Document Resource Object Relationship}
relationships
definition:
  JSON Object

patternProperties:
  ^\\w[-\\w_]*$"

properties:
  data : relationshipsData
  links
  meta

description:

  Members of the relationships object ("relationships") represent references from the
  resource object in which it's defined to other resource objects."
structure:
  {
    links: links,
    meta: meta,
    data: relationshipsData
  }.reject! {|_,v| v.nil? }

prs:
  links
    [x] https://github.com/rails-api/active_model_serializers/pull/1454
  meta
    [x] https://github.com/rails-api/active_model_serializers/pull/1454
  polymorphic
    [ ] https://github.com/rails-api/active_model_serializers/pull/1420

relationshipsData
definition:
  oneOf
    relationshipToOne
    relationshipToMany

description:
  Member, whose value represents "resource linkage"
structure:
  if has_one?
    relationshipToOne
  else
    relationshipToMany
  end

definition:
  anyOf
    null
    linkage

relationshipToOne
description:

  References to other resource objects in a to-one ("relationship"). Relationships can be
  specified by including a member in a resource's links object.

  None: Describes an empty to-one relationship.
structure:
  if has_related?
    linkage
  else
    nil
  end

relationshipToMany
definition:
  array of unique items of type 'linkage'

description:
  An array of objects each containing "type" and "id" members for to-many relationships
structure:
  [
    linkage,
    linkage
  ]
prs:
  polymorphic
    [ ] https://github.com/rails-api/active_model_serializers/pull/1282

linkage
definition:
  type (required) : String
  id   (required) : String
  meta

description:
  The "type" and "id" to non-empty members.
structure:
  {
    type: 'required-type',
    id: 'required-id',
    meta: meta
  }.reject! {|_,v| v.nil? }

Source | Google | Stack overflow

Edit

git clone [email protected]:rails-api/active_model_serializers.git

cd active_model_serializers

open lib/active_model_serializers/adapter/json_api.rb

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-ActiveModelSerializers--Adapter--JsonApi-relationships_for-for-pr


# Commit to git

git add lib/active_model_serializers/adapter/json_api.rbgit commit -m "better docs for ActiveModelSerializers::Adapter::JsonApi#relationships_for"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-ActiveModelSerializers--Adapter--JsonApi-relationships_for-for-pr

hub pull-request


# Celebrate!