Class: GrapeOAS::Exporter::OAS3::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/grape_oas/exporter/oas3/parameter.rb

Instance Method Summary collapse

Constructor Details

#initialize(operation, ref_tracker = nil, nullable_strategy: Constants::NullableStrategy::KEYWORD) ⇒ Parameter

Returns a new instance of Parameter.



7
8
9
10
11
# File 'lib/grape_oas/exporter/oas3/parameter.rb', line 7

def initialize(operation, ref_tracker = nil, nullable_strategy: Constants::NullableStrategy::KEYWORD)
  @op = operation
  @ref_tracker = ref_tracker
  @nullable_strategy = nullable_strategy
end

Instance Method Details

#buildObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/grape_oas/exporter/oas3/parameter.rb', line 13

def build
  Array(@op.parameters).map do |param|
    schema_hash = Schema.new(param.schema, @ref_tracker, nullable_strategy: @nullable_strategy).build
    schema_description = schema_hash.delete("description")
    description = param.description || schema_description
    {
      "name" => param.name,
      "in" => param.location,
      "required" => param.required,
      "description" => description,
      "style" => param.style,
      "explode" => param.explode,
      "schema" => schema_hash
    }.compact
  end.presence
end