Class: ManyfoldApi::V0::ModelSerializer
- Inherits:
-
ApplicationSerializer
- Object
- ApplicationSerializer
- ManyfoldApi::V0::ModelSerializer
- Defined in:
- app/serializers/manyfold_api/v0/model_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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/serializers/manyfold_api/v0/model_serializer.rb', line 25 def self.schema { type: :object, properties: { "@context": {"$ref" => "#/components/schemas/jsonld_context"}, "@id": {type: :string, example: "https://example.com/models/abc123"}, "@type": {type: :string, example: "3DModel"}, hasPart: { type: :array, items: { type: :object, properties: { "@id": {type: :string, example: "https://example.com/models/abc123/model_files/def456"}, "@type": {type: :string, example: "3DModel"}, name: {type: :string, example: "Benchy"}, encodingFormat: {type: :string, example: "model/stl"} } }, required: ["@id", "@type", "name", "encodingFormat"] } }.merge(ModelDeserializer.schema[:properties]), required: ["@context", "@id", "@type", "hasPart"] } end |
Instance Method Details
#serialize ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/serializers/manyfold_api/v0/model_serializer.rb', line 3 def serialize model_ref(@object).merge( "@context": context, name: @object.name, caption: @object.caption, description: @object.notes, "spdx:license": license(@object.license), hasPart: @object.model_files.without_special.map do |file| file_ref(file).merge( name: file.name, encodingFormat: file.mime_type.to_s ) end, isPartOf: @object.collections.map { collection_ref(it) }, creator: creator_ref(@object.creator), sensitive: @object.sensitive, keywords: @object.tag_list, preview_file: file_ref(@object.preview_file), links: @object.links.map { LinkSerializer.new(it).serialize } ).compact end |