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
- #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 |
# File 'lib/openapi_parameters/parameter.rb', line 8 def initialize(definition) @definition = definition @name = definition['name'] @is_deep_object = style == 'deepObject' check_supported! end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
15 16 17 |
# File 'lib/openapi_parameters/parameter.rb', line 15 def definition @definition end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/openapi_parameters/parameter.rb', line 15 def name @name end |
Instance Method Details
#allow_reserved? ⇒ Boolean
70 71 72 |
# File 'lib/openapi_parameters/parameter.rb', line 70 def allow_reserved? definition['allowReserved'] == true end |
#array? ⇒ Boolean
46 47 48 |
# File 'lib/openapi_parameters/parameter.rb', line 46 def array? type == 'array' end |
#deep_object? ⇒ Boolean
17 18 19 |
# File 'lib/openapi_parameters/parameter.rb', line 17 def deep_object? @is_deep_object end |
#deprecated? ⇒ Boolean
66 67 68 |
# File 'lib/openapi_parameters/parameter.rb', line 66 def deprecated? definition['deprecated'] == true end |
#explode? ⇒ Boolean
74 75 76 77 78 79 |
# File 'lib/openapi_parameters/parameter.rb', line 74 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”.
22 23 24 |
# File 'lib/openapi_parameters/parameter.rb', line 22 def location definition['in'] end |
#media_type ⇒ Object
34 35 36 |
# File 'lib/openapi_parameters/parameter.rb', line 34 def media_type definition['content']&.keys&.first end |
#object? ⇒ Boolean
50 51 52 |
# File 'lib/openapi_parameters/parameter.rb', line 50 def object? type == 'object' || style == 'deepObject' || schema&.key?('properties') end |
#primitive? ⇒ Boolean
42 43 44 |
# File 'lib/openapi_parameters/parameter.rb', line 42 def primitive? type != 'object' && type != 'array' end |
#required? ⇒ Boolean
60 61 62 63 64 |
# File 'lib/openapi_parameters/parameter.rb', line 60 def required? return true if location == 'path' definition['required'] == true end |
#schema ⇒ Object
28 29 30 31 32 |
# File 'lib/openapi_parameters/parameter.rb', line 28 def schema return definition.dig('content', media_type, 'schema') if media_type definition['schema'] end |
#style ⇒ Object
54 55 56 57 58 |
# File 'lib/openapi_parameters/parameter.rb', line 54 def style return definition['style'] if definition['style'] DEFAULT_STYLE.fetch(location) end |
#type ⇒ Object
38 39 40 |
# File 'lib/openapi_parameters/parameter.rb', line 38 def type schema && schema['type'] end |