Updates RelationshipSchemaGenerator to correctly generate schemas

This commit is contained in:
Muhammad Nawzad
2023-11-12 10:29:19 +03:00
parent e046194f37
commit e2ba1a7b8c
2 changed files with 37 additions and 13 deletions

View File

@@ -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