mirror of
https://github.com/ditkrg/schemable.git
synced 2026-01-22 22:26:41 +00:00
Updates RelationshipSchemaGenerator to correctly generate schemas
This commit is contained in:
parent
e046194f37
commit
e2ba1a7b8c
@ -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
|
||||
|
||||
@ -10,5 +10,7 @@ module Schemable
|
||||
def initialize: (Definition, ?relationships_to_exclude_from_expansion: Array[String], ?expand: bool) -> void
|
||||
|
||||
def generate: -> (Hash[Symbol, any] | Array[Hash[Symbol, any]])
|
||||
|
||||
def generate_schema: (String, ?collection: bool) -> Hash[Symbol, any]
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user