Class: Gitlab::GrapeOpenapi::Models::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/grape_openapi/models/parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options:, schema:, in_value:) ⇒ Parameter

Returns a new instance of Parameter.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 11

def initialize(name, options:, schema:, in_value:)
  @options = options
  @name = name
  # From https://spec.openapis.org/oas/v3.2.0.html#common-fixed-fields: "If the parameter
  # location is 'path', this property is REQUIRED and its value MUST be true.
  @required = in_value == 'path' ? true : options[:required]
  @description = options[:desc]
  @schema = schema
  @in_value = in_value
  @example = options.dig(:documentation, :example)
  @default = options.dig(:documentation, :default)
  @style = nil
  @explode = nil
end

Instance Attribute Details

#descriptionObject (readonly)



8
9
10
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 8

def description
  @description
end

#exampleObject (readonly)



8
9
10
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 8

def example
  @example
end

#explodeObject

Returns the value of attribute explode.



9
10
11
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 9

def explode
  @explode
end

#in_valueObject (readonly)



8
9
10
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 8

def in_value
  @in_value
end

#nameObject (readonly)



8
9
10
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 8

def name
  @name
end

#optionsObject (readonly)



8
9
10
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 8

def options
  @options
end

#requiredObject (readonly)



8
9
10
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 8

def required
  @required
end

#schemaObject (readonly)



8
9
10
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 8

def schema
  @schema
end

#styleObject

Returns the value of attribute style.



9
10
11
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 9

def style
  @style
end

Instance Method Details

#to_hObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab/grape_openapi/models/parameter.rb', line 26

def to_h
  result = {
    name: name,
    required: required,
    description: description,
    schema: schema,
    in: in_value,
    example: example
  }

  result[:style] = style if style
  result[:explode] = explode unless explode.nil?
  result.compact
end