Sha256: 912bbcba8e07660e0eece89942149206d64cf41fbdf6791de7a3135e44eccd03
Contents?: true
Size: 1.07 KB
Versions: 7
Compression:
Stored size: 1.07 KB
Contents
module Fitting class Cover class JSONSchemaOneOf def initialize(json_schema) @json_schema = json_schema @combinations = [] end def combi inception(@json_schema, @combinations).each do |combination| combination[0] = @json_schema.merge(combination[0]) combination[1] = ['one_of', combination[1]] end end def inception(json_schema, combinations) json_schema.each do |key, value| if key == 'oneOf' schema = json_schema.dup one_of = schema.delete('oneOf') one_of.each_index do |index| combinations.push([schema.merge('oneOf' => [one_of[index]]), "oneOf.#{index}"]) 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 end end end
Version data entries
7 entries across 7 versions & 1 rubygems