Skip to content

Commit

Permalink
bugfix JSI::Schema#described_object_property_names looks only at allO…
Browse files Browse the repository at this point in the history
…f, not oneOf/anyOf.

for oneOf/anyOf, the property names do not apply unless matched. the base schema is unly used if none of the *Of schemas match, meaning applying these properties of nonmatching subschemas is wholly incorrect.
  • Loading branch information
notEthan committed Nov 30, 2019
1 parent fcc478b commit c11ce63
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/jsi/schema.rb
Expand Up @@ -192,9 +192,8 @@ def subschema_for_index(index_)
# @return [Set] any object property names this schema indicates may be
# present on its instances. this includes, if present: keys of this
# schema's "properties" object; entries of this schema's array of
# "required" property keys. if this schema has oneOf/allOf/anyOf
# subschemas, those schemas are checked (recursively) for their
# described object property names.
# "required" property keys. if this schema has allOf subschemas, those
# schemas are checked (recursively) for their described object property names.
def described_object_property_names
memoize(:described_object_property_names) do
Set.new.tap do |property_names|
Expand All @@ -204,11 +203,10 @@ def described_object_property_names
if schema_node['required'].respond_to?(:to_ary)
property_names.merge(schema_node['required'].to_ary)
end
# we _could_ look at the properties of 'default' and each 'enum' but ... nah.
# we should look at dependencies (TODO).
%w(oneOf allOf anyOf).select { |k| schema_node[k].respond_to?(:to_ary) }.each do |schemas_key|
schema_node[schemas_key].map(&:deref).map do |someof_node|
property_names.merge(self.class.new(someof_node).described_object_property_names)
if schema_node['allOf'].respond_to?(:to_ary)
schema_node['allOf'].map(&:deref).map do |allOf_node|
property_names.merge(self.class.new(allOf_node).described_object_property_names)
end
end
end
Expand Down

0 comments on commit c11ce63

Please sign in to comment.