Module: Jsapi::Meta::Schema

Defined in:
lib/jsapi/meta/schema.rb,
lib/jsapi/meta/schema/base.rb,
lib/jsapi/meta/schema/array.rb,
lib/jsapi/meta/schema/number.rb,
lib/jsapi/meta/schema/object.rb,
lib/jsapi/meta/schema/string.rb,
lib/jsapi/meta/schema/boolean.rb,
lib/jsapi/meta/schema/integer.rb,
lib/jsapi/meta/schema/numeric.rb,
lib/jsapi/meta/schema/boundary.rb,
lib/jsapi/meta/schema/delegator.rb,
lib/jsapi/meta/schema/reference.rb,
lib/jsapi/meta/schema/conversion.rb,
lib/jsapi/meta/schema/discriminator.rb,
lib/jsapi/meta/schema/validation/base.rb,
lib/jsapi/meta/schema/validation/enum.rb,
lib/jsapi/meta/schema/validation/maximum.rb,
lib/jsapi/meta/schema/validation/minimum.rb,
lib/jsapi/meta/schema/validation/pattern.rb,
lib/jsapi/meta/schema/validation/max_items.rb,
lib/jsapi/meta/schema/validation/min_items.rb,
lib/jsapi/meta/schema/additional_properties.rb,
lib/jsapi/meta/schema/validation/max_length.rb,
lib/jsapi/meta/schema/validation/min_length.rb,
lib/jsapi/meta/schema/validation/multiple_of.rb

Defined Under Namespace

Modules: Conversion, Validation Classes: AdditionalProperties, Array, Base, Boolean, Boundary, Delegator, Discriminator, Integer, Number, Numeric, Object, Reference, String

Constant Summary collapse

TYPES =

:nodoc:

%w[array boolean integer number object string].freeze

Class Method Summary collapse

Class Method Details

.new(keywords = {}) ⇒ Object

Creates a new schema. The :type keyword determines the type of the schema to be created. Possible types are:

  • "array"

  • "boolean"

  • "integer"

  • "number"

  • "object"

  • "string"

The default type is "object".

Raises an InvalidArgumentError if the given type is invalid.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jsapi/meta/schema.rb', line 43

def new(keywords = {})
  return Reference.new(keywords) if keywords.key?(:ref)

  type = keywords[:type]
  case type&.to_s
  when 'array'
    Array
  when 'boolean'
    Boolean
  when 'integer'
    Integer
  when 'number'
    Number
  when 'object', nil
    Object
  when 'string'
    String
  else
    raise InvalidArgumentError.new('type', type, valid_values: TYPES)
  end.new(keywords.except(:type))
end