Class: WeakSwaggerParameters::Definitions::ArrayProperty

Inherits:
Object
  • Object
show all
Includes:
PropertyContainer
Defined in:
lib/weak_swagger_parameters/definitions/array_property.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, description, item_type, &block) ⇒ ArrayProperty

Returns a new instance of ArrayProperty.



8
9
10
11
12
13
14
# File 'lib/weak_swagger_parameters/definitions/array_property.rb', line 8

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

  instance_eval(&block) if block.present?
end

Instance Method Details

#apply_docs(parent_node) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/weak_swagger_parameters/definitions/array_property.rb', line 24

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

#apply_validations(parent_node) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/weak_swagger_parameters/definitions/array_property.rb', line 16

def apply_validations(parent_node)
  name = @name

  parent_node.instance_eval do
    array name
  end
end