Class: Apipie::Generator::Swagger::ParamDescription::PathParamsComposite

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

Instance Method Summary collapse

Constructor Details

#initialize(param_descriptions, context) ⇒ PathParamsComposite

Returns a new instance of PathParamsComposite.

Parameters:



4
5
6
7
8
# File 'lib/apipie/generator/swagger/param_description/path_params_composite.rb', line 4

def initialize(param_descriptions, context)
  @param_descriptions = param_descriptions
  @context = context
  @result = []
end

Instance Method Details

#to_swaggerArray

Returns:

  • (Array)


11
12
13
14
15
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
49
50
# File 'lib/apipie/generator/swagger/param_description/path_params_composite.rb', line 11

def to_swagger
  @param_descriptions.each do |desc|
    context = @context.dup

    type = Apipie::Generator::Swagger::TypeExtractor.new(desc.validator).extract

    if type == 'object' && desc.validator.params_ordered.blank?
      warn_param_ignored_in_form_data(desc.name)
      next
    end

    has_nested_params = type == 'object' &&
                        desc.validator.params_ordered.present?

    if has_nested_params
      context.add_to_prefix!(desc.name)

      out = Apipie::Generator::Swagger::ParamDescription::PathParamsComposite
            .new(desc.validator.params_ordered, context)
            .to_swagger

      @result.concat(out)
    else
      param_entry =
        Apipie::Generator::Swagger::ParamDescription::Builder
        .new(desc, in_schema: false, controller_method: context.controller_method)
        .with_description(language: context.language)
        .with_name(prefix: context.prefix)
        .with_type(with_null: context.allow_null?)
        .with_in(
          http_method: context.http_method,
          default_in_value: context.default_in_value
        ).to_swagger

      @result << param_entry
    end
  end

  @result.sort_by { |p| p[:required] ? 0 : 1 }
end