Class: DryOpenApi::Header

Inherits:
Object
  • Object
show all
Includes:
EquatableAsContent
Defined in:
lib/dry_open_api/header.rb

Overview

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EquatableAsContent

#==

Constructor Details

#initialize(description: nil, required: false, deprecated: nil, allow_empty_value: false, **other_fields_hash) ⇒ Header

Returns a new instance of Header.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/dry_open_api/header.rb', line 8

def initialize(description: nil, required: false, deprecated: nil, allow_empty_value: false, **other_fields_hash)
  self.description = description
  self.required = required
  self.deprecated = deprecated
  self.allow_empty_value = allow_empty_value
  self.other_fields_hash = other_fields_hash.with_indifferent_access

  other_fields_hash.keys.each do |field_name|
    define_singleton_method(field_name) do
      other_fields_hash[field_name]
    end
    define_singleton_method("#{field_name}=") do |value|
      other_fields_hash[field_name] = value
    end
  end
end

Instance Attribute Details

#allow_empty_valueObject

Returns the value of attribute allow_empty_value.



6
7
8
# File 'lib/dry_open_api/header.rb', line 6

def allow_empty_value
  @allow_empty_value
end

#deprecatedObject

Returns the value of attribute deprecated.



6
7
8
# File 'lib/dry_open_api/header.rb', line 6

def deprecated
  @deprecated
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/dry_open_api/header.rb', line 6

def description
  @description
end

#requiredObject

Returns the value of attribute required.



6
7
8
# File 'lib/dry_open_api/header.rb', line 6

def required
  @required
end

Class Method Details

.load(hash) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dry_open_api/header.rb', line 25

def self.load(hash)
  fixed_field_names = %i[description required deprecated allowEmptyValue]
  other_fields_hash = hash.reject { |key| key.to_sym.in?(fixed_field_names) }

  new(
    description: hash['description'],
    required: hash['required'].nil? ? false : hash['required'],
    deprecated: hash['deprecated'].nil? ? false : hash['deprecated'],
    allow_empty_value: hash['allowEmptyValue'].nil? ? false : hash['allowEmptyValue'],
    **other_fields_hash.symbolize_keys
  )
end