Class: DryOpenApi::Parameter
- Inherits:
-
Object
- Object
- DryOpenApi::Parameter
- Includes:
- EquatableAsContent
- Defined in:
- lib/dry_open_api/parameter.rb
Overview
Instance Attribute Summary collapse
-
#allow_empty_value ⇒ Object
Returns the value of attribute allow_empty_value.
-
#deprecated ⇒ Object
Returns the value of attribute deprecated.
-
#description ⇒ Object
Returns the value of attribute description.
-
#in ⇒ Object
Returns the value of attribute in.
-
#name ⇒ Object
Returns the value of attribute name.
-
#required ⇒ Object
Returns the value of attribute required.
Class Method Summary collapse
-
.load(hash) ⇒ Object
rubocop:enable Metrics/MethodLength, Metrics/ParameterLists.
Instance Method Summary collapse
-
#initialize(name:, in:, description: nil, required: nil, deprecated: nil, allow_empty_value: nil, **other_fields_hash) ⇒ Parameter
constructor
rubocop:disable Metrics/MethodLength, Metrics/ParameterLists.
- #serializable_hash ⇒ Object
Methods included from EquatableAsContent
Constructor Details
#initialize(name:, in:, description: nil, required: nil, deprecated: nil, allow_empty_value: nil, **other_fields_hash) ⇒ Parameter
rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dry_open_api/parameter.rb', line 9 def initialize(name:, in:, description: nil, required: nil, deprecated: nil, allow_empty_value: nil, **other_fields_hash) self.name = name self.in = binding.local_variable_get(:in) # `in` is reserved keyword 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 |key| define_singleton_method(key) do other_fields_hash[key] end define_singleton_method("#{key}=") do |value| other_fields_hash[key] = value end end end |
Instance Attribute Details
#allow_empty_value ⇒ Object
Returns the value of attribute allow_empty_value.
6 7 8 |
# File 'lib/dry_open_api/parameter.rb', line 6 def allow_empty_value @allow_empty_value end |
#deprecated ⇒ Object
Returns the value of attribute deprecated.
6 7 8 |
# File 'lib/dry_open_api/parameter.rb', line 6 def deprecated @deprecated end |
#description ⇒ Object
Returns the value of attribute description.
6 7 8 |
# File 'lib/dry_open_api/parameter.rb', line 6 def description @description end |
#in ⇒ Object
Returns the value of attribute in.
6 7 8 |
# File 'lib/dry_open_api/parameter.rb', line 6 def in @in end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/dry_open_api/parameter.rb', line 6 def name @name end |
#required ⇒ Object
Returns the value of attribute required.
6 7 8 |
# File 'lib/dry_open_api/parameter.rb', line 6 def required @required end |
Class Method Details
.load(hash) ⇒ Object
rubocop:enable Metrics/MethodLength, Metrics/ParameterLists
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dry_open_api/parameter.rb', line 28 def self.load(hash) other_fields_hash = hash.reject { |key| key.to_sym.in?([:name, :in, :description, :required, :deprecated, :allow_empty_value]) }.symbolize_keys.map { |k, v| value = case k when :schema then Schema.load(v) end [k, value] }.to_h new( name: hash['name'].to_s, in: hash['in'].to_s, description: hash['description']&.to_s, required: hash['required'], deprecated: hash['deprecated'], allow_empty_value: hash['allowEmptyValue'], **other_fields_hash ) end |
Instance Method Details
#serializable_hash ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dry_open_api/parameter.rb', line 50 def serializable_hash { 'name' => name.to_s, 'in' => self.in.to_s, 'required' => required, 'deprecated' => deprecated, 'allow_empty_value' => allow_empty_value }.merge( other_fields_hash.map { |k, v| [k.to_s, v.serializable_hash] }.to_h ).compact end |