Class: LambdaOpenApi::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/lambda_open_api/action.rb

Constant Summary collapse

PARAMATER_EXPRESION =
/[:\{](\w+)\}?/

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#codeObject

Returns the value of attribute code.



9
10
11
# File 'lib/lambda_open_api/action.rb', line 9

def code
  @code
end

#descriptionObject

Returns the value of attribute description.



9
10
11
# File 'lib/lambda_open_api/action.rb', line 9

def description
  @description
end

#http_verbObject

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

#methodObject

Returns the value of attribute method.



9
10
11
# File 'lib/lambda_open_api/action.rb', line 9

def method
  @method
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/lambda_open_api/action.rb', line 9

def name
  @name
end

#paramObject

Returns the value of attribute param.



9
10
11
# File 'lib/lambda_open_api/action.rb', line 9

def param
  @param
end

#parametersObject

Returns the value of attribute parameters.



9
10
11
# File 'lib/lambda_open_api/action.rb', line 9

def parameters
  @parameters
end

#path_nameObject

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

#responsesObject

Returns the value of attribute responses.



9
10
11
# File 'lib/lambda_open_api/action.rb', line 9

def responses
  @responses
end

#summeryObject

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_jsonObject



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_paramaterObject



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