Class: Modern::Descriptor::Parameters::Base

Inherits:
Struct
  • Object
show all
Defined in:
lib/modern/descriptor/parameters.rb

Direct Known Subclasses

Cookie, Header, Path, Query

Instance Method Summary collapse

Methods included from Struct::Copy

#copy

Instance Method Details

#do_retrieve(_request, _route_captures) ⇒ Object



41
42
43
# File 'lib/modern/descriptor/parameters.rb', line 41

def do_retrieve(_request, _route_captures)
  raise "#{self.class.name}#do_retrieve(request, route_captures) must be implemented."
end

#friendly_nameObject



19
20
21
# File 'lib/modern/descriptor/parameters.rb', line 19

def friendly_name
  name
end

#openapi3_inObject



37
38
39
# File 'lib/modern/descriptor/parameters.rb', line 37

def openapi3_in
  self.class.name.split("::").last.downcase
end

#retrieve(request, route_captures) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/modern/descriptor/parameters.rb', line 23

def retrieve(request, route_captures)
  ret = do_retrieve(request, route_captures)

  raise Errors::BadRequestError, "Invalid/missing parameter '#{friendly_name}'." \
    if required && ret.nil?

  begin
    ret.nil? ? nil : type[ret]
  rescue StandardError => _err
    raise Errors::InternalServiceError,
          "Couldn't interpret the value provided for parameter '#{friendly_name}': #{ret}."
  end
end

#to_openapi3(is_api_key = false) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/modern/descriptor/parameters.rb', line 45

def to_openapi3(is_api_key = false)
  {
    name: friendly_name,
    in: openapi3_in,
    required: !is_api_key ? required : nil,
    description: !is_api_key ? description : nil,
    deprecated: !is_api_key ? deprecated : nil
  }.compact
end