mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-23 05:28:53 +00:00
Add relationships to resource serializers
This commit is contained in:
committed by
Maikel Linke
parent
d66d6d6bd6
commit
d87e1805af
@@ -19,4 +19,8 @@ class CustomerSchema < JsonApiSchema
|
||||
def self.required_attributes
|
||||
[:enterprise_id, :email]
|
||||
end
|
||||
|
||||
def self.relationships
|
||||
[:enterprise]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
20
app/json_schemas/relationship_schema.rb
Normal file
20
app/json_schemas/relationship_schema.rb
Normal 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
|
||||
Reference in New Issue
Block a user