Class: ReeSwagger::BuildParameters

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL
Defined in:
lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb

Constant Summary collapse

ObjectPathParamError =
Class.new(StandardError)
ArrayPathParamError =
Class.new(StandardError)

Instance Method Summary collapse

Instance Method Details

#call(mapper, path_params, with_query_params) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb', line 16

def call(mapper, path_params, with_query_params)
  mapper.fields.filter_map do |_name, field|
    is_path_param = path_params.include?(field.name)

    next unless is_path_param || with_query_params

    if is_path_param
      if field.type.type.nil?
        raise ObjectPathParamError, "path parameter(#{
          field.name
        }) can not be an object"
      end

      if field.type.type.is_a?(ReeMapper::Array)
        raise ArrayPathParamError, "path parameter(#{
          field.name
        }) can not be an array"
      end
    end

    schema =  {
      name: field.name_as_str,
      in: is_path_param ? 'path' : 'query',
      required: is_path_param || !field.optional,
      schema: build_request_body_schema(field.type, [], wrap(field.fields_filter)) || {}
    }

    schema[:style] = 'deepObject' if field.type.type.nil?
    schema[:nullable] = true if field.null

    schema
  end
end