Sha256: 25fbaaec2eefecca41f1aa6d72a79c25fd8525d55485794e61839b1c015bee6d

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

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

      def inception(json_schema, combinations)
        json_schema.each do |key, value|
          if (key == 'properties') && (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)

              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
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fitting-2.18.3 lib/fitting/cover/json_schema.rb
fitting-2.18.2 lib/fitting/cover/json_schema.rb
fitting-2.18.1 lib/fitting/cover/json_schema.rb
fitting-2.18.0 lib/fitting/cover/json_schema.rb