Class: Explicit::Type::Array
- Inherits:
-
Explicit::Type
- Object
- Explicit::Type
- Explicit::Type::Array
- Defined in:
- lib/explicit/type/array.rb
Instance Attribute Summary collapse
-
#empty ⇒ Object
readonly
Returns the value of attribute empty.
-
#item_type ⇒ Object
readonly
Returns the value of attribute item_type.
Attributes inherited from Explicit::Type
#auth_type, #default, #description, #nilable, #param_location
Instance Method Summary collapse
-
#initialize(item_type:, empty: true) ⇒ Array
constructor
A new instance of Array.
- #json_schema(flavour) ⇒ Object
- #validate(values) ⇒ Object
Methods inherited from Explicit::Type
#auth_basic?, #auth_bearer?, build, #error_i18n, #mcp_schema, #merge_base_json_schema, #param_location_body?, #param_location_path?, #param_location_query?, #required?, #swagger_i18n, #swagger_schema
Constructor Details
Instance Attribute Details
#empty ⇒ Object (readonly)
Returns the value of attribute empty.
4 5 6 |
# File 'lib/explicit/type/array.rb', line 4 def empty @empty end |
#item_type ⇒ Object (readonly)
Returns the value of attribute item_type.
4 5 6 |
# File 'lib/explicit/type/array.rb', line 4 def item_type @item_type end |
Instance Method Details
#json_schema(flavour) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/explicit/type/array.rb', line 46 def json_schema(flavour) { type: "array", items: item_type.mcp_schema, minItems: empty ? 0 : 1 } end |
#validate(values) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/explicit/type/array.rb', line 11 def validate(values) return error_i18n("array") if !values.is_a?(::Array) if values.empty? && !empty return error_i18n("empty") end validated = [] values.each.with_index do |value, index| case item_type.validate(value) in [:ok, value] validated << value in [:error, error] return error_i18n("array_item", index:, error:) end end [:ok, validated] end |