Sha256: b4498b520c5db1a32d2cfcc2f5ae705ca6525053495b767013bccd7a790ff41f

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

module Fitting
  class Cover
    class JSONSchemaEnum
      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] = ['enum', combination[1]]
        end
      end

      def inception(json_schema, combinations)
        json_schema.each do |key, value|
          if key == 'enum' && value.size > 1
            schema = json_schema.dup
            one_of = schema.delete('enum')
            one_of.each_index do |index|
              combinations.push([schema.merge('enum' => [one_of[index]]), "enum.#{one_of[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

Version Path
fitting-2.17.0 lib/fitting/cover/json_schema_enum.rb
fitting-2.16.1 lib/fitting/cover/json_schema_enum.rb
fitting-2.16.0 lib/fitting/cover/json_schema_enum.rb
fitting-2.15.0 lib/fitting/cover/json_schema_enum.rb
fitting-2.14.1 lib/fitting/cover/json_schema_enum.rb
fitting-2.14.0 lib/fitting/cover/json_schema_enum.rb
fitting-2.13.1 lib/fitting/cover/json_schema_enum.rb