mirror of
https://github.com/ditkrg/schemable.git
synced 2026-01-22 22:26:41 +00:00
Changes Exclude Logic
This commit is contained in:
parent
ac70f1e7dd
commit
92d9f33d20
@ -21,14 +21,15 @@ module Schemable
|
|||||||
end
|
end
|
||||||
|
|
||||||
definitions.flatten!
|
definitions.flatten!
|
||||||
definition_names = definitions.map(&:model_name)
|
|
||||||
|
|
||||||
included_schemas = definitions.map do |definition|
|
included_schemas = definitions.map do |definition|
|
||||||
if expand && relationships_to_exclude_from_expansion.exclude?(definition.model_name)
|
next if relationships_to_exclude_from_expansion.include?(definition.model_name)
|
||||||
definition_relations = definition.relationships[:belongs_to].keys.map(&:to_s) + definition.relationships[:has_many].keys.map(&:to_s)
|
|
||||||
|
if expand
|
||||||
|
definition_relations = definition.relationships[:belongs_to].values.map(&:model_name) + definition.relationships[:has_many].values.map(&:model_name)
|
||||||
relations_to_exclude = []
|
relations_to_exclude = []
|
||||||
definition_relations.each do |relation|
|
definition_relations.each do |relation|
|
||||||
relations_to_exclude << relation if definition_names.exclude?(relation)
|
relations_to_exclude << relation if relationships_to_exclude_from_expansion.include?(relation)
|
||||||
end
|
end
|
||||||
|
|
||||||
prepare_schema_for_included(definition, expand:, relationships_to_exclude_from_expansion: relations_to_exclude)
|
prepare_schema_for_included(definition, expand:, relationships_to_exclude_from_expansion: relations_to_exclude)
|
||||||
@ -41,7 +42,7 @@ module Schemable
|
|||||||
included: {
|
included: {
|
||||||
type: :array,
|
type: :array,
|
||||||
items: {
|
items: {
|
||||||
anyOf: included_schemas
|
anyOf: included_schemas.compact_blank
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user