Class: Apia::OpenApi::Objects::Parameters

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/apia/open_api/objects/parameters.rb

Instance Method Summary collapse

Methods included from Helpers

#add_to_components_schemas, #convert_type_to_open_api_data_type, #formatted_description, #generate_array_schema, #generate_id_from_definition, #generate_scalar_schema, #generate_schema_ref

Constructor Details

#initialize(spec:, argument:, route_spec:) ⇒ Parameters

Returns a new instance of Parameters.



29
30
31
32
33
# File 'lib/apia/open_api/objects/parameters.rb', line 29

def initialize(spec:, argument:, route_spec:)
  @spec = spec
  @argument = argument
  @route_spec = route_spec
end

Instance Method Details

#add_to_specObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/apia/open_api/objects/parameters.rb', line 35

def add_to_spec
  if @argument.type.argument_set?
    generate_argument_set_params
  elsif @argument.array?
    if @argument.type.enum? || @argument.type.object?
      items = generate_schema_ref(@argument)
    else
      items = generate_scalar_schema(@argument)
    end

    param = {
      name: "#{@argument.name}[]",
      in: "query",
      schema: {
        type: "array",
        items: items
      }
    }
    param[:description] = @argument.description if @argument.description.present?
    param[:required] = true if @argument.required?
    add_to_parameters(param)
  elsif @argument.type.enum?
    param = {
      name: @argument.name.to_s,
      in: "query",
      schema: generate_schema_ref(@argument)
    }
    param[:description] = @argument.description if @argument.description.present?
    param[:required] = true if @argument.required?
    add_to_parameters(param)
  else
    param = {
      name: @argument.name.to_s,
      in: "query",
      schema: generate_scalar_schema(@argument)
    }
    param[:description] = @argument.description if @argument.description.present?

    add_pagination_params(param)

    param[:required] = true if @argument.required?
    add_to_parameters(param)
  end
end