Class: SoberSwag::Reporting::Input::Enum

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

Overview

Specify that a value must be included in a list of possible values.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Interface

#add_schema_key, #call!, #described, #enum, #format, #in_range, #list, #mapped, #modify_schema, #multiple_of, #optional, #or, #referenced, #swagger_path_schema, #swagger_query_schema, #|

Constructor Details

#initialize(input, values) ⇒ Enum

Returns a new instance of Enum.



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

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

Instance Attribute Details

#inputInterface (readonly)

Returns base type.

Returns:



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

def input
  @input
end

#valuesArray<String> (readonly)

Returns acceptable types.

Returns:

  • (Array<String>)

    acceptable types



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

def values
  @values
end

Instance Method Details

#call(value) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/sober_swag/reporting/input/enum.rb', line 20

def call(value)
  inner = input.call(value)

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

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

  inner
end

#swagger_schemaObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sober_swag/reporting/input/enum.rb', line 30

def swagger_schema
  schema, found = input.swagger_schema

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