Class: Gitlab::GrapeOpenapi::Converters::RequestBodyConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/grape_openapi/converters/request_body_converter.rb

Constant Summary collapse

DEFAULT_CONTENT_TYPE =
'application/json'
MULTIPART_FORM_DATA_CONTENT_TYPE =
'multipart/form-data'
GET_METHOD =
'GET'
DELETE_METHOD =
'DELETE'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route:, options:, params:, request_body_registry:) ⇒ RequestBodyConverter

Returns a new instance of RequestBodyConverter.



18
19
20
21
22
23
# File 'lib/gitlab/grape_openapi/converters/request_body_converter.rb', line 18

def initialize(route:, options:, params:, request_body_registry:)
  @route = route
  @options = options
  @params = params
  @request_body_registry = request_body_registry
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/gitlab/grape_openapi/converters/request_body_converter.rb', line 12

def options
  @options
end

#paramsObject (readonly)

Returns the value of attribute params.



12
13
14
# File 'lib/gitlab/grape_openapi/converters/request_body_converter.rb', line 12

def params
  @params
end

#request_body_registryObject (readonly)

Returns the value of attribute request_body_registry.



12
13
14
# File 'lib/gitlab/grape_openapi/converters/request_body_converter.rb', line 12

def request_body_registry
  @request_body_registry
end

#routeObject (readonly)

Returns the value of attribute route.



12
13
14
# File 'lib/gitlab/grape_openapi/converters/request_body_converter.rb', line 12

def route
  @route
end

Class Method Details

.convert(route:, options:, params:, request_body_registry:) ⇒ Object



14
15
16
# File 'lib/gitlab/grape_openapi/converters/request_body_converter.rb', line 14

def self.convert(route:, options:, params:, request_body_registry:)
  new(route: route, options: options, params: params, request_body_registry: request_body_registry).convert
end

Instance Method Details

#convertObject



25
26
27
28
29
30
31
32
33
# File 'lib/gitlab/grape_openapi/converters/request_body_converter.rb', line 25

def convert
  return nil if route_method == GET_METHOD || route_method == DELETE_METHOD
  return nil if params.empty?

  body_params = Models::RequestBody::Parameters.new(route: route, params: params).extract
  return nil if body_params.empty?

  build_request_body(body_params)
end