Sha256: 45923fdd8b783ac8a2c4b4aaa708852463db9023c04809c61737fffa907a8692

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 KB

Contents

module Fitting
  class Cover
    class JSONSchemaOneOf
      attr_reader :json_schema, :combinations

      def initialize(json_schema)
        @json_schema = json_schema
        @combinations = []
      end

      def combi
        inception(json_schema, combinations).each do |combination|
          combination[0] = 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|
              schema_new = json_schema.dup
              schema_new.delete('oneOf')
              combinations.push([schema_new.merge(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

8 entries across 8 versions & 1 rubygems

Version Path
fitting-4.2.1 lib/fitting/cover/json_schema_one_of.rb
fitting-4.2.0 lib/fitting/cover/json_schema_one_of.rb
fitting-4.1.0 lib/fitting/cover/json_schema_one_of.rb
fitting-4.0.4 lib/fitting/cover/json_schema_one_of.rb
fitting-4.0.3 lib/fitting/cover/json_schema_one_of.rb
fitting-4.0.2 lib/fitting/cover/json_schema_one_of.rb
fitting-4.0.1 lib/fitting/cover/json_schema_one_of.rb
fitting-4.0.0 lib/fitting/cover/json_schema_one_of.rb