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
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #allow_reserved? ⇒ Boolean
- #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
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
16 17 18 |
# File 'lib/openapi_parameters/parameter.rb', line 16 def definition @definition end |
#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
75 76 77 |
# File 'lib/openapi_parameters/parameter.rb', line 75 def allow_reserved? definition['allowReserved'] == true end |
#array? ⇒ Boolean
51 52 53 |
# File 'lib/openapi_parameters/parameter.rb', line 51 def array? type == 'array' end |
#convert(value) ⇒ Object
18 19 20 |
# File 'lib/openapi_parameters/parameter.rb', line 18 def convert(value) @converter.call(value) end |
#deep_object? ⇒ Boolean
22 23 24 |
# File 'lib/openapi_parameters/parameter.rb', line 22 def deep_object? @is_deep_object end |
#deprecated? ⇒ Boolean
71 72 73 |
# File 'lib/openapi_parameters/parameter.rb', line 71 def deprecated? definition['deprecated'] == true end |
#explode? ⇒ Boolean
79 80 81 82 83 84 |
# File 'lib/openapi_parameters/parameter.rb', line 79 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”.
27 28 29 |
# File 'lib/openapi_parameters/parameter.rb', line 27 def location definition['in'] end |
#media_type ⇒ Object
39 40 41 |
# File 'lib/openapi_parameters/parameter.rb', line 39 def media_type definition['content']&.keys&.first end |
#object? ⇒ Boolean
55 56 57 |
# File 'lib/openapi_parameters/parameter.rb', line 55 def object? type == 'object' || style == 'deepObject' || schema&.key?('properties') end |
#primitive? ⇒ Boolean
47 48 49 |
# File 'lib/openapi_parameters/parameter.rb', line 47 def primitive? type != 'object' && type != 'array' end |
#required? ⇒ Boolean
65 66 67 68 69 |
# File 'lib/openapi_parameters/parameter.rb', line 65 def required? return true if location == 'path' definition['required'] == true end |
#schema ⇒ Object
33 34 35 36 37 |
# File 'lib/openapi_parameters/parameter.rb', line 33 def schema return definition.dig('content', media_type, 'schema') if media_type definition['schema'] end |
#style ⇒ Object
59 60 61 62 63 |
# File 'lib/openapi_parameters/parameter.rb', line 59 def style return definition['style'] if definition['style'] DEFAULT_STYLE.fetch(location) end |
#type ⇒ Object
43 44 45 |
# File 'lib/openapi_parameters/parameter.rb', line 43 def type schema && schema['type'] end |