Class: ManyfoldApi::V0::GroupSerializer

Inherits:
ApplicationSerializer show all
Defined in:
app/serializers/manyfold_api/v0/group_serializer.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationSerializer

#collection_ref, #context, #creator_ref, #file_ref, #group_ref, #initialize, #license, #model_ref, #ref, schema_ref, schema_ref_name

Constructor Details

This class inherits a constructor from ManyfoldApi::V0::ApplicationSerializer

Class Method Details

.schema ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/serializers/manyfold_api/v0/group_serializer.rb', line 12

def self.schema
  {
    type: :object,
    properties: {
      "@context": {"$ref" => "#/components/schemas/jsonld_context"},
      "@id": {type: :string, example: "https://example.com/creators/abc123/groups/1"},
      "@type": {type: :string, example: "Group"},
      members: {type: :array, items: {type: :string, example: "username"}}
    }.merge(GroupDeserializer.schema[:properties].except(:add_members, :remove_members)),
    required: ["@context", "@id", "@type"]
  }
end

Instance Method Details

#serialize ⇒ Object



3
4
5
6
7
8
9
10
# File 'app/serializers/manyfold_api/v0/group_serializer.rb', line 3

def serialize
  group_ref(@object).merge(
    "@context": context,
    name: @object.name,
    description: @object.description,
    members: @object.members.active.map(&:username)
  ).compact
end