mirror of
https://github.com/ditkrg/schemable.git
synced 2026-01-25 07:36:40 +00:00
Updates RelationshipSchemaGenerator to correctly generate schemas
This commit is contained in:
@@ -33,20 +33,9 @@ module Schemable
|
||||
}
|
||||
}
|
||||
|
||||
result = {
|
||||
type: :object,
|
||||
properties: {
|
||||
data: {
|
||||
type: :object,
|
||||
properties: {
|
||||
id: { type: :string },
|
||||
type: { type: :string, default: definition[:definition].model_name }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result = relation_type == :belongs_to ? generate_schema(definition.model_name) : generate_schema(definition.model_name, collection: true)
|
||||
|
||||
result = non_expanded_data_properties if !expand || @relationships_to_exclude_from_expansion.include?(definition[:definition].model_name)
|
||||
result = non_expanded_data_properties if !expand || @relationships_to_exclude_from_expansion.include?(definition.model_name)
|
||||
|
||||
schema[:properties].merge!(relation => result)
|
||||
end
|
||||
@@ -62,5 +51,38 @@ module Schemable
|
||||
|
||||
schema
|
||||
end
|
||||
|
||||
def generate_schema(type_name, collection: false)
|
||||
if collection
|
||||
{
|
||||
type: :object,
|
||||
properties: {
|
||||
data: {
|
||||
type: :array,
|
||||
items: {
|
||||
type: :object,
|
||||
properties: {
|
||||
id: { type: :string },
|
||||
type: { type: :string, default: type_name }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
type: :object,
|
||||
properties: {
|
||||
data: {
|
||||
type: :object,
|
||||
properties: {
|
||||
id: { type: :string },
|
||||
type: { type: :string, default: type_name }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user