Refactor generate_schema method to handle nullable relationships

This commit is contained in:
Muhammad Nawzad 2024-01-30 13:15:40 +03:00
parent 213a265ddd
commit dbfb9c1dd7
No known key found for this signature in database
GPG Key ID: B954B6AAE33940B2

View File

@ -84,7 +84,7 @@ module Schemable
#
# @return [Hash] The generated schema for the relationship.
def generate_schema(type_name, collection: false)
if collection
schema = if collection
{
type: :object,
properties: {
@ -114,6 +114,13 @@ module Schemable
}
}
end
# Modify the schema to nullable if the relationship is in nullable
is_relation_nullable = @model_definition.nullable_relationships.include?(type_name)
return schema unless is_relation_nullable
@schema_modifier.add_properties(schema, { nullable: true }, 'properties.data')
end
end
end