Class: Mountapi::OpenApi::Operation
- Inherits:
-
Object
- Object
- Mountapi::OpenApi::Operation
- Defined in:
- lib/mountapi/open_api/operation.rb
Constant Summary collapse
- METHODS =
%w[get post put patch delete options trace head].freeze
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#spec ⇒ Object
readonly
Returns the value of attribute spec.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
-
#initialize(method, spec, path, version) ⇒ Operation
constructor
A new instance of Operation.
-
#parameters ⇒ Array<String, Hash>
The parameter name and it’s options.
-
#responses ⇒ Array<String, Hash>
The response status code and it’s schema.
- #to_route ⇒ Object
Constructor Details
#initialize(method, spec, path, version) ⇒ Operation
Returns a new instance of Operation.
9 10 11 12 13 14 |
# File 'lib/mountapi/open_api/operation.rb', line 9 def initialize(method, spec, path, version) @path = path @method = method @version = version @spec = spec end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
8 9 10 |
# File 'lib/mountapi/open_api/operation.rb', line 8 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/mountapi/open_api/operation.rb', line 8 def path @path end |
#spec ⇒ Object (readonly)
Returns the value of attribute spec.
8 9 10 |
# File 'lib/mountapi/open_api/operation.rb', line 8 def spec @spec end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
8 9 10 |
# File 'lib/mountapi/open_api/operation.rb', line 8 def version @version end |
Instance Method Details
#parameters ⇒ Array<String, Hash>
Returns the parameter name and it’s options.
31 32 33 |
# File 'lib/mountapi/open_api/operation.rb', line 31 def parameters http_params.concat(body_params) end |
#responses ⇒ Array<String, Hash>
Returns the response status code and it’s schema.
36 37 38 39 40 |
# File 'lib/mountapi/open_api/operation.rb', line 36 def responses spec.node.responses.inject([]) do |responses, (code, response)| responses << [code, response.content["application/json"]&.schema] end end |
#to_route ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mountapi/open_api/operation.rb', line 16 def to_route operation_id = spec.node.operation_id Route.build( path: path, method: method, handler: Mountapi.handlers[operation_id], parameters: parameters, responses: responses, version: version, operation_id: operation_id ) end |