Class: GrapeOAS::ApiModel::Operation

Inherits:
Node
  • Object
show all
Defined in:
lib/grape_oas/api_model/operation.rb

Overview

Represents an API operation (endpoint action) in the DTO model for OpenAPI v2/v3. Encapsulates HTTP method, parameters, request body, responses, tags, and security. Used as the core unit for both OpenAPIv2 and OpenAPIv3 operation objects.

Constant Summary

Constants inherited from Node

Node::BUCKET_NAMES

Instance Attribute Summary collapse

Attributes inherited from Node

#id

Instance Method Summary collapse

Methods inherited from Node

bucket, #ref

Constructor Details

#initialize(http_method:, operation_id: nil, summary: nil, description: nil, deprecated: false, parameters: [], request_body: nil, responses: [], tag_names: [], security: [], extensions: nil, consumes: [], produces: []) ⇒ Operation

Returns a new instance of Operation.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/grape_oas/api_model/operation.rb', line 17

def initialize(http_method:, operation_id: nil, summary: nil, description: nil,
               deprecated: false, parameters: [], request_body: nil,
               responses: [], tag_names: [], security: [], extensions: nil,
               consumes: [], produces: [])
  super()
  @http_method   = http_method.to_s.downcase
  @operation_id  = operation_id
  @summary       = summary
  @description   = description
  @deprecated    = deprecated
  @parameters    = Array(parameters)
  @request_body  = request_body
  @responses     = Array(responses)
  @tag_names     = Array(tag_names)
  @security      = Array(security)
  @extensions    = extensions
  @consumes      = Array(consumes)
  @produces      = Array(produces)
  @suppress_default_error_response = false
end

Instance Attribute Details

#consumesObject

Returns the value of attribute consumes.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def consumes
  @consumes
end

#deprecatedObject

Returns the value of attribute deprecated.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def deprecated
  @deprecated
end

#descriptionObject

Returns the value of attribute description.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def description
  @description
end

#extensionsObject

Returns the value of attribute extensions.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def extensions
  @extensions
end

#http_methodObject

Returns the value of attribute http_method.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def http_method
  @http_method
end

#operation_idObject

Returns the value of attribute operation_id.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def operation_id
  @operation_id
end

#parametersObject

Returns the value of attribute parameters.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def parameters
  @parameters
end

#producesObject

Returns the value of attribute produces.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def produces
  @produces
end

#request_bodyObject

Returns the value of attribute request_body.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def request_body
  @request_body
end

#responsesObject

Returns the value of attribute responses.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def responses
  @responses
end

#securityObject

Returns the value of attribute security.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def security
  @security
end

#summaryObject

Returns the value of attribute summary.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def summary
  @summary
end

#suppress_default_error_responseObject

Returns the value of attribute suppress_default_error_response.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def suppress_default_error_response
  @suppress_default_error_response
end

#tag_namesObject

Returns the value of attribute tag_names.



12
13
14
# File 'lib/grape_oas/api_model/operation.rb', line 12

def tag_names
  @tag_names
end

Instance Method Details

#add_parameter(parameter) ⇒ Object



38
39
40
# File 'lib/grape_oas/api_model/operation.rb', line 38

def add_parameter(parameter)
  @parameters << parameter
end

#add_parameters(*parameters) ⇒ Object



42
43
44
# File 'lib/grape_oas/api_model/operation.rb', line 42

def add_parameters(*parameters)
  @parameters.concat(parameters)
end

#add_response(response) ⇒ Object



46
47
48
# File 'lib/grape_oas/api_model/operation.rb', line 46

def add_response(response)
  @responses << response
end

#response(code) ⇒ Object



50
51
52
# File 'lib/grape_oas/api_model/operation.rb', line 50

def response(code)
  @responses.find { |r| r.http_status == code.to_s }
end