Class: Fitting::Cover::JSONSchema
- Inherits:
-
Object
- Object
- Fitting::Cover::JSONSchema
- Defined in:
- lib/fitting/cover/json_schema.rb
Instance Attribute Summary collapse
-
#combinations ⇒ Object
readonly
Returns the value of attribute combinations.
-
#json_schema ⇒ Object
readonly
Returns the value of attribute json_schema.
Instance Method Summary collapse
- #combi ⇒ Object
- #inception(json_schema, combinations) ⇒ Object
-
#initialize(json_schema) ⇒ JSONSchema
constructor
A new instance of JSONSchema.
Constructor Details
#initialize(json_schema) ⇒ JSONSchema
Returns a new instance of JSONSchema.
6 7 8 9 |
# File 'lib/fitting/cover/json_schema.rb', line 6 def initialize(json_schema) @json_schema = json_schema @combinations = [] end |
Instance Attribute Details
#combinations ⇒ Object (readonly)
Returns the value of attribute combinations.
4 5 6 |
# File 'lib/fitting/cover/json_schema.rb', line 4 def combinations @combinations end |
#json_schema ⇒ Object (readonly)
Returns the value of attribute json_schema.
4 5 6 |
# File 'lib/fitting/cover/json_schema.rb', line 4 def json_schema @json_schema end |
Instance Method Details
#combi ⇒ Object
11 12 13 14 15 16 |
# File 'lib/fitting/cover/json_schema.rb', line 11 def combi inception(json_schema, combinations).each do |combination| combination[0] = json_schema.merge(combination[0]) combination[1] = ['required', combination[1]] end end |
#inception(json_schema, combinations) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/fitting/cover/json_schema.rb', line 18 def inception(json_schema, combinations) json_schema.each do |key, value| if (key == 'properties') && value && (json_schema['required'] != value.keys) schema = json_schema.dup one_of = schema.delete('required') || [] schema['properties'].each_key do |property| next if one_of.include?(property) next if property == 'type' || property == 'properties' combinations.push([schema.merge('required' => one_of + [property]), "required.#{property}"]) end elsif value.is_a?(Hash) com = inception(value, []) com.each do |combination| combination[0] = { key => value.merge(combination[0]) } combination[1] = "#{key}.#{combination[1]}" end combinations += com end end combinations end |