Class: Verquest::Properties::Array
- Defined in:
- lib/verquest/properties/array.rb
Overview
Array property type for schema generation and mapping
Represents an array data structure in the schema with specified item type. Used to define arrays of scalar types (string, number, integer, boolean).
Instance Attribute Summary collapse
-
#schema_options ⇒ Object
readonly
private
Returns the value of attribute schema_options.
-
#type ⇒ Object
readonly
private
Returns the value of attribute type.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(name:, type:, map: nil, required: false, **schema_options) ⇒ Array
constructor
Initialize a new Array property.
-
#mapping(key_prefix:, value_prefix:, mapping:, version: nil) ⇒ Hash
Create mapping for this array property.
-
#to_schema ⇒ Hash
Generate JSON schema definition for this array property.
Methods inherited from Base
#add, #mapping_value_key, #mapping_value_prefix, #to_validation_schema
Constructor Details
#initialize(name:, type:, map: nil, required: false, **schema_options) ⇒ Array
Initialize a new Array property
25 26 27 28 29 30 31 32 33 |
# File 'lib/verquest/properties/array.rb', line 25 def initialize(name:, type:, map: nil, required: false, **) raise ArgumentError, "You can not map array to the root" if map == "/" @name = name @type = type @map = map @required = required = end |
Instance Attribute Details
#schema_options ⇒ Object (readonly, private)
Returns the value of attribute schema_options.
60 61 62 |
# File 'lib/verquest/properties/array.rb', line 60 def end |
#type ⇒ Object (readonly, private)
Returns the value of attribute type.
60 61 62 |
# File 'lib/verquest/properties/array.rb', line 60 def type @type end |
Instance Method Details
#mapping(key_prefix:, value_prefix:, mapping:, version: nil) ⇒ Hash
Create mapping for this array property
54 55 56 |
# File 'lib/verquest/properties/array.rb', line 54 def mapping(key_prefix:, value_prefix:, mapping:, version: nil) mapping[(key_prefix + [name]).join(".")] = mapping_value_key(value_prefix:) end |
#to_schema ⇒ Hash
Generate JSON schema definition for this array property
38 39 40 41 42 43 44 45 |
# File 'lib/verquest/properties/array.rb', line 38 def to_schema { name => { type: :array, items: {type: type} }.merge() } end |