Class: SoberSwag::Reporting::Input::Object::Property

Inherits:
Object
  • Object
show all
Defined in:
lib/sober_swag/reporting/input/object/property.rb

Overview

Describe a single property key in an object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, required:, description: '') ⇒ Property

Returns a new instance of Property.



8
9
10
11
12
# File 'lib/sober_swag/reporting/input/object/property.rb', line 8

def initialize(value, required:, description: '')
  @value = value
  @required = required
  @description = description
end

Instance Attribute Details

#descriptionString? (readonly)

Returns description.

Returns:

  • (String, nil)

    description



24
25
26
# File 'lib/sober_swag/reporting/input/object/property.rb', line 24

def description
  @description
end

#valueSoberSwag::Reporting::Input::Interface (readonly)

Returns value type.

Returns:



16
17
18
# File 'lib/sober_swag/reporting/input/object/property.rb', line 16

def value
  @value
end

Instance Method Details

#add_description(dir) ⇒ Object (private)



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sober_swag/reporting/input/object/property.rb', line 38

def add_description(dir)
  t =
    if dir.key?(:$ref)
      # workaround: we have to do this if we want to allow
      # descriptions in reference types
      { allOf: [dir] }
    else
      dir
    end
  t.merge(description: description)
end

#property_schemaObject



26
27
28
29
30
31
32
33
34
# File 'lib/sober_swag/reporting/input/object/property.rb', line 26

def property_schema
  direct, refined = value.swagger_schema

  if description
    [add_description(direct), refined]
  else
    [direct, refined]
  end
end

#required?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/sober_swag/reporting/input/object/property.rb', line 18

def required?
  @required
end