Class: GrapeOAS::ApiModel::Operation
- 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
Instance Attribute Summary collapse
-
#consumes ⇒ Object
Returns the value of attribute consumes.
-
#deprecated ⇒ Object
Returns the value of attribute deprecated.
-
#description ⇒ Object
Returns the value of attribute description.
-
#extensions ⇒ Object
Returns the value of attribute extensions.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#operation_id ⇒ Object
Returns the value of attribute operation_id.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#produces ⇒ Object
Returns the value of attribute produces.
-
#request_body ⇒ Object
Returns the value of attribute request_body.
-
#responses ⇒ Object
Returns the value of attribute responses.
-
#security ⇒ Object
Returns the value of attribute security.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#suppress_default_error_response ⇒ Object
Returns the value of attribute suppress_default_error_response.
-
#tag_names ⇒ Object
Returns the value of attribute tag_names.
Attributes inherited from Node
Instance Method Summary collapse
- #add_parameter(parameter) ⇒ Object
- #add_parameters(*parameters) ⇒ Object
- #add_response(response) ⇒ Object
-
#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
constructor
A new instance of Operation.
- #response(code) ⇒ Object
Methods inherited from Node
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
#consumes ⇒ Object
Returns the value of attribute consumes.
12 13 14 |
# File 'lib/grape_oas/api_model/operation.rb', line 12 def consumes @consumes end |
#deprecated ⇒ Object
Returns the value of attribute deprecated.
12 13 14 |
# File 'lib/grape_oas/api_model/operation.rb', line 12 def deprecated @deprecated end |
#description ⇒ Object
Returns the value of attribute description.
12 13 14 |
# File 'lib/grape_oas/api_model/operation.rb', line 12 def description @description end |
#extensions ⇒ Object
Returns the value of attribute extensions.
12 13 14 |
# File 'lib/grape_oas/api_model/operation.rb', line 12 def extensions @extensions end |
#http_method ⇒ Object
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_id ⇒ Object
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 |
#parameters ⇒ Object
Returns the value of attribute parameters.
12 13 14 |
# File 'lib/grape_oas/api_model/operation.rb', line 12 def parameters @parameters end |
#produces ⇒ Object
Returns the value of attribute produces.
12 13 14 |
# File 'lib/grape_oas/api_model/operation.rb', line 12 def produces @produces end |
#request_body ⇒ Object
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 |
#responses ⇒ Object
Returns the value of attribute responses.
12 13 14 |
# File 'lib/grape_oas/api_model/operation.rb', line 12 def responses @responses end |
#security ⇒ Object
Returns the value of attribute security.
12 13 14 |
# File 'lib/grape_oas/api_model/operation.rb', line 12 def security @security end |
#summary ⇒ Object
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_response ⇒ Object
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_names ⇒ Object
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 |