Class: ManyfoldApi::V0::ModelFileSerializer
- Inherits:
-
ApplicationSerializer
- Object
- ApplicationSerializer
- ManyfoldApi::V0::ModelFileSerializer
- Defined in:
- app/serializers/manyfold_api/v0/model_file_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
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/serializers/manyfold_api/v0/model_file_serializer.rb', line 24 def self.schema { type: :object, properties: { # JSON-LD "@context": {"$ref" => "#/components/schemas/jsonld_context"}, "@id": {type: :string, example: "https://example.com/models/abc123/model_files/def456"}, "@type": {type: :string, example: "3DModel"}, # Derived attributes name: {type: :string, example: "Benchy"}, encodingFormat: {type: :string, example: "model/stl"}, contentUrl: {type: :string, example: "https://example.com/models/abc123/model_files/def456.stl"}, contentSize: {type: :integer, example: 12345}, # Attributes from model isPartOf: {type: :object, properties: { "@id": {type: :string, example: "https://example.com/models/abc123"}, "@type": {type: :string, example: "3DModel"} }}, "spdx:license": {"$ref" => "#/components/schemas/spdxLicense"}, creator: { type: :object, properties: { "@id": {type: :string, example: "https://example.com/creators/abc123"}, "@type": {type: :string, example: "Organization"} } } }.merge(ModelFileDeserializer.schema[:properties]), required: ["@context", "@id", "@type", "isPartOf", "encodingFormat"] } 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 |
# File 'app/serializers/manyfold_api/v0/model_file_serializer.rb', line 3 def serialize file_ref(@object).merge( "@context": context, name: @object.name, isPartOf: model_ref(@object.model), contentUrl: Rails.application.routes.url_helpers.model_model_file_path(@object.model, @object, format: @object.extension), encodingFormat: @object.mime_type.to_s, contentSize: @object.size, description: @object.notes, caption: @object.caption, presupported: @object.presupported, up: @object.up_direction, related: [ @object.presupported_version ? file_ref(@object.presupported_version).merge(relationship: "presupported_version") : nil, @object.unsupported_version ? file_ref(@object.unsupported_version).merge(relationship: "presupported_version_of") : nil ].compact, "spdx:license": license(@object.model.license), creator: creator_ref(@object.model.creator) ).compact end |