Module: SoberSwag::Reporting::Input::Interface

Included in:
Base, Struct
Defined in:
lib/sober_swag/reporting/input/interface.rb

Overview

Module for interface methods.

Instance Method Summary collapse

Instance Method Details

#add_schema_key(base, addition) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/sober_swag/reporting/input/interface.rb', line 107

def add_schema_key(base, addition)
  if base.key?(:$ref)
    { allOf: [base] }.merge(addition)
  else
    base.merge(addition)
  end
end

#call!(value) ⇒ Object

Raises:



81
82
83
84
85
86
# File 'lib/sober_swag/reporting/input/interface.rb', line 81

def call!(value)
  res = call(value)
  raise Report::Error.new(res) if res.is_a?(Report::Base) # rubocop:disable Style/RaiseArgs

  res
end

#described(desc) ⇒ Object



65
66
67
# File 'lib/sober_swag/reporting/input/interface.rb', line 65

def described(desc)
  Described.new(self, desc)
end

#enum(*cases) ⇒ Object



69
70
71
# File 'lib/sober_swag/reporting/input/interface.rb', line 69

def enum(*cases)
  Enum.new(self, cases)
end

#format(format) ⇒ Object



61
62
63
# File 'lib/sober_swag/reporting/input/interface.rb', line 61

def format(format)
  Format.new(self, format)
end

#in_range(range) ⇒ InRange

Constrained values: must be in range.

Returns:

Raises:

  • (ArgumentError)


45
46
47
48
49
# File 'lib/sober_swag/reporting/input/interface.rb', line 45

def in_range(range)
  raise ArgumentError, "need a range, not a #{range.class}" unless range.is_a?(Range)

  InRange.new(self, range)
end

#listList Also known as: array

A list of this input.

Returns:

  • (List)

    the new input.



36
37
38
# File 'lib/sober_swag/reporting/input/interface.rb', line 36

def list
  List.new(self)
end

#mapped(&block) ⇒ Mapped

Map a function after this input runs.

Returns:



77
78
79
# File 'lib/sober_swag/reporting/input/interface.rb', line 77

def mapped(&block)
  Mapped.new(self, block)
end

#modify_schema(base, addition) ⇒ Object



96
97
98
99
100
101
102
103
104
105
# File 'lib/sober_swag/reporting/input/interface.rb', line 96

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

#multiple_of(number) ⇒ Object

Constrained values: must be a multiple of the given number



53
54
55
# File 'lib/sober_swag/reporting/input/interface.rb', line 53

def multiple_of(number)
  MultipleOf.new(self, number)
end

#optionalEither Also known as: nilable

This, or null.

Returns:

  • (Either)

    an either type of this or nil.



26
27
28
# File 'lib/sober_swag/reporting/input/interface.rb', line 26

def optional
  self | Null.new
end

#or(other) ⇒ Either

Make a new input that is either this type or the argument.

Returns:

  • (Either)

    this input, or some other input.



12
13
14
# File 'lib/sober_swag/reporting/input/interface.rb', line 12

def or(other)
  Either.new(self, other)
end

#referenced(name) ⇒ Object



57
58
59
# File 'lib/sober_swag/reporting/input/interface.rb', line 57

def referenced(name)
  Referenced.new(self, name)
end

#swagger_path_schemaObject



88
89
90
# File 'lib/sober_swag/reporting/input/interface.rb', line 88

def swagger_path_schema
  raise InvalidSchemaError::InvalidForPathError.new(self) # rubocop:disable Style/RaiseArgs
end

#swagger_query_schemaObject



92
93
94
# File 'lib/sober_swag/reporting/input/interface.rb', line 92

def swagger_query_schema
  raise InvalidSchemaError::InvalidForQueryError.new(self) # rubocop:disable Style/RaiseArgs
end

#|(other) ⇒ Object

See Also:

  • SoberSwag::Reporting::Input::Interface.{{#or}


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

def |(other)
  Either.new(self, other)
end