Sha256: 65c3525e1a3ab23370969a3bbc281670ee3605c5faeb7773d5e9023f20fdd556

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module WeakSwaggerParameters
  module Definitions
    class ArrayProperty
      include WeakSwaggerParameters::Definitions::PropertyContainer

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

        instance_eval(&block) if block.present?
      end

      def apply_validations(parent_node)
        name = @name

        parent_node.instance_eval do
          array name
        end
      end

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

        parent_node.instance_eval do
          schema_node = Swagger::Blocks::SchemaNode.call(version: version, inline_keys: nil)
          definitions.each { |definition| definition.apply_docs(schema_node) }

          property name, description: description, type: :array do
            items do
              if definitions.any?
                key :type, :object
                key :properties, schema_node.as_json[:properties]
              else
                key :type, item_type
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
weak_swagger_parameters-0.6.0 lib/weak_swagger_parameters/definitions/array_property.rb