Class: Babl::Schema::AnyOf

Inherits:
Object
  • Object
show all
Defined in:
lib/babl/schema/any_of.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(choices) ⇒ AnyOf

Returns a new instance of AnyOf.



9
10
11
12
# File 'lib/babl/schema/any_of.rb', line 9

def initialize(choices)
    flattened_choices = choices.flat_map { |doc| AnyOf === doc ? doc.choice_set.to_a : [doc] }.uniq
    super(flattened_choices.to_set.freeze)
end

Class Method Details

.canonicalized(choices) ⇒ Object



34
35
36
# File 'lib/babl/schema/any_of.rb', line 34

def self.canonicalized(choices)
    new(choices).simplify
end

Instance Method Details

#jsonObject



14
15
16
# File 'lib/babl/schema/any_of.rb', line 14

def json
    json_only_primitives || json_coalesced_types || json_general_case
end

#simplifyObject

Perform simple transformations in order to reduce the size of the generated schema.



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/babl/schema/any_of.rb', line 20

def simplify
    simplify_single ||
        simplify_anything ||
        simplify_boolean ||
        simplify_typed_and_static ||
        simplify_empty_array ||
        simplify_push_down_dyn_array ||
        simplify_dyn_and_fixed_array ||
        simplify_merge_objects ||
        simplify_integer_is_number ||
        simplify_many_fixed_arrays ||
        self
end