Module: OpenApiAnnotator::ControllerAnnotatable

Defined in:
lib/open_api_annotator/controller_annotatable.rb

Instance Method Summary collapse

Instance Method Details

#endpoint(type) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/open_api_annotator/controller_annotatable.rb', line 12

def endpoint(type)
  validate_open_api_type!(type)
  @last_endpoint = Endpoint.new(type)

rescue ValidationError => e
  raise TypeError, <<~EOL
  #{e.message}

  Examples:
    - `[Project]`: means collection of Project
    - `Project`: means single resouce Project

  In your controller:

    endpoint [Project]
    def index
      # ... some code
    end
  EOL
end

#endpoint_hashObject



3
4
5
# File 'lib/open_api_annotator/controller_annotatable.rb', line 3

def endpoint_hash
  @endpoint_hash ||= {}
end

#method_added(name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/open_api_annotator/controller_annotatable.rb', line 33

def method_added(name)
  super
  return unless @last_endpoint

  endpoint = @last_endpoint
  @last_endpoint = nil

  return if private_method_defined?(name)

  endpoint_hash[name] = endpoint
end

#validate_open_api_type!(type) ⇒ Object



7
8
9
10
# File 'lib/open_api_annotator/controller_annotatable.rb', line 7

def validate_open_api_type!(type)
  @open_api_type_validator ||= TypeValidator.new
  @open_api_type_validator.validate!(type)
end