Class: Mountapi::OpenApi::Operation

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#methodObject (readonly)

Returns the value of attribute method.



8
9
10
# File 'lib/mountapi/open_api/operation.rb', line 8

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/mountapi/open_api/operation.rb', line 8

def path
  @path
end

#specObject (readonly)

Returns the value of attribute spec.



8
9
10
# File 'lib/mountapi/open_api/operation.rb', line 8

def spec
  @spec
end

#versionObject (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

#parametersArray<String, Hash>

Returns the parameter name and it’s options.

Returns:

  • (Array<String, Hash>)

    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

#responsesArray<String, Hash>

Returns the response status code and it’s schema.

Returns:

  • (Array<String, Hash>)

    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_routeObject



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