Class: OpenapiParameters::Parameter
- Inherits:
-
Object
- Object
- OpenapiParameters::Parameter
- Defined in:
- lib/openapi_parameters/parameter.rb
Overview
Represents a parameter in an OpenAPI operation.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #allow_reserved? ⇒ Boolean
- #array? ⇒ Boolean
- #bracket_array? ⇒ Boolean
- #convert(value) ⇒ Object
- #deep_object? ⇒ Boolean
- #deprecated? ⇒ Boolean
- #explode? ⇒ Boolean
-
#initialize(definition) ⇒ Parameter
constructor
A new instance of Parameter.
-
#location ⇒ String
(also: #in)
The location of the parameter in the request, “path”, “query”, “header” or “cookie”.
- #media_type ⇒ Object
- #object? ⇒ Boolean
- #primitive? ⇒ Boolean
- #required? ⇒ Boolean
- #schema ⇒ Object
- #style ⇒ Object
- #type ⇒ Object
- #unpack(value) ⇒ Object
Constructor Details
#initialize(definition) ⇒ Parameter
Returns a new instance of Parameter.
8 9 10 11 12 13 14 15 16 |
# File 'lib/openapi_parameters/parameter.rb', line 8 def initialize(definition) @definition = definition @name = definition['name'] @is_deep_object = style == 'deepObject' @converter = Converters[schema] check_supported! @unpacker = Unpackers.find(self) @bracket_array = (array? && @name&.end_with?(EMPTY_BRACKETS)) || false end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/openapi_parameters/parameter.rb', line 18 def name @name end |
Instance Method Details
#allow_reserved? ⇒ Boolean
91 92 93 |
# File 'lib/openapi_parameters/parameter.rb', line 91 def allow_reserved? definition['allowReserved'] == true end |
#array? ⇒ Boolean
60 61 62 |
# File 'lib/openapi_parameters/parameter.rb', line 60 def array? type == 'array' end |
#bracket_array? ⇒ Boolean
67 68 69 |
# File 'lib/openapi_parameters/parameter.rb', line 67 def bracket_array? @bracket_array end |
#convert(value) ⇒ Object
27 28 29 |
# File 'lib/openapi_parameters/parameter.rb', line 27 def convert(value) @converter.call(value) end |
#deep_object? ⇒ Boolean
31 32 33 |
# File 'lib/openapi_parameters/parameter.rb', line 31 def deep_object? @is_deep_object end |
#deprecated? ⇒ Boolean
87 88 89 |
# File 'lib/openapi_parameters/parameter.rb', line 87 def deprecated? definition['deprecated'] == true end |
#explode? ⇒ Boolean
95 96 97 98 99 100 |
# File 'lib/openapi_parameters/parameter.rb', line 95 def explode? return definition['explode'] if definition.key?('explode') return true if style == 'form' false end |
#location ⇒ String Also known as: in
Returns The location of the parameter in the request, “path”, “query”, “header” or “cookie”.
36 37 38 |
# File 'lib/openapi_parameters/parameter.rb', line 36 def location definition['in'] end |
#media_type ⇒ Object
48 49 50 |
# File 'lib/openapi_parameters/parameter.rb', line 48 def media_type definition['content']&.keys&.first end |
#object? ⇒ Boolean
71 72 73 |
# File 'lib/openapi_parameters/parameter.rb', line 71 def object? type == 'object' || style == 'deepObject' || schema&.key?('properties') end |
#primitive? ⇒ Boolean
56 57 58 |
# File 'lib/openapi_parameters/parameter.rb', line 56 def primitive? type != 'object' && type != 'array' end |
#required? ⇒ Boolean
81 82 83 84 85 |
# File 'lib/openapi_parameters/parameter.rb', line 81 def required? return true if location == 'path' definition['required'] == true end |
#schema ⇒ Object
42 43 44 45 46 |
# File 'lib/openapi_parameters/parameter.rb', line 42 def schema return definition.dig('content', media_type, 'schema') if media_type definition['schema'] end |
#style ⇒ Object
75 76 77 78 79 |
# File 'lib/openapi_parameters/parameter.rb', line 75 def style return definition['style'] if definition['style'] DEFAULT_STYLE.fetch(location) end |
#type ⇒ Object
52 53 54 |
# File 'lib/openapi_parameters/parameter.rb', line 52 def type schema && schema['type'] end |
#unpack(value) ⇒ Object
21 22 23 24 25 |
# File 'lib/openapi_parameters/parameter.rb', line 21 def unpack(value) return value if value.nil? unpacker.call(value) end |