Sha256: 89c83ea3a6fde1e6f0a5a734b4782d96663b9895865c77796b2d3e17c01d9684

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module WeakSwaggerParameters
  module Definitions
    class HashProperty
      include WeakSwaggerParameters::Definitions::PropertyContainer

      def initialize(name, description, &block)
        @name = name
        @description = description

        instance_eval(&block) if block.present?
      end

      def apply_validations(parent_node)
        name = @name
        param_definitions = child_definitions

        parent_node.instance_eval do
          hash name, strong: true do
            param_definitions.each { |definition| definition.apply_validations(parent_node) }
          end
        end
      end

      def apply_docs(parent_node)
        name = @name
        description = @description
        definitions = child_definitions

        parent_node.instance_eval do
          property name, description: description, type: :object do
            hash_node = self
            definitions.each { |definition| definition.apply_docs(hash_node) }
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
weak_swagger_parameters-0.6.0 lib/weak_swagger_parameters/definitions/hash_property.rb
weak_swagger_parameters-0.5.0 lib/weak_swagger_parameters/definitions/hash_property.rb