diff --git a/lib/schemable/included_schema_generator.rb b/lib/schemable/included_schema_generator.rb index 4786c01..7c3e02a 100644 --- a/lib/schemable/included_schema_generator.rb +++ b/lib/schemable/included_schema_generator.rb @@ -1,14 +1,11 @@ module Schemable class IncludedSchemaGenerator - attr_accessor :model_definition, :schema_modifier, :configuration, :relationships, :expand, :relationships_to_exclude_from_expansion + attr_accessor :model_definition, :schema_modifier, :relationships - def initialize(model_definition, relationships_to_exclude_from_expansion: [], expand: false) - @expand = expand + def initialize(model_definition) @model_definition = model_definition @schema_modifier = SchemaModifier.new - @configuration = Schemable.configuration @relationships = @model_definition.relationships - @relationships_to_exclude_from_expansion = relationships_to_exclude_from_expansion end def generate(expand: false, relationships_to_exclude_from_expansion: []) @@ -56,7 +53,7 @@ module Schemable def prepare_schema_for_included(model_definition, expand: false, relationships_to_exclude_from_expansion: []) attributes_schema = AttributeSchemaGenerator.new(model_definition).generate - relationships_schema = RelationshipSchemaGenerator.new(model_definition, relationships_to_exclude_from_expansion:, expand:) + relationships_schema = RelationshipSchemaGenerator.new(model_definition).generate(relationships_to_exclude_from_expansion:, expand:) { type: :object, diff --git a/lib/schemable/relationship_schema_generator.rb b/lib/schemable/relationship_schema_generator.rb index 609d75c..383e5af 100644 --- a/lib/schemable/relationship_schema_generator.rb +++ b/lib/schemable/relationship_schema_generator.rb @@ -1,17 +1,14 @@ module Schemable class RelationshipSchemaGenerator - attr_accessor :model_definition, :schema_modifier, :configuration, :relationships, :expand, :relationships_to_exclude_from_expansion + attr_accessor :model_definition, :schema_modifier, :relationships - def initialize(model_definition, relationships_to_exclude_from_expansion: [], expand: false) - @expand = expand + def initialize(model_definition) @model_definition = model_definition @schema_modifier = SchemaModifier.new - @configuration = Schemable.configuration @relationships = model_definition.relationships - @relationships_to_exclude_from_expansion = relationships_to_exclude_from_expansion end - def generate + def generate(relationships_to_exclude_from_expansion: [], expand: false) return {} if @relationships.blank? || @relationships == { belongs_to: {}, has_many: {} } schema = { @@ -35,7 +32,7 @@ module Schemable 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.model_name) + result = non_expanded_data_properties if !expand || relationships_to_exclude_from_expansion.include?(definition.model_name) schema[:properties].merge!(relation => result) end diff --git a/sig/schemable/included_schema_generator.rbs b/sig/schemable/included_schema_generator.rbs index 796b6ea..a090746 100644 --- a/sig/schemable/included_schema_generator.rbs +++ b/sig/schemable/included_schema_generator.rbs @@ -7,7 +7,7 @@ module Schemable attr_accessor relationships: Hash[Symbol, any] attr_accessor relationships_to_exclude_from_expansion: Array[String] - def initialize: (Definition, ?relationships_to_exclude_from_expansion: Array[String], ?expand: bool) -> void + def initialize: (Definition) -> void def prepare_schema_for_included: (Definition, ?relationships_to_exclude_from_expansion: Array[String], ?expand: bool) -> Hash[Symbol, any] diff --git a/sig/schemable/relationship_schema_generator.rbs b/sig/schemable/relationship_schema_generator.rbs index a1c50e0..2e6a874 100644 --- a/sig/schemable/relationship_schema_generator.rbs +++ b/sig/schemable/relationship_schema_generator.rbs @@ -1,15 +1,12 @@ module Schemable class RelationshipSchemaGenerator - attr_accessor expand: bool attr_accessor model_definition: Definition - attr_accessor configuration: Configuration attr_accessor schema_modifier: SchemaModifier attr_accessor relationships: Hash[Symbol, any] - attr_accessor relationships_to_exclude_from_expansion: Array[String] - def initialize: (Definition, ?relationships_to_exclude_from_expansion: Array[String], ?expand: bool) -> void + def initialize: (Definition) -> void - def generate: -> (Hash[Symbol, any] | Array[Hash[Symbol, any]]) + def generate: (?relationships_to_exclude_from_expansion: Array[String], ?expand: bool) -> (Hash[Symbol, any] | Array[Hash[Symbol, any]]) def generate_schema: (String, ?collection: bool) -> Hash[Symbol, any] end