Class: Apipie::Generator::Swagger::OperationId

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/generator/swagger/operation_id.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, http_method:, param: nil) ⇒ OperationId

Returns a new instance of OperationId.



2
3
4
5
6
# File 'lib/apipie/generator/swagger/operation_id.rb', line 2

def initialize(path:, http_method:, param: nil)
  @path = path
  @http_method = http_method
  @param = param
end

Class Method Details

.from(describable, param: nil) ⇒ Apipie::Generator::Swagger::OperationId

Parameters:

Returns:



23
24
25
26
27
28
29
30
31
32
# File 'lib/apipie/generator/swagger/operation_id.rb', line 23

def self.from(describable, param: nil)
  path, http_method =
    if describable.respond_to?(:path) && describable.respond_to?(:http_method)
      [describable.path, describable.http_method]
    elsif describable.is_a?(Apipie::MethodDescription)
      [describable.apis.first.path, describable.apis.first.http_method]
    end

  new(path: path, http_method: http_method, param: param)
end

Instance Method Details

#to_sString

Returns:

  • (String)


9
10
11
12
13
14
15
16
17
# File 'lib/apipie/generator/swagger/operation_id.rb', line 9

def to_s
  base = normalized_http_method + path

  if @param.present?
    "#{base}_param_#{@param}"
  else
    base
  end
end