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/wrapper.rb,
lib/jsapi/meta/schema/boundary.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, Discriminator, Integer, Number, Numeric, Object, Reference, String, Wrapper

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 ArgumentError if the given type is invalid.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/jsapi/meta/schema.rb', line 37

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 ArgumentError, Messages.invalid_value(
      name: 'type',
      value: type,
      valid_values: TYPES
    )
  end.new(keywords.except(:type))
end

.wrap(schema, definitions) ⇒ Object

Wraps schema.



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/jsapi/meta/schema.rb', line 64

def wrap(schema, definitions)
  return if schema.nil?
  return schema if schema.is_a?(Wrapper)

  case schema.resolve(definitions).type
  when 'array'
    Array::Wrapper
  when 'object'
    Object::Wrapper
  else
    Wrapper
  end.new(schema, definitions)
end