Class: RuboCop::Cop::Iotventure::SaveRequestExample

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/iotventure/save_request_example.rb

Overview

This cop checks for missing request examples (only needed when params in query).

Examples:


# bad

parameter name: :param1, in: :body
response 200, 'response description' {}

# bad

parameter name: :param1, in: :body
response 200, 'response description', save_request_example: :param2 {}

# good

parameter name: :param1, in: :body
response 200, 'response description', save_request_example: :param1 {}

# good

response 200, 'response description' {}

Constant Summary collapse

MISSING_MSG =
'Request example `:%<param_name>s` is missing at %<current>s.'
MISNAMED_MSG =
'Request example `:%<wrong_param_name>s` is misnamed at %<current>s.'\
'It should be `:%<correct_param_name>s`.'

Instance Method Summary collapse

Instance Method Details

#body_param_name?(node) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rubocop/cop/iotventure/save_request_example.rb', line 45

def_node_matcher :body_param_name, <<~PATTERN
  (begin
    <(send nil? :parameter
      (hash
        <(pair
          (sym :name)
          (sym $_)
        )
        (pair
          (sym :in)
          (sym :body)
        )... >
    )) ... >
  )
PATTERN

#on_begin(node) ⇒ Object



86
87
88
89
90
91
# File 'lib/rubocop/cop/iotventure/save_request_example.rb', line 86

def on_begin(node)
  body_param_name = body_param_name(node)
  return unless body_param_name

  check_for_wrong_save_request_example(node, body_param_name)
end

#save_request_example_name(node) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rubocop/cop/iotventure/save_request_example.rb', line 74

def_node_matcher :save_request_example_name, <<~PATTERN
  (hash
    <
      (pair
        (sym :save_request_example)
        (sym $_)
      )
      ...
    >
  )
PATTERN

#success_response(node) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/rubocop/cop/iotventure/save_request_example.rb', line 62

def_node_matcher :success_response, <<~PATTERN
  (block
    (send nil? :response
      (:int #success_response_code?)
      (:str _)
      $...
    )
    ...
  )
PATTERN