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
Constructor Details
#initialize(definition) ⇒ Parameter
Returns a new instance of Parameter.
8 9 10 11 12 13 14 |
# 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! end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/openapi_parameters/parameter.rb', line 16 def name @name end |
Instance Method Details
#allow_reserved? ⇒ Boolean
83 84 85 |
# File 'lib/openapi_parameters/parameter.rb', line 83 def allow_reserved? definition['allowReserved'] == true end |
#array? ⇒ Boolean
52 53 54 |
# File 'lib/openapi_parameters/parameter.rb', line 52 def array? type == 'array' end |
#bracket_array? ⇒ Boolean
59 60 61 |
# File 'lib/openapi_parameters/parameter.rb', line 59 def bracket_array? @bracket_array ||= array? && name.end_with?(EMPTY_BRACKETS) end |
#convert(value) ⇒ Object
19 20 21 |
# File 'lib/openapi_parameters/parameter.rb', line 19 def convert(value) @converter.call(value) end |
#deep_object? ⇒ Boolean
23 24 25 |
# File 'lib/openapi_parameters/parameter.rb', line 23 def deep_object? @is_deep_object end |
#deprecated? ⇒ Boolean
79 80 81 |
# File 'lib/openapi_parameters/parameter.rb', line 79 def deprecated? definition['deprecated'] == true end |
#explode? ⇒ Boolean
87 88 89 90 91 92 |
# File 'lib/openapi_parameters/parameter.rb', line 87 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”.
28 29 30 |
# File 'lib/openapi_parameters/parameter.rb', line 28 def location definition['in'] end |
#media_type ⇒ Object
40 41 42 |
# File 'lib/openapi_parameters/parameter.rb', line 40 def media_type definition['content']&.keys&.first end |
#object? ⇒ Boolean
63 64 65 |
# File 'lib/openapi_parameters/parameter.rb', line 63 def object? type == 'object' || style == 'deepObject' || schema&.key?('properties') end |
#primitive? ⇒ Boolean
48 49 50 |
# File 'lib/openapi_parameters/parameter.rb', line 48 def primitive? type != 'object' && type != 'array' end |
#required? ⇒ Boolean
73 74 75 76 77 |
# File 'lib/openapi_parameters/parameter.rb', line 73 def required? return true if location == 'path' definition['required'] == true end |
#schema ⇒ Object
34 35 36 37 38 |
# File 'lib/openapi_parameters/parameter.rb', line 34 def schema return definition.dig('content', media_type, 'schema') if media_type definition['schema'] end |
#style ⇒ Object
67 68 69 70 71 |
# File 'lib/openapi_parameters/parameter.rb', line 67 def style return definition['style'] if definition['style'] DEFAULT_STYLE.fetch(location) end |
#type ⇒ Object
44 45 46 |
# File 'lib/openapi_parameters/parameter.rb', line 44 def type schema && schema['type'] end |