Class: SoberSwag::Reporting::Input::Enum
- 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
-
#input ⇒ Interface
readonly
Base type.
-
#values ⇒ Array<String>
readonly
Acceptable types.
Instance Method Summary collapse
- #call(value) ⇒ Object
-
#initialize(input, values) ⇒ Enum
constructor
A new instance of Enum.
- #swagger_schema ⇒ Object
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
#input ⇒ Interface (readonly)
Returns base type.
14 15 16 |
# File 'lib/sober_swag/reporting/input/enum.rb', line 14 def input @input end |
#values ⇒ Array<String> (readonly)
Returns 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_schema ⇒ Object
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 |