Class: Jsapi::Meta::Operation
Instance Method Summary collapse
-
#add_parameter(name, keywords = {}) ⇒ Object
:nodoc:.
-
#callbacks ⇒ Object
:attr: callbacks The optional callbacks.
-
#consumed_mime_types ⇒ Object
(also: #consumes)
:attr: consumed_mime_types The MIME types consumed by the operation.
-
#deprecated ⇒ Object
:attr: deprecated Specifies whether or not the operation is deprecated.
-
#description ⇒ Object
:attr: description The optional description of the operation.
-
#external_docs ⇒ Object
:attr: external_docs The optional OpenAPI::ExternalDocumentation object.
-
#initialize(name = nil, keywords = {}) ⇒ Operation
constructor
A new instance of Operation.
-
#method ⇒ Object
:attr: method The HTTP verb of the operation.
-
#model ⇒ Object
:attr: model The model class to access top-level parameters by.
-
#name ⇒ Object
:attr_reader: name The name of the operation.
-
#parameters ⇒ Object
:attr: parameters The parameters of the operation.
-
#path ⇒ Object
:attr: path The relative path of the operation.
-
#produced_mime_types ⇒ Object
(also: #produces)
:attr: consumed_mime_types The MIME types produced by the operation.
-
#request_body ⇒ Object
:attr: request_body The optional request body of the operation.
-
#responses ⇒ Object
:attr: responses The responses of the operation.
-
#schemes ⇒ Object
:attr: schemes The transfer protocols supported by the operation.
-
#security_requirements ⇒ Object
:attr: security_requirements The OpenAPI::SecurityRequirement objects.
-
#servers ⇒ Object
:attr: servers The OpenAPI::Server objects.
-
#summary ⇒ Object
:attr: summary The optional summary of the operation.
-
#tags ⇒ Object
:attr: tags The tags used to group operations in an OpenAPI document.
-
#to_openapi(version, definitions) ⇒ Object
Returns a hash representing the OpenAPI operation object.
Methods inherited from Base
#inspect, #reference?, #resolve
Methods included from Attributes::ClassMethods
Constructor Details
#initialize(name = nil, keywords = {}) ⇒ Operation
Returns a new instance of Operation.
133 134 135 136 |
# File 'lib/jsapi/meta/operation.rb', line 133 def initialize(name = nil, keywords = {}) @name = name&.to_s super(keywords) end |
Instance Method Details
#add_parameter(name, keywords = {}) ⇒ Object
:nodoc:
138 139 140 |
# File 'lib/jsapi/meta/operation.rb', line 138 def add_parameter(name, keywords = {}) # :nodoc: (@parameters ||= {})[name.to_s] = Parameter.new(name, keywords) end |
#callbacks ⇒ Object
:attr: callbacks The optional callbacks. Applies to OpenAPI 3.x.
9 |
# File 'lib/jsapi/meta/operation.rb', line 9 attribute :callbacks, { String => OpenAPI::Callback } |
#consumed_mime_types ⇒ Object Also known as: consumes
:attr: consumed_mime_types The MIME types consumed by the operation. Applies to OpenAPI 2.0 only.
15 |
# File 'lib/jsapi/meta/operation.rb', line 15 attribute :consumed_mime_types, [String] |
#deprecated ⇒ Object
:attr: deprecated Specifies whether or not the operation is deprecated.
24 |
# File 'lib/jsapi/meta/operation.rb', line 24 attribute :deprecated, values: [true, false] |
#description ⇒ Object
:attr: description The optional description of the operation.
29 |
# File 'lib/jsapi/meta/operation.rb', line 29 attribute :description, String |
#external_docs ⇒ Object
:attr: external_docs The optional OpenAPI::ExternalDocumentation object.
34 |
# File 'lib/jsapi/meta/operation.rb', line 34 attribute :external_docs, OpenAPI::ExternalDocumentation |
#method ⇒ Object
:attr: method The HTTP verb of the operation. Possible values are:
-
"delete"
-
"get"
-
"head"
-
"options"
-
"patch"
-
"post"
-
"put"
The default HTTP verb is "get"
.
49 50 51 |
# File 'lib/jsapi/meta/operation.rb', line 49 attribute :method, values: %w[delete get head options patch post put], default: 'get' |
#model ⇒ Object
:attr: model The model class to access top-level parameters by. The default model class is Model::Base.
57 |
# File 'lib/jsapi/meta/operation.rb', line 57 attribute :model, Class, default: Model::Base |
#name ⇒ Object
:attr_reader: name The name of the operation.
62 |
# File 'lib/jsapi/meta/operation.rb', line 62 attribute :name, writer: false |
#parameters ⇒ Object
:attr: parameters The parameters of the operation.
67 68 69 |
# File 'lib/jsapi/meta/operation.rb', line 67 attribute :parameters, { String => Parameter }, default: {}, writer: false |
#path ⇒ Object
:attr: path The relative path of the operation.
74 |
# File 'lib/jsapi/meta/operation.rb', line 74 attribute :path, String |
#produced_mime_types ⇒ Object Also known as: produces
:attr: consumed_mime_types The MIME types produced by the operation. Applies to OpenAPI 2.0 only.
80 |
# File 'lib/jsapi/meta/operation.rb', line 80 attribute :produced_mime_types, [String] |
#request_body ⇒ Object
:attr: request_body The optional request body of the operation.
89 |
# File 'lib/jsapi/meta/operation.rb', line 89 attribute :request_body, RequestBody |
#responses ⇒ Object
:attr: responses The responses of the operation.
94 95 96 |
# File 'lib/jsapi/meta/operation.rb', line 94 attribute :responses, { String => Response }, default: {}, default_key: 'default' |
#schemes ⇒ Object
:attr: schemes The transfer protocols supported by the operation. Possible values are:
-
"http"
-
"https"
-
"ws"
-
"wss"
Applies to OpenAPI 2.0 only.
109 |
# File 'lib/jsapi/meta/operation.rb', line 109 attribute :schemes, [String], values: %w[http https ws wss] |
#security_requirements ⇒ Object
:attr: security_requirements The OpenAPI::SecurityRequirement objects.
114 |
# File 'lib/jsapi/meta/operation.rb', line 114 attribute :security_requirements, [OpenAPI::SecurityRequirement] |
#servers ⇒ Object
:attr: servers The OpenAPI::Server objects. Applies to OpenAPI 3.x.
121 |
# File 'lib/jsapi/meta/operation.rb', line 121 attribute :servers, [OpenAPI::Server] |
#summary ⇒ Object
:attr: summary The optional summary of the operation.
126 |
# File 'lib/jsapi/meta/operation.rb', line 126 attribute :summary, String |
#tags ⇒ Object
:attr: tags The tags used to group operations in an OpenAPI document.
131 |
# File 'lib/jsapi/meta/operation.rb', line 131 attribute :tags, [String] |
#to_openapi(version, definitions) ⇒ Object
Returns a hash representing the OpenAPI operation object.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/jsapi/meta/operation.rb', line 143 def to_openapi(version, definitions) version = OpenAPI::Version.from(version) { operationId: name, tags: , summary: summary, description: description, externalDocs: external_docs&.to_openapi, deprecated: deprecated?.presence, security: security_requirements&.map(&:to_openapi) }.tap do |hash| if version.major == 2 hash[:consumes] = consumed_mime_types if consumed_mime_types hash[:produces] = produced_mime_types if produced_mime_types hash[:schemes] = schemes if schemes elsif servers hash[:servers] = servers.map(&:to_openapi) end # Parameters (and request body) hash[:parameters] = parameters.values.flat_map do |parameter| parameter.to_openapi(version, definitions) end if request_body if version.major == 2 hash[:parameters] << request_body.resolve(definitions).to_openapi_parameter else hash[:request_body] = request_body.to_openapi(version) end end # Responses hash[:responses] = responses.transform_values do |response| response.to_openapi(version, definitions) end # Callbacks if callbacks && version.major > 2 hash[:callbacks] = callbacks.transform_values do |callback| callback.to_openapi(version, definitions) end end end.compact end |