Class: SoberSwag::Reporting::Output::Enum

Inherits:
Base
  • Object
show all
Defined in:
lib/sober_swag/reporting/output/enum.rb

Overview

Models outputting an enum.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#view, #views

Methods included from Interface

#call!, #described, #enum, #in_range, #list, #nilable, #partitioned, #referenced, #reporting?, #serialize, #via_map

Constructor Details

#initialize(output, values) ⇒ Enum

Returns a new instance of Enum.



7
8
9
10
# File 'lib/sober_swag/reporting/output/enum.rb', line 7

def initialize(output, values)
  @output = output
  @values = values
end

Instance Attribute Details

#outputInterface (readonly)

Returns:



14
15
16
# File 'lib/sober_swag/reporting/output/enum.rb', line 14

def output
  @output
end

#valuesArray (readonly)

Returns:

  • (Array)


18
19
20
# File 'lib/sober_swag/reporting/output/enum.rb', line 18

def values
  @values
end

Instance Method Details

#call(value) ⇒ Object



20
21
22
# File 'lib/sober_swag/reporting/output/enum.rb', line 20

def call(value)
  output.call(value)
end

#serialize_report(value) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/sober_swag/reporting/output/enum.rb', line 24

def serialize_report(value)
  rep = output.serialize_report(value)

  return rep if rep.is_a?(Report::Base)

  return Report::Value.new(['was not an acceptable enum member']) unless values.include?(rep)

  rep
end

#swagger_schemaObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/sober_swag/reporting/output/enum.rb', line 34

def swagger_schema
  schema, found = output.swagger_schema
  merged =
    if schema.key?(:$ref)
      { allOf: [schema] }
    else
      schema
    end.merge(enum: values)
  [merged, found]
end