class OpenApi::Parameter

github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#parameterObject

Attributes

allow_empty_value[RW]
deprecated[RW]
description[RW]
in[RW]
name[RW]
other_fields_hash[RW]
required[RW]

Public Class Methods

load(hash) click to toggle source
# File lib/open_api/parameter.rb, line 26
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
new(name:, in:, description: nil, required: nil, deprecated: nil, allow_empty_value: nil, **other_fields_hash) click to toggle source
# File lib/open_api/parameter.rb, line 8
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

Public Instance Methods

serializable_hash() click to toggle source
# File lib/open_api/parameter.rb, line 48
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