Class: LambdaOpenApi::Action
- Inherits:
-
Object
- Object
- LambdaOpenApi::Action
- Defined in:
- lib/lambda_open_api/action.rb
Constant Summary collapse
- PARAMATER_EXPRESION =
/[:\{](\w+)\}?/
Instance Attribute Summary collapse
-
#code ⇒ Object
Returns the value of attribute code.
-
#description ⇒ Object
Returns the value of attribute description.
-
#http_verb ⇒ Object
Returns the value of attribute http_verb.
-
#method ⇒ Object
Returns the value of attribute method.
-
#name ⇒ Object
Returns the value of attribute name.
-
#param ⇒ Object
Returns the value of attribute param.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#path_name ⇒ Object
Returns the value of attribute path_name.
-
#responses ⇒ Object
Returns the value of attribute responses.
-
#summery ⇒ Object
Returns the value of attribute summery.
Instance Method Summary collapse
- #action_json ⇒ Object
-
#initialize(name:, http_verb:, path_name:) ⇒ Action
constructor
A new instance of Action.
- #interpolate_path_paramater ⇒ Object
- #set_request_body(data) ⇒ Object
- #set_response(data) ⇒ Object
- #titleize(string) ⇒ Object
Constructor Details
#initialize(name:, http_verb:, path_name:) ⇒ Action
Returns a new instance of Action.
11 12 13 14 15 16 17 18 19 |
# File 'lib/lambda_open_api/action.rb', line 11 def initialize(name:, http_verb:, path_name:) @responses = {} @parameters = [] @name = name @http_verb = http_verb @path_name = path_name interpolate_path_paramater end |
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
9 10 11 |
# File 'lib/lambda_open_api/action.rb', line 9 def code @code end |
#description ⇒ Object
Returns the value of attribute description.
9 10 11 |
# File 'lib/lambda_open_api/action.rb', line 9 def description @description end |
#http_verb ⇒ Object
Returns the value of attribute http_verb.
9 10 11 |
# File 'lib/lambda_open_api/action.rb', line 9 def http_verb @http_verb end |
#method ⇒ Object
Returns the value of attribute method.
9 10 11 |
# File 'lib/lambda_open_api/action.rb', line 9 def method @method end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/lambda_open_api/action.rb', line 9 def name @name end |
#param ⇒ Object
Returns the value of attribute param.
9 10 11 |
# File 'lib/lambda_open_api/action.rb', line 9 def param @param end |
#parameters ⇒ Object
Returns the value of attribute parameters.
9 10 11 |
# File 'lib/lambda_open_api/action.rb', line 9 def parameters @parameters end |
#path_name ⇒ Object
Returns the value of attribute path_name.
9 10 11 |
# File 'lib/lambda_open_api/action.rb', line 9 def path_name @path_name end |
#responses ⇒ Object
Returns the value of attribute responses.
9 10 11 |
# File 'lib/lambda_open_api/action.rb', line 9 def responses @responses end |
#summery ⇒ Object
Returns the value of attribute summery.
9 10 11 |
# File 'lib/lambda_open_api/action.rb', line 9 def summery @summery end |
Instance Method Details
#action_json ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/lambda_open_api/action.rb', line 39 def action_json { "tags"=> [titleize(@name)], "summary"=> @summery, "description"=> @description, "consumes"=> [ "application/json" ], "produces"=> [ "application/json" ], "parameters" => @parameters, "responses" => @responses } end |
#interpolate_path_paramater ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/lambda_open_api/action.rb', line 21 def interpolate_path_paramater matches = @path_name.scan PARAMATER_EXPRESION return unless matches.any? matches.flatten.each do |match| @parameters << LambdaOpenApi::PathParameter.new(name: match).json end end |
#set_request_body(data) ⇒ Object
31 32 33 |
# File 'lib/lambda_open_api/action.rb', line 31 def set_request_body(data) @parameters << LambdaOpenApi::BodyParameter.new(data).json end |
#set_response(data) ⇒ Object
35 36 37 |
# File 'lib/lambda_open_api/action.rb', line 35 def set_response(data) @responses["200"] = LambdaOpenApi::Response.new(data).json end |
#titleize(string) ⇒ Object
56 57 58 |
# File 'lib/lambda_open_api/action.rb', line 56 def titleize(string) string.to_s.split("_").map{|word| word.capitalize}.join(" ") end |