Class: ManyfoldApi::V0::CollectionSerializer

Inherits:
ApplicationSerializer show all
Defined in:
app/serializers/manyfold_api/v0/collection_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



16
17
18
19
20
21
22
23
24
25
26
# File 'app/serializers/manyfold_api/v0/collection_serializer.rb', line 16

def self.schema
  {
    type: :object,
    properties: {
      "@context": {"$ref" => "#/components/schemas/jsonld_context"},
      "@id": {type: :string, example: "https://example.com/collections/abc123"},
      "@type": {type: :string, example: "Collection"}
    }.merge(CollectionDeserializer.schema[:properties]),
    required: ["@context", "@id", "@type"]
  }
end

Instance Method Details

#serialize ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/serializers/manyfold_api/v0/collection_serializer.rb', line 3

def serialize
  collection_ref(@object).merge(
    "@context": context,
    name: @object.name,
    caption: @object.caption,
    description: @object.notes,
    creator: creator_ref(@object.creator),
    isPartOf: collection_ref(@object.collection),
    preview_model: model_ref(@object.preview_model),
    links: @object.links.map { LinkSerializer.new(it).serialize }
  ).compact
end