Add relationships to resource serializers

This commit is contained in:
Matt-Yorkley
2021-12-12 20:51:39 +00:00
committed by Maikel Linke
parent d66d6d6bd6
commit d87e1805af
3 changed files with 34 additions and 1 deletions

View File

@@ -19,4 +19,8 @@ class CustomerSchema < JsonApiSchema
def self.required_attributes
[:enterprise_id, :email]
end
def self.relationships
[:enterprise]
end
end

View File

@@ -10,6 +10,10 @@ class JsonApiSchema
[]
end
def relationships
[]
end
def all_attributes
attributes.keys
end
@@ -83,7 +87,12 @@ class JsonApiSchema
properties: attributes,
required: required
},
relationships: { type: :object }
relationships: {
type: :object,
properties: relationships.to_h do |name|
[name, { "$ref" => "#/components/schemas/relationship" }]
end
}
}
end
end

View File

@@ -0,0 +1,20 @@
# frozen_string_literal: true
class RelationshipSchema
def self.schema
{
type: :object,
properties: {
data: {
type: [:object, :array]
},
links: {
type: :object,
properties: {
related: { type: :string }
}
}
}
}
end
end