Class: Jsapi::Meta::Parameter::Base
- Inherits:
-
Model::Base
- Object
- Model::Base
- Jsapi::Meta::Parameter::Base
- Includes:
- OpenAPI::Extensions
- Defined in:
- lib/jsapi/meta/parameter/base.rb
Overview
Specifies a parameter.
Constant Summary
Constants included from Model::Attributes
Model::Attributes::DEFAULT_ARRAY, Model::Attributes::DEFAULT_HASH
Instance Method Summary collapse
-
#allow_empty_value? ⇒ Boolean
Returns true if empty values are allowed as specified by OpenAPI, false otherwise.
-
#deprecated ⇒ Object
:attr: deprecated Specifies whether or not the parameter is deprecated.
-
#description ⇒ Object
:attr: description The description of the parameter.
-
#examples ⇒ Object
:attr_reader: examples The examples.
-
#in ⇒ Object
:attr: in The location of the parameter.
-
#initialize(name, keywords = {}) ⇒ Base
constructor
Creates a new parameter.
-
#name ⇒ Object
:attr_reader: name The name of the parameter.
-
#required? ⇒ Boolean
Returns true if it is required as specified by JSON Schema, false otherwise.
-
#schema ⇒ Object
:attr_reader: schema The Schema of the parameter.
-
#to_openapi(version, definitions) ⇒ Object
Returns a hash representing the OpenAPI parameter object.
-
#to_openapi_parameters(version, definitions) ⇒ Object
Returns an array of hashes representing the OpenAPI parameter objects.
Methods included from OpenAPI::Extensions
Methods inherited from Model::Base
#inspect, #merge!, #reference?, #resolve
Methods included from Model::Attributes
Constructor Details
#initialize(name, keywords = {}) ⇒ Base
Creates a new parameter.
Raises an ArgumentError if name is blank.
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/jsapi/meta/parameter/base.rb', line 51 def initialize(name, keywords = {}) raise ArgumentError, "parameter name can't be blank" if name.blank? @name = name.to_s keywords = keywords.dup super(keywords.extract!(:deprecated, :description, :examples, :in, :openapi_extensions)) add_example(value: keywords.delete(:example)) if keywords.key?(:example) keywords[:ref] = keywords.delete(:schema) if keywords.key?(:schema) @schema = Schema.new(keywords) end |
Instance Method Details
#allow_empty_value? ⇒ Boolean
Returns true if empty values are allowed as specified by OpenAPI, false otherwise.
66 67 68 |
# File 'lib/jsapi/meta/parameter/base.rb', line 66 def allow_empty_value? schema.existence <= Existence::ALLOW_EMPTY && self.in == 'query' end |
#deprecated ⇒ Object
:attr: deprecated Specifies whether or not the parameter is deprecated.
15 |
# File 'lib/jsapi/meta/parameter/base.rb', line 15 attribute :deprecated, values: [true, false] |
#description ⇒ Object
:attr: description The description of the parameter.
20 |
# File 'lib/jsapi/meta/parameter/base.rb', line 20 attribute :description, String |
#examples ⇒ Object
:attr_reader: examples The examples.
25 |
# File 'lib/jsapi/meta/parameter/base.rb', line 25 attribute :examples, { String => Example }, default_key: 'default' |
#in ⇒ Object
:attr: in The location of the parameter. Possible values are:
-
"header" -
"path" -
"query"
The default location is "query".
36 |
# File 'lib/jsapi/meta/parameter/base.rb', line 36 attribute :in, String, values: %w[header path query], default: 'query' |
#name ⇒ Object
:attr_reader: name The name of the parameter.
41 |
# File 'lib/jsapi/meta/parameter/base.rb', line 41 attribute :name, accessors: %i[reader] |
#required? ⇒ Boolean
Returns true if it is required as specified by JSON Schema, false otherwise.
71 72 73 |
# File 'lib/jsapi/meta/parameter/base.rb', line 71 def required? schema.existence > Existence::ALLOW_OMITTED || self.in == 'path' end |
#schema ⇒ Object
:attr_reader: schema The Schema of the parameter.
46 |
# File 'lib/jsapi/meta/parameter/base.rb', line 46 attribute :schema, accessors: %i[reader] |
#to_openapi(version, definitions) ⇒ Object
Returns a hash representing the OpenAPI parameter object.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/jsapi/meta/parameter/base.rb', line 76 def to_openapi(version, definitions) version = OpenAPI::Version.from(version) schema = self.schema.resolve(definitions) openapi_parameter( name, schema, version, description: description, required: required?, deprecated: deprecated?, allow_empty_value: allow_empty_value?, examples: examples ) end |
#to_openapi_parameters(version, definitions) ⇒ Object
Returns an array of hashes representing the OpenAPI parameter objects.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/jsapi/meta/parameter/base.rb', line 93 def to_openapi_parameters(version, definitions) version = OpenAPI::Version.from(version) schema = self.schema.resolve(definitions) if schema.object? explode_parameter( name, schema, version, definitions, required: required?, deprecated: deprecated? ) else [ openapi_parameter( name, schema, version, description: description, required: required?, deprecated: deprecated?, allow_empty_value: allow_empty_value?, examples: examples ) ] end end |